mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[FIX]reverting changes applied to v11
This commit is contained in:
@@ -47,16 +47,18 @@ class RmaOrderLine(models.Model):
|
||||
@api.multi
|
||||
def _compute_in_shipment_count(self):
|
||||
for line in self:
|
||||
line.in_shipment_count = len(self.env['stock.picking'].search(
|
||||
[('origin', '=', line.name),
|
||||
('picking_type_code', '=', 'incoming')]).ids)
|
||||
moves = line.procurement_ids.mapped('move_ids').filtered(
|
||||
lambda m: m.location_dest_id.usage == 'internal')
|
||||
pickings = moves.mapped('picking_id')
|
||||
line.in_shipment_count = len(pickings)
|
||||
|
||||
@api.multi
|
||||
def _compute_out_shipment_count(self):
|
||||
for line in self:
|
||||
line.out_shipment_count = len(self.env['stock.picking'].search(
|
||||
[('origin', '=', line.name),
|
||||
('picking_type_code', '=', 'outgoing')]).ids)
|
||||
moves = line.procurement_ids.mapped('move_ids').filtered(
|
||||
lambda m: m.location_dest_id.usage != 'internal')
|
||||
pickings = moves.mapped('picking_id')
|
||||
line.out_shipment_count = len(pickings)
|
||||
|
||||
@api.multi
|
||||
def _get_rma_move_qty(self, states, direction='in'):
|
||||
@@ -67,7 +69,7 @@ class RmaOrderLine(models.Model):
|
||||
op = ops['=']
|
||||
else:
|
||||
op = ops['!=']
|
||||
for move in rec.move_ids.filtered(
|
||||
for move in rec.procurement_ids.mapped('move_ids').filtered(
|
||||
lambda m: m.state in states and op(m.location_id.usage,
|
||||
rec.type)):
|
||||
qty += product_obj._compute_quantity(
|
||||
@@ -82,8 +84,8 @@ class RmaOrderLine(models.Model):
|
||||
rec.qty_to_receive = 0.0
|
||||
if rec.receipt_policy == 'ordered':
|
||||
rec.qty_to_receive = rec.product_qty - rec.qty_received
|
||||
elif rec.receipt_policy == 'delivered':
|
||||
rec.qty_to_receive = rec.qty_delivered - rec.qty_received
|
||||
elif self.receipt_policy == 'delivered':
|
||||
self.qty_to_receive = rec.qty_delivered - rec.qty_received
|
||||
|
||||
@api.multi
|
||||
@api.depends('move_ids', 'move_ids.state',
|
||||
@@ -525,36 +527,42 @@ class RmaOrderLine(models.Model):
|
||||
def action_view_in_shipments(self):
|
||||
action = self.env.ref('stock.action_picking_tree_all')
|
||||
result = action.read()[0]
|
||||
moves = self.env['stock.move'].search([
|
||||
('rma_line_id', 'in', self.ids)])
|
||||
picking_ids = moves.mapped('picking_id').filtered(
|
||||
lambda p: p.picking_type_code == 'incoming').ids
|
||||
picking_ids = []
|
||||
for line in self:
|
||||
for move in line.move_ids:
|
||||
if move.location_dest_id.usage == 'internal':
|
||||
picking_ids.append(move.picking_id.id)
|
||||
shipments = list(set(picking_ids))
|
||||
# choose the view_mode accordingly
|
||||
if len(picking_ids) > 1:
|
||||
result['domain'] = [('id', 'in', picking_ids)]
|
||||
else:
|
||||
if len(shipments) != 1:
|
||||
result['domain'] = "[('id', 'in', " + \
|
||||
str(shipments) + ")]"
|
||||
elif len(shipments) == 1:
|
||||
res = self.env.ref('stock.view_picking_form', False)
|
||||
result['views'] = [(res and res.id or False, 'form')]
|
||||
result['res_id'] = picking_ids and picking_ids[0]
|
||||
result['res_id'] = shipments[0]
|
||||
return result
|
||||
|
||||
@api.multi
|
||||
def action_view_out_shipments(self):
|
||||
action = self.env.ref('stock.action_picking_tree_all')
|
||||
result = action.read()[0]
|
||||
moves = self.env['stock.move'].search([
|
||||
('rma_line_id', 'in', self.ids)])
|
||||
picking_ids = moves.mapped('picking_id').filtered(
|
||||
lambda p: p.picking_type_code == 'outgoing').ids
|
||||
picking_ids = []
|
||||
for line in self:
|
||||
for move in line.move_ids:
|
||||
if move.location_dest_id.usage in ('supplier', 'customer'):
|
||||
picking_ids.append(move.picking_id.id)
|
||||
shipments = list(set(picking_ids))
|
||||
# choose the view_mode accordingly
|
||||
if len(picking_ids) > 1:
|
||||
result['domain'] = [('id', 'in', picking_ids)]
|
||||
else:
|
||||
if len(shipments) != 1:
|
||||
result['domain'] = "[('id', 'in', " + \
|
||||
str(shipments) + ")]"
|
||||
elif len(shipments) == 1:
|
||||
res = self.env.ref('stock.view_picking_form', False)
|
||||
result['views'] = [(res and res.id or False, 'form')]
|
||||
result['res_id'] = picking_ids and picking_ids[0]
|
||||
result['res_id'] = shipments[0]
|
||||
return result
|
||||
|
||||
|
||||
@api.multi
|
||||
def action_view_procurements(self):
|
||||
action = self.env.ref(
|
||||
|
||||
@@ -138,23 +138,21 @@
|
||||
<notebook>
|
||||
<page name="route" string="Routes" groups="stock.group_adv_location">
|
||||
<group>
|
||||
<group>
|
||||
<group name="inbound" string="Inbound">
|
||||
<field name="in_warehouse_id"/>
|
||||
<field name="location_id"
|
||||
domain="[('usage', '=', 'internal')]"/>
|
||||
<field name="in_route_id"/>
|
||||
<field name="supplier_to_customer"/>
|
||||
</group>
|
||||
<group name="outbound" string="Outbound">
|
||||
<field name="out_warehouse_id"/>
|
||||
<field name="out_route_id"/>
|
||||
</group>
|
||||
<group name="delivery_address"
|
||||
string="Delivery Address (drop ship">
|
||||
<field name="delivery_address_id"
|
||||
groups='rma.group_rma_delivery_invoice_address'/>
|
||||
</group>
|
||||
<group name="inbound" string="Inbound">
|
||||
<field name="in_warehouse_id"/>
|
||||
<field name="location_id"
|
||||
domain="[('usage', '=', 'internal')]"/>
|
||||
<field name="in_route_id"/>
|
||||
<field name="supplier_to_customer"/>
|
||||
</group>
|
||||
<group name="outbound" string="Outbound">
|
||||
<field name="out_warehouse_id"/>
|
||||
<field name="out_route_id"/>
|
||||
</group>
|
||||
<group name="delivery_address"
|
||||
string="Delivery Address (drop ship">
|
||||
<field name="delivery_address_id"
|
||||
groups='rma.group_rma_delivery_invoice_address'/>
|
||||
</group>
|
||||
</group>
|
||||
</page>
|
||||
|
||||
@@ -112,8 +112,12 @@ class RmaMakePicking(models.TransientModel):
|
||||
warehouse = line.in_warehouse_id
|
||||
route = line.in_route_id
|
||||
else:
|
||||
location = self._get_address_location(
|
||||
delivery_address_id, line.type)
|
||||
if line.supplier_to_customer:
|
||||
location = self._get_address_location(
|
||||
delivery_address_id, 'customer')
|
||||
else:
|
||||
location = self._get_address_location(
|
||||
delivery_address_id, line.type)
|
||||
warehouse = line.out_warehouse_id
|
||||
route = line.out_route_id
|
||||
if not route:
|
||||
@@ -157,6 +161,7 @@ class RmaMakePicking(models.TransientModel):
|
||||
def _create_picking(self):
|
||||
"""Method called when the user clicks on create picking"""
|
||||
picking_type = self.env.context.get('picking_type')
|
||||
procurement_list = []
|
||||
for item in self.item_ids:
|
||||
line = item.line_id
|
||||
if line.state != 'approved':
|
||||
@@ -172,7 +177,9 @@ class RmaMakePicking(models.TransientModel):
|
||||
raise ValidationError(
|
||||
_('No deliveries needed for this operation'))
|
||||
procurement = self._create_procurement(item, picking_type)
|
||||
return procurement
|
||||
procurement_list.append(procurement)
|
||||
procurements = self.env['procurement.order'].browse(procurement_list)
|
||||
return procurements
|
||||
|
||||
@api.model
|
||||
def _get_action(self, pickings, procurements):
|
||||
@@ -195,20 +202,19 @@ class RmaMakePicking(models.TransientModel):
|
||||
|
||||
@api.multi
|
||||
def action_create_picking(self):
|
||||
procurement = self._create_picking()
|
||||
action = self.env.ref('stock.do_view_pickings')
|
||||
action = action.read()[0]
|
||||
if procurement:
|
||||
procurements = self._create_picking()
|
||||
groups = []
|
||||
for proc in procurements:
|
||||
if proc.group_id:
|
||||
groups.append(proc.group_id.id)
|
||||
if len(groups):
|
||||
pickings = self.env['stock.picking'].search(
|
||||
[('origin', '=', procurement)]).ids
|
||||
if len(pickings) > 1:
|
||||
action['domain'] = [('id', 'in', pickings)]
|
||||
else:
|
||||
form = self.env.ref('stock.view_picking_form', False)
|
||||
action['views'] = [(form and form.id or False, 'form')]
|
||||
action['res_id'] = pickings and pickings[0]
|
||||
[('group_id', 'in', groups)])
|
||||
|
||||
action = self._get_action(pickings, procurements)
|
||||
return action
|
||||
|
||||
|
||||
@api.multi
|
||||
def action_cancel(self):
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
@@ -72,6 +72,25 @@ class AccountInvoiceLine(models.Model):
|
||||
)
|
||||
return res
|
||||
|
||||
@api.multi
|
||||
def name_get(self):
|
||||
res = []
|
||||
if self.env.context.get('rma'):
|
||||
for inv in self:
|
||||
if inv.invoice_id.reference:
|
||||
res.append((inv.id, "%s %s %s qty:%s" % (
|
||||
inv.invoice_id.number, inv.invoice_id.reference,
|
||||
inv.product_id.name, inv.quantity)))
|
||||
elif inv.invoice_id.number:
|
||||
res.append((inv.id, "%s %s qty:%s" % (
|
||||
inv.invoice_id.number or '',
|
||||
inv.product_id.name, inv.quantity)))
|
||||
else:
|
||||
res.append(super(AccountInvoiceLine, inv).name_get()[0])
|
||||
return res
|
||||
else:
|
||||
return super(AccountInvoiceLine, self).name_get()
|
||||
|
||||
@api.multi
|
||||
def _compute_rma_count(self):
|
||||
for invl in self:
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
</button>
|
||||
<group name="main_info" position="inside">
|
||||
<field name="invoice_line_id"
|
||||
context="{'rma': True}"
|
||||
options="{'no_create': True}"
|
||||
domain="['|',
|
||||
('invoice_id.partner_id', '=', partner_id),
|
||||
@@ -59,6 +60,7 @@
|
||||
</button>
|
||||
<group name="main_info" position="inside">
|
||||
<field name="invoice_line_id"
|
||||
context="{'rma': True}"
|
||||
options="{'no_create': True}"
|
||||
domain="['|',
|
||||
('invoice_id.partner_id', '=', partner_id),
|
||||
|
||||
@@ -26,3 +26,18 @@ class PurchaseOrderLine(models.Model):
|
||||
return super(PurchaseOrderLine, self)._name_search(
|
||||
name='', args=args, operator=operator, limit=limit,
|
||||
name_get_uid=name_get_uid)
|
||||
|
||||
@api.multi
|
||||
def name_get(self):
|
||||
res = []
|
||||
if self.env.context.get('rma'):
|
||||
for purchase in self:
|
||||
if purchase.order_id.name:
|
||||
res.append((purchase.id, "%s %s qty:%s" % (
|
||||
purchase.order_id.name,
|
||||
purchase.product_id.name, purchase.product_qty)))
|
||||
else:
|
||||
res.append(super(purchaseOrderLine, purchase).name_get()[0])
|
||||
return res
|
||||
else:
|
||||
return super(purchaseOrderLine, self).name_get()
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
</div>
|
||||
<group name="main_info" position="inside">
|
||||
<field name="purchase_order_line_id"
|
||||
context="{'rma': True}"
|
||||
options="{'no_create': True}"
|
||||
domain="['|',
|
||||
('order_id.partner_id', '=', partner_id),
|
||||
|
||||
@@ -27,6 +27,21 @@ class SaleOrderLine(models.Model):
|
||||
name='', args=args, operator=operator, limit=limit,
|
||||
name_get_uid=name_get_uid)
|
||||
|
||||
@api.multi
|
||||
def name_get(self):
|
||||
res = []
|
||||
if self.env.context.get('rma'):
|
||||
for sale in self:
|
||||
if sale.order_id.name:
|
||||
res.append((sale.id, "%s %s qty:%s" % (
|
||||
sale.order_id.name,
|
||||
sale.product_id.name, sale.product_uom_qty)))
|
||||
else:
|
||||
res.append(super(SaleOrderLine, sale).name_get()[0])
|
||||
return res
|
||||
else:
|
||||
return super(SaleOrderLine, self).name_get()
|
||||
|
||||
rma_line_id = fields.Many2one(
|
||||
comodel_name='rma.order.line', string='RMA', ondelete='restrict')
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
</div>
|
||||
<group name="main_info" position="inside">
|
||||
<field name="sale_line_id"
|
||||
context="{'rma': True}"
|
||||
options="{'no_create': True}"
|
||||
domain="['|',
|
||||
('order_id.partner_id', '=', partner_id),
|
||||
|
||||
Reference in New Issue
Block a user