diff --git a/rma_account/__manifest__.py b/rma_account/__manifest__.py index eb22180c..012c6945 100644 --- a/rma_account/__manifest__.py +++ b/rma_account/__manifest__.py @@ -3,7 +3,7 @@ { "name": "RMA Account", - "version": "15.0.1.1.0", + "version": "15.0.1.1.1", "license": "LGPL-3", "category": "RMA", "summary": "Integrates RMA with Invoice Processing", diff --git a/rma_account/models/account_move.py b/rma_account/models/account_move.py index 361abdd8..e28f89a3 100644 --- a/rma_account/models/account_move.py +++ b/rma_account/models/account_move.py @@ -234,15 +234,8 @@ class AccountMoveLine(models.Model): and bool(l.move_id.reversed_entry_id) == is_line_reversing ) qty_refunded = sum( -<<<<<<< HEAD x.product_uom_id._compute_quantity(x.quantity, x.product_id.uom_id) for x in posted_invoice_lines -======= - [ - x.product_uom_id._compute_quantity(x.quantity, x.product_id.uom_id) - for x in posted_invoice_lines - ] ->>>>>>> 614c98c ([FIX] include anglo-saxon price unit calculation in refunds.) ) product = self.product_id.with_company(self.company_id).with_context( is_returned=is_line_reversing diff --git a/rma_account/models/procurement.py b/rma_account/models/procurement.py index 7a3ae703..e065cfe9 100644 --- a/rma_account/models/procurement.py +++ b/rma_account/models/procurement.py @@ -4,40 +4,6 @@ from odoo import fields, models -class StockRule(models.Model): - _inherit = "stock.rule" - - def _get_stock_move_values( - self, - product_id, - product_qty, - product_uom, - location_id, - name, - origin, - company_id, - values, - ): - res = super(StockRule, self)._get_stock_move_values( - product_id, - product_qty, - product_uom, - location_id, - name, - origin, - company_id, - values, - ) - if "rma_line_id" in values: - line = values.get("rma_line_id") - line = self.env["rma.order.line"].browse([line]) - move = line.reference_move_id - if move and move.stock_valuation_layer_ids: - cost = move.stock_valuation_layer_ids[-1].unit_cost - res["price_unit"] = cost - return res - - class ProcurementGroup(models.Model): _inherit = "procurement.group" diff --git a/rma_account/models/rma_order_line.py b/rma_account/models/rma_order_line.py index ece41b2e..0231446d 100644 --- a/rma_account/models/rma_order_line.py +++ b/rma_account/models/rma_order_line.py @@ -333,3 +333,19 @@ class RmaOrderLine(models.Model): ) # Reconcile. amls.reconcile() + + def _get_price_unit(self): + self.ensure_one() + price_unit = super(RmaOrderLine, self)._get_price_unit() + if self.reference_move_id: + move = self.reference_move_id + layers = move.sudo().stock_valuation_layer_ids + if layers: + price_unit = sum(layers.mapped("value")) / sum( + layers.mapped("quantity") + ) + price_unit = price_unit + elif self.account_move_line_id and self.type == "supplier": + # We get the cost from the original invoice line + price_unit = self.account_move_line_id.price_unit + return price_unit diff --git a/rma_account/models/stock_move.py b/rma_account/models/stock_move.py index 1eb1ef02..c5872fa4 100644 --- a/rma_account/models/stock_move.py +++ b/rma_account/models/stock_move.py @@ -20,6 +20,7 @@ class StockMove(models.Model): != self.product_id.categ_id.property_stock_valuation_account_id.id ): line[2]["rma_line_id"] = self.rma_line_id.id + return res def _account_entry_move(self, qty, description, svl_id, cost): res = super(StockMove, self)._account_entry_move(qty, description, svl_id, cost)