From 043aa0b158be4fb0c97fb951bd7f4d346e0f15fc Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Thu, 24 Nov 2016 16:26:46 +0100 Subject: [PATCH] [FIX] stock_account: _get_anglo_saxon_price_unit Backport of ab279d9ceaf46fc0f00cfb41303362e0916a612e 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 da0bd383187..4c6a968f514 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 f046bea5678..8c22ea70e25 100644 --- a/addons/sale_stock/sale_stock.py +++ b/addons/sale_stock/sale_stock.py @@ -336,7 +336,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 926622fc386..1f054a8021f 100644 --- a/addons/stock_account/stock_account.py +++ b/addons/stock_account/stock_account.py @@ -30,7 +30,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')