[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 286ea6b681e9ba77357f91b546052449f6342f20
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/odoo#88734

X-original-commit: 643d91ef5ebfb29fde142294ced82c470d42c136
Signed-off-by: Florian Gilbert <flg@odoo.com>
This commit is contained in:
Guillaume (guva)
2022-04-14 07:17:53 +02:00
parent a50465bb3c
commit 4432ce5f7f
2 changed files with 39 additions and 10 deletions
+14 -10
View File
@@ -99,16 +99,20 @@ class AccountMove(models.Model):
price_unit = line.price_unit * (1 - (line.discount or 0.0) / 100.0)
if line.tax_ids and line.quantity:
# We do not want to round the price unit since :
# - It does not follow the currency precision
# - It may include a discount
# Since compute_all still rounds the total, we use an ugly workaround:
# multiply then divide the price unit.
price_unit *= line.quantity
price_unit = line.tax_ids.with_context(round=False, force_sign=move._get_tax_force_sign()).compute_all(
price_unit, currency=move.currency_id, quantity=1.0, is_refund=move.move_type == 'in_refund')['total_excluded']
price_unit /= line.quantity
if line.tax_ids:
if line.discount and line.quantity:
# We do not want to round the price unit since :
# - It does not follow the currency precision
# - It may include a discount
# Since compute_all still rounds the total, we use an ugly workaround:
# multiply then divide the price unit.
price_unit *= line.quantity
price_unit = line.tax_ids.with_context(round=False, force_sign=move._get_tax_force_sign()).compute_all(
price_unit, currency=move.currency_id, quantity=1.0, is_refund=move.move_type == 'in_refund')['total_excluded']
price_unit /= line.quantity
else:
price_unit = line.tax_ids.compute_all(
price_unit, currency=move.currency_id, quantity=1.0, is_refund=move.move_type == 'in_refund')['total_excluded']
price_unit_val_dif = price_unit - valuation_price_unit
price_subtotal = line.quantity * price_unit_val_dif
@@ -1276,3 +1276,28 @@ class TestStockValuationWithCOA(AccountTestInvoicingCommon):
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.")
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.")
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.")
def test_anglosaxon_valuation_price_unit_diff_avco(self):
"""
Inv: price unit: 100
"""
self.env.company.anglo_saxon_accounting = True
self.product1.categ_id.property_cost_method = 'average'
self.product1.categ_id.property_valuation = 'real_time'
self.product1.categ_id.property_account_creditor_price_difference_categ = self.price_diff_account
self.product1.standard_price = 1.01
invoice = self.env['account.move'].create({
'move_type': 'in_invoice',
'invoice_date': '2022-03-31',
'partner_id': self.partner_id.id,
'invoice_line_ids': [
(0, 0, {'product_id': self.product1.id, 'quantity': 10.50, 'price_unit': 1.01, 'tax_ids': self.tax_purchase_a.ids})
]
})
invoice.action_post()
# Check if something was posted in the price difference account
price_diff_aml = invoice.line_ids.filtered(lambda l: l.account_id == self.price_diff_account)
self.assertEqual(len(price_diff_aml), 0, "No line should have been generated in the price difference account.")