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..0c5d6fffd 100644
--- a/rma/wizards/rma_make_picking.py
+++ b/rma/wizards/rma_make_picking.py
@@ -34,15 +34,25 @@ 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)
+ if context.get("highlight"):
+ lines = rma.rma_line_ids.filtered(lambda x: x.qty_to_receive > 0)
+ else:
+ lines = rma.rma_line_ids.filtered(lambda x: x.receipt_policy != "no")
+ 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..d25ec5c39 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"
/>