From 87818f7fccc045f6011ab8f4f96c447740d6f41e Mon Sep 17 00:00:00 2001 From: Olivier Colson Date: Wed, 16 May 2018 16:28:05 +0200 Subject: [PATCH] [FIX] purchase: anglosaxon accounting: use price difference account properly when making a refund MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before that, the following scenario failed due to FIFO handling of stock: - make PO 1 for 10 x product A at 10€/piece, receive and invoice everything - make PO 2 for 10 x product A at 20€/piece, receive and invoice everything - refund and send back PO 2 => With FIFO handling, it means the valuation corresponding to the return of product A consists of the first received products, hence 10x10=100€. The credit note, though, was made with the price of the invoice (200€) and did not (because of a too simple check) use the price difference account to post the missing amount (100€). Test test_fifo_anglosaxon_return (purchase/tests/test_stockvaluation.py) failed because of that. --- addons/purchase/models/account_invoice.py | 4 +--- addons/purchase/tests/test_stockvaluation.py | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/addons/purchase/models/account_invoice.py b/addons/purchase/models/account_invoice.py index 8b068509539..877ba90d0cf 100644 --- a/addons/purchase/models/account_invoice.py +++ b/addons/purchase/models/account_invoice.py @@ -218,9 +218,7 @@ class AccountInvoice(models.Model): price_unit_val_dif = price_unit - valuation_price_unit price_val_dif = price_before - interim_account_price - po_line = i_line.purchase_line_id - po_line_price_unit_inv_cur = po_line.currency_id.with_context(date=po_line.order_id.date_order).compute(po_line.price_unit, inv.currency_id) - if inv.currency_id.compare_amounts(i_line.price_unit, po_line_price_unit_inv_cur) != 0 and acc: + if inv.currency_id.compare_amounts(i_line.price_unit, valuation_price_unit) != 0 and acc: # If the unit prices have not changed and we have a # valuation difference, it means this difference is due to exchange rates, # so we don't create anything, the exchange rate entries will diff --git a/addons/purchase/tests/test_stockvaluation.py b/addons/purchase/tests/test_stockvaluation.py index 8e6b656558c..54fd5bc63f0 100644 --- a/addons/purchase/tests/test_stockvaluation.py +++ b/addons/purchase/tests/test_stockvaluation.py @@ -392,7 +392,7 @@ class TestStockValuationWithCOA(AccountingTestCase): stock_return_picking_action = stock_return_picking.create_returns() return_pick = self.env['stock.picking'].browse(stock_return_picking_action['res_id']) return_pick.move_lines[0].move_line_ids[0].qty_done = 10 - return_pick.do_transfer() + return_pick.button_validate() # valuation of product1 should be 200 as the first items will be sent out self.assertEqual(self.product1.stock_value, 200)