From ab279d9ceaf46fc0f00cfb41303362e0916a612e Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Wed, 16 Nov 2016 12:45:49 +0100 Subject: [PATCH] [FIX] stock_account: _get_anglo_saxon_price_unit When getting the price from a account.move.line, the uom set on the line must be taken into account. Before the fix: -Set anglo-saxon accounting -Create two units of measure Box and Mot where 1Mot = 10Box -Create a stockable product with Box as unit of reference and set with real price and perpetual -Create a SO with a Mot of this product -Confirm the SO and create the invoice -Validate the invoice Bug: In the journal of entries, only one box was counted for the debit and the credit instead of 10. NB: The function _get_anglo_saxon_price_unit must return the price unit of the product in the unit of measure of the account.invoice.line. opw:693075 --- addons/sale_mrp/sale_mrp.py | 2 +- addons/sale_stock/sale_stock.py | 2 +- addons/stock_account/stock_account.py | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/addons/sale_mrp/sale_mrp.py b/addons/sale_mrp/sale_mrp.py index e02c87ff656..bcb2c1442ee 100644 --- a/addons/sale_mrp/sale_mrp.py +++ b/addons/sale_mrp/sale_mrp.py @@ -143,5 +143,5 @@ class AccountInvoiceLine(models.Model): prod_quantity = factor * quantity average_price_unit += self._compute_average_price(prod_qty_done, prod_quantity, prod_moves) price_unit = average_price_unit or price_unit - price_unit = uom_obj._compute_qty_obj(self.uom_id, price_unit, self.product_id.uom_id, round=False) + price_unit = self.product_id.uom_id._compute_price(self.product_id.uom_id.id, price_unit, to_uom_id=self.uom_id.id) return price_unit diff --git a/addons/sale_stock/sale_stock.py b/addons/sale_stock/sale_stock.py index 0754cdee820..88c2a227489 100644 --- a/addons/sale_stock/sale_stock.py +++ b/addons/sale_stock/sale_stock.py @@ -359,7 +359,7 @@ class AccountInvoiceLine(models.Model): # on the moves we encounter. average_price_unit = self._compute_average_price(qty_done, quantity, moves) price_unit = average_price_unit or price_unit - price_unit = uom_obj._compute_qty_obj(self.uom_id, price_unit, self.product_id.uom_id, round=False) + price_unit = self.product_id.uom_id._compute_price(self.product_id.uom_id.id, price_unit, to_uom_id=self.uom_id.id) return price_unit def _compute_average_price(self, qty_done, quantity, moves): diff --git a/addons/stock_account/stock_account.py b/addons/stock_account/stock_account.py index b545b44ce67..a85712960eb 100644 --- a/addons/stock_account/stock_account.py +++ b/addons/stock_account/stock_account.py @@ -31,7 +31,11 @@ class account_invoice_line(osv.osv): def _get_anglo_saxon_price_unit(self): self.ensure_one() - return self.product_id.standard_price + price = self.product_id.standard_price + if not self.uom_id or self.product_id.uom_id == self.uom_id: + return price + else: + return self.product_id.uom_id._compute_price(self.product_id.uom_id.id, price, to_uom_id=self.uom_id.id) def _get_price(self, cr, uid, inv, company_currency, i_line, price_unit): cur_obj = self.pool.get('res.currency')