diff --git a/rma/models/rma_order.py b/rma/models/rma_order.py
index 68d32bf89..627109d8f 100644
--- a/rma/models/rma_order.py
+++ b/rma/models/rma_order.py
@@ -88,7 +88,11 @@ def _default_warehouse_id(self):
description = fields.Text()
comment = fields.Text("Additional Information")
date_rma = fields.Datetime(
- string="Order Date", index=True, default=lambda self: self._default_date_rma()
+ compute="_compute_date_rma",
+ inverse="_inverse_date_rma",
+ string="Order Date",
+ index=True,
+ default=lambda self: self._default_date_rma(),
)
partner_id = fields.Many2one(
comodel_name="res.partner", string="Partner", required=True
@@ -150,6 +154,26 @@ def _default_warehouse_id(self):
store=True,
)
+ @api.depends("rma_line_ids.date_rma")
+ def _compute_date_rma(self):
+ """If all order line have same date set date_rma.
+ If no lines, respect value given by the user.
+ """
+ for rma in self:
+ if rma.rma_line_ids:
+ date_rma = rma.rma_line_ids[0].date_rma or False
+ for rma_line in rma.rma_line_ids:
+ if rma_line.date_rma != date_rma:
+ date_rma = False
+ break
+ rma.date_rma = date_rma
+
+ def _inverse_date_rma(self):
+ """When set date_rma set date_rma on all order lines"""
+ for po in self:
+ if po.date_rma:
+ po.rma_line_ids.write({"date_rma": po.date_rma})
+
@api.constrains("partner_id", "rma_line_ids")
def _check_partner_id(self):
if self.rma_line_ids and self.partner_id != self.mapped(
diff --git a/rma/models/rma_order_line.py b/rma/models/rma_order_line.py
index fbfb32c83..a10fcf259 100644
--- a/rma/models/rma_order_line.py
+++ b/rma/models/rma_order_line.py
@@ -263,7 +263,7 @@ def _default_date_rma(self):
states={"draft": [("readonly", False)]},
help="Reference of the document that produced this rma.",
)
- date = fields.Datetime(
+ date_rma = fields.Datetime(
string="Order Date", index=True, default=lambda self: self._default_date_rma()
)
state = fields.Selection(
diff --git a/rma/views/rma_order_line_view.xml b/rma/views/rma_order_line_view.xml
index e37ad2870..ee39ae694 100644
--- a/rma/views/rma_order_line_view.xml
+++ b/rma/views/rma_order_line_view.xml
@@ -15,6 +15,7 @@
/>
+
@@ -40,6 +41,7 @@
/>
+
@@ -184,6 +186,7 @@
+
@@ -385,6 +388,7 @@
+