diff --git a/rma/models/rma_order.py b/rma/models/rma_order.py index 879738ffb..bee01c3b6 100644 --- a/rma/models/rma_order.py +++ b/rma/models/rma_order.py @@ -65,6 +65,11 @@ def _compute_qty_to_receive(self): for rec in self: rec.qty_to_receive = sum(rec.rma_line_ids.mapped("qty_to_receive")) + @api.depends("rma_line_ids", "rma_line_ids.qty_to_deliver") + def _compute_qty_to_deliver(self): + for rec in self: + rec.qty_to_deliver = sum(rec.rma_line_ids.mapped("qty_to_deliver")) + @api.model def _default_date_rma(self): return datetime.now() @@ -184,6 +189,10 @@ def _default_warehouse_id(self): digits="Product Unit of Measure", compute="_compute_qty_to_receive", ) + qty_to_deliver = fields.Float( + digits="Product Unit of Measure", + compute="_compute_qty_to_deliver", + ) @api.onchange( "operation_default_id", diff --git a/rma/views/rma_order_view.xml b/rma/views/rma_order_view.xml index 0a99d911c..b4ee9a32c 100644 --- a/rma/views/rma_order_view.xml +++ b/rma/views/rma_order_view.xml @@ -211,6 +211,7 @@ 'readonly':[('state', '!=', 'draft')]}" /> + diff --git a/rma/wizards/rma_make_picking.py b/rma/wizards/rma_make_picking.py index 60cdc4afa..a8afdb439 100644 --- a/rma/wizards/rma_make_picking.py +++ b/rma/wizards/rma_make_picking.py @@ -32,7 +32,7 @@ def default_get(self, fields_list): supplier. """ context = self._context.copy() - res = super(RmaMakePicking, self).default_get(fields_list) + res = super().default_get(fields_list) rma_line_obj = self.env["rma.order.line"] rma_obj = self.env["rma.order"] active_ids = self.env.context["active_ids"] or [] @@ -47,7 +47,10 @@ def default_get(self, fields_list): items = [] if active_model == "rma.order": rma = rma_obj.browse(active_ids) - lines = rma.rma_line_ids.filtered(lambda x: x.qty_to_receive > 0) + if context.get("picking_type") == "incoming": + lines = rma.rma_line_ids.filtered(lambda x: x.qty_to_receive > 0) + if context.get("picking_type") == "outgoing": + lines = rma.rma_line_ids.filtered(lambda x: x.qty_to_deliver > 0) else: lines = rma_line_obj.browse(active_ids) if len(lines.mapped("partner_id")) > 1: diff --git a/rma/wizards/rma_make_picking_view.xml b/rma/wizards/rma_make_picking_view.xml index 29a4b0bfc..480aec9d7 100644 --- a/rma/wizards/rma_make_picking_view.xml +++ b/rma/wizards/rma_make_picking_view.xml @@ -147,6 +147,13 @@ attrs="{'invisible':['|', ('qty_to_receive', '=', 0), ('qty_to_receive', '<', 0)]}" type="action" /> +