Skip to content

Commit 315a18f

Browse files
committed
[FIX] purchase_stock: wrong amount in price difference account
1. Activate anglo saxon accounting 2. Create product with automated inventory valuation and standard pricing 3. Set decimal accuracy to 6 4. Set product cost price to 0,01719 5. Create PO for 30.000 items -> price = 0,01782 -> total = 534,6 6. Receive goods -> stock journal entry = 515,7 (based on the cost, ok) 7. Create vendor bill Price difference is incorrect if you have a tax rate in the vendor bill `price_unit_val_dif` will be rounded to 0.02 Multiplied by a great quantity the result will be wrong (84.30) Without using the tax rate the price difference amount is the expected one This commit partially revert 643d91e to improve the original fix. opw-2849074 closes odoo#91621 Signed-off-by: Laurent Smet <[email protected]>
1 parent 849a561 commit 315a18f

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

addons/purchase_stock/models/account_invoice.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,16 @@ def _stock_account_prepare_anglo_saxon_in_lines_vals(self):
100100

101101
price_unit = line.price_unit * (1 - (line.discount or 0.0) / 100.0)
102102
if line.tax_ids:
103-
if line.discount and line.quantity:
104-
# We do not want to round the price unit since :
105-
# - It does not follow the currency precision
106-
# - It may include a discount
107-
# Since compute_all still rounds the total, we use an ugly workaround:
108-
# multiply then divide the price unit.
109-
price_unit *= line.quantity
110-
price_unit = line.tax_ids.with_context(round=False, force_sign=move._get_tax_force_sign()).compute_all(
111-
price_unit, currency=move.currency_id, quantity=1.0, is_refund=move.move_type == 'in_refund')['total_excluded']
112-
price_unit /= line.quantity
113-
else:
114-
price_unit = line.tax_ids.compute_all(
115-
price_unit, currency=move.currency_id, quantity=1.0, is_refund=move.move_type == 'in_refund')['total_excluded']
103+
# We do not want to round the price unit since :
104+
# - It does not follow the currency precision
105+
# - It may include a discount
106+
# Since compute_all still rounds the total, we use an ugly workaround:
107+
# shift the decimal part using a fixed quantity to avoid rounding issues
108+
prec = 1e+6
109+
price_unit *= prec
110+
price_unit = line.tax_ids.with_context(round=False, force_sign=move._get_tax_force_sign()).compute_all(
111+
price_unit, currency=move.currency_id, quantity=1.0, is_refund=move.move_type == 'in_refund')['total_excluded']
112+
price_unit /= prec
116113

117114
price_unit_val_dif = price_unit - valuation_price_unit
118115
price_subtotal = line.quantity * price_unit_val_dif

addons/purchase_stock/tests/test_stockvaluation.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,3 +1351,30 @@ def test_anglosaxon_valuation_price_unit_diff_avco(self):
13511351
# Check if something was posted in the price difference account
13521352
price_diff_aml = invoice.line_ids.filtered(lambda l: l.account_id == self.price_diff_account)
13531353
self.assertEqual(len(price_diff_aml), 0, "No line should have been generated in the price difference account.")
1354+
1355+
def test_anglosaxon_valuation_price_unit_diff_standard(self):
1356+
"""
1357+
Check the price unit difference account is hit with the correct amount
1358+
"""
1359+
self.env.ref("product.decimal_price").digits = 6
1360+
self.env.company.anglo_saxon_accounting = True
1361+
self.product1.categ_id.property_cost_method = 'standard'
1362+
self.product1.categ_id.property_valuation = 'real_time'
1363+
self.product1.categ_id.property_account_creditor_price_difference_categ = self.price_diff_account
1364+
self.product1.standard_price = 0.01719
1365+
1366+
invoice = self.env['account.move'].create({
1367+
'move_type': 'in_invoice',
1368+
'invoice_date': '2022-03-31',
1369+
'partner_id': self.partner_id.id,
1370+
'invoice_line_ids': [
1371+
(0, 0, {'product_id': self.product1.id, 'quantity': 30000, 'price_unit': 0.01782, 'tax_ids': self.tax_purchase_a.ids})
1372+
]
1373+
})
1374+
1375+
invoice.action_post()
1376+
1377+
# Check if something was posted in the price difference account
1378+
price_diff_aml = invoice.line_ids.filtered(lambda l: l.account_id == self.price_diff_account)
1379+
self.assertEqual(len(price_diff_aml), 1, "A line should have been generated in the price difference account.")
1380+
self.assertAlmostEqual(price_diff_aml.balance, 18.90)

0 commit comments

Comments
 (0)