From 0e6898893af88f14588902ca19ddb66d2d809736 Mon Sep 17 00:00:00 2001 From: "chafique.delli" Date: Mon, 25 Mar 2024 17:52:30 +0100 Subject: [PATCH] [16.0][IMP] rma: create incoming shipment from rma group --- rma/models/rma_order.py | 9 +++++++++ rma/views/rma_order_view.xml | 1 + rma/wizards/rma_make_picking.py | 17 ++++++++++++----- rma/wizards/rma_make_picking_view.xml | 25 ++++++++++++++++++++++++- 4 files changed, 46 insertions(+), 6 deletions(-) diff --git a/rma/models/rma_order.py b/rma/models/rma_order.py index edd4d5637..5e4b804e1 100644 --- a/rma/models/rma_order.py +++ b/rma/models/rma_order.py @@ -64,6 +64,11 @@ def _compute_state(self): state = "draft" rec.state = state + @api.depends("rma_line_ids", "rma_line_ids.qty_to_receive") + def _compute_qty_to_receive(self): + for rec in self: + rec.qty_to_receive = sum(rec.rma_line_ids.mapped("qty_to_receive")) + @api.model def _default_date_rma(self): return datetime.now() @@ -178,6 +183,10 @@ def _default_warehouse_id(self): required=False, string="Default Operation Type", ) + qty_to_receive = fields.Float( + digits="Product Unit of Measure", + compute="_compute_qty_to_receive", + ) @api.onchange( "operation_default_id", diff --git a/rma/views/rma_order_view.xml b/rma/views/rma_order_view.xml index 7a042423c..c3481f5dc 100644 --- a/rma/views/rma_order_view.xml +++ b/rma/views/rma_order_view.xml @@ -157,6 +157,7 @@ 'invisible':[('customer_to_supplier', '=', False)], 'readonly':[('state', '!=', 'draft')]}" /> + diff --git a/rma/wizards/rma_make_picking.py b/rma/wizards/rma_make_picking.py index 0b92b1d85..08d4738e4 100644 --- a/rma/wizards/rma_make_picking.py +++ b/rma/wizards/rma_make_picking.py @@ -34,15 +34,22 @@ def default_get(self, fields_list): context = self._context.copy() res = super(RmaMakePicking, self).default_get(fields_list) rma_line_obj = self.env["rma.order.line"] - rma_line_ids = self.env.context["active_ids"] or [] + rma_obj = self.env["rma.order"] + active_ids = self.env.context["active_ids"] or [] active_model = self.env.context["active_model"] - - if not rma_line_ids: + if not active_ids: return res - assert active_model == "rma.order.line", "Bad context propagation" + assert active_model in [ + "rma.order.line", + "rma.order", + ], "Bad context propagation" items = [] - lines = rma_line_obj.browse(rma_line_ids) + if active_model == "rma.order": + rma = rma_obj.browse(active_ids) + lines = rma.rma_line_ids.filtered(lambda x: x.state == "approved") + else: + lines = rma_line_obj.browse(active_ids) if len(lines.mapped("partner_id")) > 1: raise ValidationError( _( diff --git a/rma/wizards/rma_make_picking_view.xml b/rma/wizards/rma_make_picking_view.xml index 380be500b..2968ba692 100644 --- a/rma/wizards/rma_make_picking_view.xml +++ b/rma/wizards/rma_make_picking_view.xml @@ -108,7 +108,7 @@ name="%(action_rma_picking_in)d" string="Create Incoming Shipment" class="oe_highlight" - attrs="{'invisible':['|', '|', '|', ('qty_to_receive', '=', 0), ('qty_to_receive', '<', 0), ('state', '!=', 'approved'), ('receipt_policy', '=', 'no')]}" + attrs="{'invisible':['|', '|', ('qty_to_receive', '<', 0), ('state', '!=', 'approved'), ('receipt_policy', '=', 'no')]}" type="action" />