[IMP] centralize the logic to get the correct cost of the RMA.

This commit is contained in:
Jordi Ballester Alomar
2022-11-23 15:26:03 +01:00
parent 3b86ea4b9c
commit b0f3dd97e5
12 changed files with 88 additions and 127 deletions

View File

@@ -308,7 +308,10 @@ class RmaOrderLine(models.Model):
states={"draft": [("readonly", False)]},
)
price_unit = fields.Monetary(
string="Price Unit", readonly=True, states={"draft": [("readonly", False)]}
string="Unit cost",
readonly=True,
states={"draft": [("readonly", False)]},
help="Unit cost of the items under RMA",
)
in_shipment_count = fields.Integer(
compute="_compute_in_shipment_count", string="# of Shipments"
@@ -651,15 +654,24 @@ class RmaOrderLine(models.Model):
)
return super(RmaOrderLine, self).create(vals)
def _get_price_unit(self):
"""The price unit corresponds to the cost of that product"""
self.ensure_one()
if self.reference_move_id:
price_unit = self.reference_move_id.price_unit
else:
price_unit = self.product_id.with_company(self.company_id).standard_price
return price_unit
@api.onchange("product_id")
def _onchange_product_id(self):
result = {}
if not self.product_id:
return result
self.uom_id = self.product_id.uom_id.id
self.price_unit = self.product_id.standard_price
if not self.type:
self.type = self._get_default_type()
self.price_unit = self._get_price_unit()
if self.type == "customer":
self.operation_id = (
self.product_id.rma_customer_operation_id