[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) <jol@odoo.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -1032,6 +1032,9 @@
|
||||
<field name="quantity" optional="show"/>
|
||||
<field name="product_uom_category_id" column_invisible="True"/>
|
||||
<field name="product_uom_id" string="UoM" groups="uom.group_uom" optional="show"/>
|
||||
<!-- /l10n_in_edi.test_edi_json -->
|
||||
<!-- required for @api.onchange('product_id') -->
|
||||
<field name="product_uom_id" column_invisible="True"/>
|
||||
<field name="price_unit" string="Price"/>
|
||||
<field name="discount" string="Disc.%" optional="hide"/>
|
||||
<field name="tax_ids" widget="many2many_tags"
|
||||
@@ -1052,9 +1055,6 @@
|
||||
<field name="company_id" column_invisible="True"/>
|
||||
<field name="company_currency_id" column_invisible="True"/>
|
||||
<field name="display_type" force_save="1" column_invisible="True"/>
|
||||
<!-- /l10n_in_edi.test_edi_json -->
|
||||
<!-- required for @api.onchange('product_id') -->
|
||||
<field name="product_uom_id" column_invisible="True"/>
|
||||
</tree>
|
||||
<kanban class="o_kanban_mobile">
|
||||
<!-- Displayed fields -->
|
||||
|
||||
Reference in New Issue
Block a user