Skip to content

Commit 643d91e

Browse files
committed
[FIX] purchase_stock: price diff on vendor bill
Steps to reproduce: • Create Record: Product Category - Costing Method: Average - Inventory Valuation: Automated - Specify a price difference account (may create new account). - Ensure Stock Interim (Received) account is reconcilable. • Create Record: Product - Product Type: Storable - Cost Price: 1.01 - Product Category: New Product Category • Create bill with this product, for a quantity of 10.5 -> The is price difference of 0.1 Issue comes from this commit 286ea6b which doesn't round if there is a discount. With this commit we isolate the latter case in order to keep the price unit rounded if there is no discount. closes odoo#87666 Signed-off-by: Florian Gilbert <[email protected]>
1 parent 782c43c commit 643d91e

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

addons/purchase_stock/models/account_invoice.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,20 @@ def _stock_account_prepare_anglo_saxon_in_lines_vals(self):
9999

100100

101101
price_unit = line.price_unit * (1 - (line.discount or 0.0) / 100.0)
102-
if line.tax_ids and line.quantity:
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-
# multiply then divide the price unit.
108-
price_unit *= line.quantity
109-
price_unit = line.tax_ids.with_context(round=False, force_sign=move._get_tax_force_sign()).compute_all(
110-
price_unit, currency=move.currency_id, quantity=1.0, is_refund=move.move_type == 'in_refund')['total_excluded']
111-
price_unit /= line.quantity
102+
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']
112116

113117
price_unit_val_dif = price_unit - valuation_price_unit
114118
price_subtotal = line.quantity * price_unit_val_dif

addons/purchase_stock/tests/test_stockvaluation.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,3 +1326,28 @@ def test_anglosaxon_valuation_price_unit_diff_discount(self):
13261326
self.assertEqual(len(input_aml), 2, "Only two lines should have been generated in stock input account: one when receiving the product, one when making the invoice.")
13271327
self.assertAlmostEqual(sum(input_aml.mapped('debit')), 90, "Total debit value on stock input account should be equal to the original PO price of the product.")
13281328
self.assertAlmostEqual(sum(input_aml.mapped('credit')), 90, "Total credit value on stock input account should be equal to the original PO price of the product.")
1329+
1330+
def test_anglosaxon_valuation_price_unit_diff_avco(self):
1331+
"""
1332+
Inv: price unit: 100
1333+
"""
1334+
self.env.company.anglo_saxon_accounting = True
1335+
self.product1.categ_id.property_cost_method = 'average'
1336+
self.product1.categ_id.property_valuation = 'real_time'
1337+
self.product1.categ_id.property_account_creditor_price_difference_categ = self.price_diff_account
1338+
self.product1.standard_price = 1.01
1339+
1340+
invoice = self.env['account.move'].create({
1341+
'move_type': 'in_invoice',
1342+
'invoice_date': '2022-03-31',
1343+
'partner_id': self.partner_id.id,
1344+
'invoice_line_ids': [
1345+
(0, 0, {'product_id': self.product1.id, 'quantity': 10.50, 'price_unit': 1.01, 'tax_ids': self.tax_purchase_a.ids})
1346+
]
1347+
})
1348+
1349+
invoice.action_post()
1350+
1351+
# Check if something was posted in the price difference account
1352+
price_diff_aml = invoice.line_ids.filtered(lambda l: l.account_id == self.price_diff_account)
1353+
self.assertEqual(len(price_diff_aml), 0, "No line should have been generated in the price difference account.")

0 commit comments

Comments
 (0)