Skip to content

Commit

Permalink
Merge pull request #432 from ForgeFlow/14.0-imp-rma_line_date
Browse files Browse the repository at this point in the history
[14.0][IMP] rma: add date to rma_order_line
  • Loading branch information
AaronHForgeFlow authored Nov 22, 2023
2 parents 2f76541 + f155deb commit 74aee1d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
26 changes: 25 additions & 1 deletion rma/models/rma_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,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
Expand Down Expand Up @@ -192,6 +196,26 @@ def _onchange_operation(self):
self.in_route_id = self.operation_default_id.in_route_id
self.out_route_id = self.operation_default_id.out_route_id

@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(
Expand Down
7 changes: 7 additions & 0 deletions rma/models/rma_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ def _compute_rma_line_count(self):
for rec in self.filtered(lambda r: r.type == "supplier"):
rec.rma_line_count = len(rec.customer_rma_id)

@api.model
def _default_date_rma(self):
return fields.Datetime.now()

delivery_address_id = fields.Many2one(
comodel_name="res.partner",
string="Partner delivery address",
Expand Down Expand Up @@ -248,6 +252,9 @@ def _compute_rma_line_count(self):
states={"draft": [("readonly", False)]},
help="Reference of the document that produced this rma.",
)
date_rma = fields.Datetime(
string="Order Date", index=True, default=lambda self: self._default_date_rma()
)
state = fields.Selection(
selection=[
("draft", "Draft"),
Expand Down
4 changes: 4 additions & 0 deletions rma/views/rma_order_line_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
/>
<field name="rma_id" groups="rma.group_rma_groups" />
<field name="origin" />
<field name="date_rma" />
<field name="operation_id" />
<field name="supplier_address_id" />
<field name="uom_id" groups="uom.group_uom" />
Expand Down Expand Up @@ -47,6 +48,7 @@
/>
<field name="rma_id" groups="rma.group_rma_groups" />
<field name="origin" />
<field name="date_rma" />
<field name="operation_id" domain="[('type','=','supplier')]" />
<field name="uom_id" groups="uom.group_uom" />
<field name="product_qty" />
Expand Down Expand Up @@ -191,6 +193,7 @@
</group>
<group>
<group name="contact">
<field name="date_rma" />
<field name="requested_by" readonly="1" />
<field name="assigned_to" />
<field name="type" invisible="1" />
Expand Down Expand Up @@ -392,6 +395,7 @@
<field name="assigned_to" />
<field name="product_id" />
<field name="lot_id" />
<field name="date_rma" />
<separator />
<filter
name="assigned_to"
Expand Down

0 comments on commit 74aee1d

Please sign in to comment.