diff --git a/rma/__manifest__.py b/rma/__manifest__.py index d3022fd77..c44123925 100644 --- a/rma/__manifest__.py +++ b/rma/__manifest__.py @@ -3,7 +3,7 @@ { 'name': 'RMA (Return Merchandise Authorization)', - 'version': '12.0.2.3.0', + 'version': '12.0.2.3.1', 'license': 'LGPL-3', 'category': 'RMA', 'summary': 'Introduces the return merchandise authorization (RMA) process ' diff --git a/rma/models/procurement.py b/rma/models/procurement.py index a3dc86969..f823ece96 100644 --- a/rma/models/procurement.py +++ b/rma/models/procurement.py @@ -27,10 +27,7 @@ def _get_stock_move_values(self, product_id, product_qty, product_uom, res['partner_id'] = line.delivery_address_id.id else: res["partner_id"] = line.rma_id.partner_id.id - 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 + res["price_unit"] = line._get_price_unit() return res diff --git a/rma/models/rma_order_line.py b/rma/models/rma_order_line.py index 33bcb493b..6fa4ba00a 100644 --- a/rma/models/rma_order_line.py +++ b/rma/models/rma_order_line.py @@ -239,8 +239,10 @@ def _compute_rma_line_count(self): readonly=True, 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') @@ -504,15 +506,24 @@ def create(self, vals): 'rma.order.line.customer') return super(RmaOrderLine, self).create(vals) - @api.onchange('product_id') + 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 or \ self.product_id.categ_id.rma_customer_operation_id diff --git a/rma_account/__manifest__.py b/rma_account/__manifest__.py index 47ddd0b08..535d68507 100644 --- a/rma_account/__manifest__.py +++ b/rma_account/__manifest__.py @@ -3,7 +3,7 @@ { 'name': 'RMA Account', - 'version': '12.0.1.0.0', + 'version': '12.0.1.0.1', 'license': 'LGPL-3', 'category': 'RMA', 'summary': 'Integrates RMA with Invoice Processing', diff --git a/rma_account/models/rma_order_line.py b/rma_account/models/rma_order_line.py index f15389aca..797e0b112 100644 --- a/rma_account/models/rma_order_line.py +++ b/rma_account/models/rma_order_line.py @@ -236,3 +236,13 @@ def name_get(self): return res else: return super(RmaOrderLine, self).name_get() + + def _get_price_unit(self): + self.ensure_one() + price_unit = super(RmaOrderLine, self)._get_price_unit() + if self.reference_move_id and self.reference_move_id.value: + price_unit = self.reference_move_id.value + elif self.invoice_line_id and self.type == "supplier": + # We get the cost from the original invoice line + price_unit = self.invoice_line_id.price_unit + return price_unit diff --git a/rma_purchase/__manifest__.py b/rma_purchase/__manifest__.py index 62ae5af85..10c442d2b 100644 --- a/rma_purchase/__manifest__.py +++ b/rma_purchase/__manifest__.py @@ -2,7 +2,7 @@ # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) { 'name': 'RMA Purchase', - 'version': '12.0.1.0.0', + 'version': '12.0.1.0.1', 'category': 'RMA', 'summary': 'RMA from PO', 'license': 'LGPL-3', diff --git a/rma_purchase/models/rma_order_line.py b/rma_purchase/models/rma_order_line.py index c2a7b4a7b..b944fbc29 100644 --- a/rma_purchase/models/rma_order_line.py +++ b/rma_purchase/models/rma_order_line.py @@ -201,3 +201,21 @@ def _get_rma_purchased_qty(self): qty += self.uom_id._compute_quantity( line.product_qty, line.product_uom) return qty + + def _get_price_unit(self): + self.ensure_one() + price_unit = super(RmaOrderLine, self)._get_price_unit() + if self.purchase_order_line_id: + moves = self.purchase_order_line_id.move_ids + if moves: + price_unit = sum(moves.mapped("value")) / sum( + moves.mapped("product_qty") + ) + elif self.invoice_line_id.purchase_line_id: + purchase_lines = self.invoice_line_id.purchase_line_id + moves = purchase_lines.mapped("move_ids") + if moves: + price_unit = sum(moves.mapped("value")) / sum( + moves.mapped("product_qty") + ) + return price_unit diff --git a/rma_sale/__manifest__.py b/rma_sale/__manifest__.py index bba86a048..420a0f127 100644 --- a/rma_sale/__manifest__.py +++ b/rma_sale/__manifest__.py @@ -3,7 +3,7 @@ { 'name': 'RMA Sale', - 'version': '12.0.1.1.0', + 'version': '12.0.1.1.1', 'license': 'LGPL-3', 'category': 'RMA', 'summary': 'Links RMA with Sales Orders', diff --git a/rma_sale/models/rma_order_line.py b/rma_sale/models/rma_order_line.py index d4745bd8a..6b3449324 100644 --- a/rma_sale/models/rma_order_line.py +++ b/rma_sale/models/rma_order_line.py @@ -178,3 +178,29 @@ def _get_rma_sold_qty(self): lambda p: p.state not in ('draft', 'sent', 'cancel')): qty += sale_line.product_uom_qty return qty + + def _get_price_unit(self): + self.ensure_one() + price_unit = super(RmaOrderLine, self)._get_price_unit() + if self.sale_line_id: + moves = self.sale_line_id.move_ids.filtered( + lambda x: x.state == "done" + and x.location_id.usage in ("internal", "supplier") + and x.location_dest_id.usage == "customer" + ) + if moves: + price_unit = sum(moves.mapped("value")) / sum( + moves.mapped("product_qty") + ) + elif self.invoice_line_id: + sale_lines = self.invoice_line_id.sale_line_ids + moves = sale_lines.mapped("move_ids").filtered( + lambda x: x.state == "done" + and x.location_id.usage in ("internal", "supplier") + and x.location_dest_id.usage == "customer" + ) + if moves: + price_unit = sum(moves.mapped("value")) / sum( + moves.mapped("product_qty") + ) + return price_unit