From ff58ff20ab443bd041c70c91839fa35e2d2023b0 Mon Sep 17 00:00:00 2001 From: "Anh Thao Pham (pta)" Date: Tue, 5 Mar 2024 08:59:30 +0100 Subject: [PATCH] [FIX] account: fix totals computation Steps to reproduce: - Install Invoicing - Create a product with $0 cost (e.g. Product X) - Create a vendor bill: * Vendor: [any] * Invoice Lines: - Product: [none] - Label: [anything] - Price: [any] - Taxes: [any] => The displayed "Untaxed Amount", "Taxes" and "Total" are correct - Save the vendor bill - Edit the invoice line of the bill - Add Product X => "Untaxed Amount", "Taxes" and "Total" are correctly set to 0 as expected - Change Price to 100 manually Issue: "Untaxed Amount", "Taxes" and "Total" stay at $0. Upon save, "Untaxed Amount" is correctly set to $100, but "Taxes" stays at $0. If "Units of Measure" option is activated in the Settings (available with Sales, Purchase or Inventory app), the user will be in "uom.group_uom" and the issue will not happen. Cause: When the user isn't in "uom.group_uom" group, "product_uom_id" field is declared after "price_unit" field in the view. Due to that, adding a product in the invoice line and changing the price to $100, will first set "price_unit" to $100 and then set "product_uom_id" that will trigger "_compute_price_unit" method where "price_unit" is recomputed to $0 (its cost). Solution: Move "product_uom_id" field before "price_unit" field in the view as it is the case when the user is in "uom.group_uom" group. opw-3750740 closes odoo/odoo#156447 Signed-off-by: John Laterre (jol) --- .../tests/test_account_move_in_invoice.py | 50 +++++++++++++++++++ addons/account/views/account_move_views.xml | 6 +-- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/addons/account/tests/test_account_move_in_invoice.py b/addons/account/tests/test_account_move_in_invoice.py index 2a0d5c10363..f5cd4d62265 100644 --- a/addons/account/tests/test_account_move_in_invoice.py +++ b/addons/account/tests/test_account_move_in_invoice.py @@ -2565,3 +2565,53 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): with Form(self.invoice) as move_form: move_form.payment_reference = False self.assertEqual(payment_term_line.name, '', 'Payment term line was not changed') + + def test_taxes_onchange_product_uom_and_price_unit(self): + """ + Ensure that taxes are recomputed correctly when product uom and + price unit are changed for users without 'uom.group_uom' group + """ + self.env.user.groups_id -= self.env.ref('uom.group_uom') + tax = self.company_data['default_tax_purchase'] + product = self.env['product.product'].create({ + 'name': 'product', + 'uom_id': self.env.ref('uom.product_uom_unit').id, + 'standard_price': 0.0, + 'supplier_taxes_id': [Command.set(tax.ids)], + }) + expected_values = [ + { + 'tax_line_id': False, + 'debit': 100.0, + 'credit': 0.0, + }, + { + 'tax_line_id': tax.id, + 'debit': 15.0, + 'credit': 0.0, + }, + { + 'tax_line_id': False, + 'debit': 0.0, + 'credit': 115.0, + }, + ] + move_form = Form(self.env['account.move'].with_context(default_move_type='in_invoice')) + move_form.partner_id = self.partner_a + move_form.invoice_date = fields.Date.from_string('2024-03-01') + # add a line (without product) with a price of 100.0 and a 15% tax + with move_form.invoice_line_ids.new() as line_form: + line_form.name = 'no product' + line_form.price_unit = 100.0 + line_form.tax_ids.add(tax) + invoice = move_form.save() + self.assertRecordValues(invoice.line_ids, expected_values) + + move_form = Form(invoice) + # edit line to add a product and set price to 100.0 manually + # that should recompute the taxes + with move_form.invoice_line_ids.edit(0) as line_form: + line_form.product_id = product + line_form.price_unit = 100.0 + invoice = move_form.save() + self.assertRecordValues(invoice.line_ids, expected_values) diff --git a/addons/account/views/account_move_views.xml b/addons/account/views/account_move_views.xml index 7bb2b2654e1..c344af46122 100644 --- a/addons/account/views/account_move_views.xml +++ b/addons/account/views/account_move_views.xml @@ -1032,6 +1032,9 @@ + + + - - -