mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[IMP] rma: date_rma in lines
This commit is contained in:
@@ -88,7 +88,11 @@ class RmaOrder(models.Model):
|
||||
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 @@ class RmaOrder(models.Model):
|
||||
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(
|
||||
|
||||
Reference in New Issue
Block a user