[IMP] rma: date_rma in lines

This commit is contained in:
AaronHForgeFlow
2023-10-27 11:49:33 +02:00
parent 7a56d6381f
commit 17a44b1be9
3 changed files with 30 additions and 2 deletions

View File

@@ -88,7 +88,11 @@ class RmaOrder(models.Model):
description = fields.Text() description = fields.Text()
comment = fields.Text("Additional Information") comment = fields.Text("Additional Information")
date_rma = fields.Datetime( 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( partner_id = fields.Many2one(
comodel_name="res.partner", string="Partner", required=True comodel_name="res.partner", string="Partner", required=True
@@ -150,6 +154,26 @@ class RmaOrder(models.Model):
store=True, 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") @api.constrains("partner_id", "rma_line_ids")
def _check_partner_id(self): def _check_partner_id(self):
if self.rma_line_ids and self.partner_id != self.mapped( if self.rma_line_ids and self.partner_id != self.mapped(

View File

@@ -263,7 +263,7 @@ class RmaOrderLine(models.Model):
states={"draft": [("readonly", False)]}, states={"draft": [("readonly", False)]},
help="Reference of the document that produced this rma.", 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() string="Order Date", index=True, default=lambda self: self._default_date_rma()
) )
state = fields.Selection( state = fields.Selection(

View File

@@ -15,6 +15,7 @@
/> />
<field name="rma_id" groups="rma.group_rma_groups" /> <field name="rma_id" groups="rma.group_rma_groups" />
<field name="origin" /> <field name="origin" />
<field name="date_rma" />
<field name="operation_id" /> <field name="operation_id" />
<field name="supplier_address_id" /> <field name="supplier_address_id" />
<field name="uom_id" groups="uom.group_uom" /> <field name="uom_id" groups="uom.group_uom" />
@@ -40,6 +41,7 @@
/> />
<field name="rma_id" groups="rma.group_rma_groups" /> <field name="rma_id" groups="rma.group_rma_groups" />
<field name="origin" /> <field name="origin" />
<field name="date_rma" />
<field name="operation_id" domain="[('type','=','supplier')]" /> <field name="operation_id" domain="[('type','=','supplier')]" />
<field name="uom_id" groups="uom.group_uom" /> <field name="uom_id" groups="uom.group_uom" />
<field name="product_qty" /> <field name="product_qty" />
@@ -184,6 +186,7 @@
</group> </group>
<group> <group>
<group name="contact"> <group name="contact">
<field name="date_rma" />
<field name="requested_by" readonly="1" /> <field name="requested_by" readonly="1" />
<field name="assigned_to" /> <field name="assigned_to" />
<field name="type" invisible="1" /> <field name="type" invisible="1" />
@@ -385,6 +388,7 @@
<field name="assigned_to" /> <field name="assigned_to" />
<field name="product_id" /> <field name="product_id" />
<field name="lot_id" /> <field name="lot_id" />
<field name="date_rma" />
<separator /> <separator />
<filter <filter
name="assigned_to_filter" name="assigned_to_filter"