[FIX] purchase: anglosaxon accounting: use price difference account properly when making a refund

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.
This commit is contained in:
Olivier Colson
2018-05-16 16:38:46 +02:00
parent 92abf95a87
commit 87818f7fcc
2 changed files with 2 additions and 4 deletions
+1 -3
View File
@@ -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
+1 -1
View File
@@ -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)