[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
committed by Carlos Vallés Fuster
parent 4f59aea9e3
commit 1a2599e866
3 changed files with 18 additions and 10 deletions

View File

@@ -3,7 +3,7 @@
{ {
"name": "RMA (Return Merchandise Authorization)", "name": "RMA (Return Merchandise Authorization)",
"version": "15.0.1.1.0", "version": "15.0.1.1.1",
"license": "LGPL-3", "license": "LGPL-3",
"category": "RMA", "category": "RMA",
"summary": "Introduces the return merchandise authorization (RMA) process in odoo", "summary": "Introduces the return merchandise authorization (RMA) process in odoo",

View File

@@ -303,7 +303,12 @@ class RmaOrderLine(models.Model):
readonly=True, readonly=True,
states={"draft": [("readonly", False)]}, states={"draft": [("readonly", False)]},
) )
price_unit = fields.Monetary(readonly=True, states={"draft": [("readonly", False)]}) price_unit = fields.Monetary(
string="Unit cost",
readonly=True,
states={"draft": [("readonly", False)]},
help="Unit cost of the items under RMA",
)
in_shipment_count = fields.Integer( in_shipment_count = fields.Integer(
compute="_compute_in_shipment_count", string="# of Shipments" compute="_compute_in_shipment_count", string="# of Shipments"
) )
@@ -636,15 +641,24 @@ class RmaOrderLine(models.Model):
) )
return super(RmaOrderLine, self).create(vals) 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") @api.onchange("product_id")
def _onchange_product_id(self): def _onchange_product_id(self):
result = {} result = {}
if not self.product_id: if not self.product_id:
return result return result
self.uom_id = self.product_id.uom_id.id self.uom_id = self.product_id.uom_id.id
self.price_unit = self.product_id.standard_price
if not self.type: if not self.type:
self.type = self._get_default_type() self.type = self._get_default_type()
self.price_unit = self._get_price_unit()
if self.type == "customer": if self.type == "customer":
self.operation_id = ( self.operation_id = (
self.product_id.rma_customer_operation_id self.product_id.rma_customer_operation_id

View File

@@ -36,11 +36,5 @@ class StockRule(models.Model):
res["partner_id"] = line.delivery_address_id.id res["partner_id"] = line.delivery_address_id.id
else: else:
res["partner_id"] = line.rma_id.partner_id.id res["partner_id"] = line.rma_id.partner_id.id
# We are not checking the reference move here because if stock account res["price_unit"] = line._get_price_unit()
# is not installed, there is no way to know the cost of the stock move
# so better use the standard cost in this case.
company_id = res["company_id"]
company = self.env["res.company"].browse(company_id)
cost = product_id.with_company(company).standard_price
res["price_unit"] = cost
return res return res