[FIX] purchase: use Product Price precision in bills
When the Product Price precision is greater than the currency precision,
it can lead to incorrect data
To reproduce the error:
(Enable debug mode)
1. Settings > Technical > Database Structure > Decimal Accuracy, edit
Product Price:
- Digits: 3
2. Create a PO
- Add a product:
- Quantity: 12
- Unit Price: 0.001
3. Save, Confirm, Edit the PO:
- Qty Received: 12
- (Note that the total is $0.01)
4. Create a bill:
- Add the PO to the field "Auto-Complete"
Error: The unit price is $0.000 and so does the total
The rounding of the unit price should be based on the Product Price
precision, not the currency precision.
OPW-2601867
closes odoo/odoo#74813
X-original-commit: 1123856c77cce4b69059b63c2bcbb382c7f0719e
Signed-off-by: Rémy Voet <ryv-odoo@users.noreply.github.com>
Signed-off-by: Adrien Widart <adwid@users.noreply.github.com>
This commit is contained in:
@@ -1260,7 +1260,7 @@ class PurchaseOrderLine(models.Model):
|
||||
'product_id': self.product_id.id,
|
||||
'product_uom_id': self.product_uom.id,
|
||||
'quantity': self.qty_to_invoice,
|
||||
'price_unit': self.currency_id._convert(self.price_unit, aml_currency, self.company_id, date),
|
||||
'price_unit': self.currency_id._convert(self.price_unit, aml_currency, self.company_id, date, round=False),
|
||||
'tax_ids': [(6, 0, self.taxes_id.ids)],
|
||||
'analytic_account_id': self.account_analytic_id.id,
|
||||
'analytic_tag_ids': [(6, 0, self.analytic_tag_ids.ids)],
|
||||
|
||||
@@ -275,3 +275,27 @@ class TestPurchaseToInvoice(AccountTestInvoicingCommon):
|
||||
self.assertEqual(len(amls), 2)
|
||||
self.assertEqual(amls[0].amount_currency, 1000)
|
||||
self.assertEqual(amls[1].amount_currency, 500)
|
||||
|
||||
def test_product_price_decimal_accuracy(self):
|
||||
self.env['ir.model.data'].xmlid_to_object('product.decimal_price').digits = 3
|
||||
self.env.company.currency_id.rounding = 0.01
|
||||
|
||||
po = self.env['purchase.order'].with_context(tracking_disable=True).create({
|
||||
'partner_id': self.partner_a.id,
|
||||
'order_line': [(0, 0, {
|
||||
'name': self.product_a.name,
|
||||
'product_id': self.product_a.id,
|
||||
'product_qty': 12,
|
||||
'product_uom': self.product_a.uom_id.id,
|
||||
'price_unit': 0.001,
|
||||
'taxes_id': False,
|
||||
})]
|
||||
})
|
||||
po.button_confirm()
|
||||
po.order_line.qty_received = 12
|
||||
|
||||
move_form = Form(self.env['account.move'].with_context(default_move_type='in_invoice'))
|
||||
move_form.purchase_vendor_bill_id = self.env['purchase.bill.union'].browse(-po.id)
|
||||
move = move_form.save()
|
||||
|
||||
self.assertEqual(move.amount_total, 0.01)
|
||||
|
||||
Reference in New Issue
Block a user