[FIX] account: Cash rounding

Steps to reproduce:
- Enable Automated Valuation.
- Set the cost of Acoustic Bloc Screens to 287.33.
- Set the Product Category on the product to have AVCO automated valuation.
- Enable Cash Rounding.
- Create a Cash Rounding (see tests).
- Make an invoice selling one Acoustic Bloc Screen and remove the tax.
- Set the Cash Rounding on the invoice under "Other Info".
- Confirm the invoice.

Bug:
when summing the ammount of all the lines the result is slightly off
(float accuracy) this will create an unnecessary cash rounding to
compensate

Fix:
round the sum to the currency precision before checking for the cash rounding

opw-3681307

closes odoo/odoo#152112

X-original-commit: 4a6ec1a667ee3d2fba00d277b4c7e8a730a45ecd
Signed-off-by: Walid Hanniche (waha) <waha@odoo.com>
This commit is contained in:
Walid
2024-02-01 12:56:27 +00:00
parent ccb1f922b2
commit 3c87077d12
2 changed files with 33 additions and 0 deletions
@@ -61,5 +61,6 @@ class AccountCashRounding(models.Model):
:param amount: The amount
:return: round(difference)
"""
amount = currency.round(amount)
difference = self.round(amount) - amount
return currency.round(difference)
@@ -758,6 +758,38 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon):
'amount_total': 1384.0,
})
def test_compute_cash_rounding_lines(self):
cash_rounding_add_invoice_line = self.env['account.cash.rounding'].create({
'name': 'Add invoice line Rounding Down',
'rounding': .1,
'strategy': 'add_invoice_line',
'profit_account_id': self.company_data['default_account_revenue'].id,
'loss_account_id': self.company_data['default_account_expense'].id,
'rounding_method': 'DOWN',
})
move = self.env['account.move'].create({
'move_type': 'in_invoice',
'partner_id': self.partner_a.id,
'invoice_date': '2019-01-01',
'invoice_cash_rounding_id': cash_rounding_add_invoice_line.id,
'invoice_line_ids': [
Command.create({
'name': 'line',
'price_unit': 295,
'tax_ids': [],
}),
Command.create({
'name': 'cost',
'price_unit': 280.33,
}),
Command.create({
'name': 'cost neg',
'price_unit': -280.33,
}),
],
})
self.assertFalse(move.line_ids.filtered(lambda line: line.display_type == 'rounding'))
def test_in_invoice_line_onchange_cash_rounding_1(self):
# Required for `invoice_cash_rounding_id` to be visible in the view
self.env.user.groups_id += self.env.ref('account.group_cash_rounding')