Skip to content
Snippets Groups Projects
Commit 6b93d5aa authored by Adrien Widart's avatar Adrien Widart
Browse files

[FIX] repair: filter taxes with current company


When adding a product to a repair order, the module automatically adds
all product's taxes, even if some taxes belong to other companies.

To reproduce the error
(Need 2 companies C01 and C02. Let C01 be the current company)
1. Create a product P
    - Must have a tax T_C01
2. Switch to C02
3. Edit P
    - Add a tax T_C02
4. Activate C01
5. Create a Repair Order
    - Add a customer
    - Add a line with product P

Error: Both T_C01 and T_C02 are added. However, since C02 is the current
company, T_C01 should not be added.

(Similar issue possible with `repair.fee`)

OPW-2486791
closes #68079

closes odoo/odoo#69975

Signed-off-by: default avatarSteve Van Essche <svs-odoo@users.noreply.github.com>
parent 959052e9
Branches
Tags
No related merge requests found
......@@ -672,7 +672,8 @@ class RepairLine(models.Model):
# Check automatic detection
fp_id = self.env['account.fiscal.position'].get_fiscal_position(partner.id, delivery_id=self.repair_id.address_id.id)
fp = self.env['account.fiscal.position'].browse(fp_id)
self.tax_id = fp.map_tax(self.product_id.taxes_id, self.product_id, partner).ids
taxes = self.product_id.taxes_id.filtered(lambda x: x.company_id == self.repair_id.company_id)
self.tax_id = fp.map_tax(taxes, self.product_id, partner).ids
warning = False
if not pricelist:
warning = {
......@@ -739,7 +740,8 @@ class RepairFee(models.Model):
# Check automatic detection
fp_id = self.env['account.fiscal.position'].get_fiscal_position(partner.id, delivery_id=self.repair_id.address_id.id)
fp = self.env['account.fiscal.position'].browse(fp_id)
self.tax_id = fp.map_tax(self.product_id.taxes_id, self.product_id, partner).ids
taxes = self.product_id.taxes_id.filtered(lambda x: x.company_id == self.repair_id.company_id)
self.tax_id = fp.map_tax(taxes, self.product_id, partner).ids
if self.product_id:
if partner:
self.name = self.product_id.with_context(lang=partner.lang).display_name
......
......@@ -4,7 +4,7 @@
from datetime import datetime
from odoo.addons.account.tests.account_test_classes import AccountingTestCase
from odoo.tests import tagged
from odoo.tests import tagged, Form
@tagged('post_install', '-at_install')
......@@ -168,3 +168,42 @@ class TestRepair(AccountingTestCase):
# I define Invoice Method 'No Invoice' option in this repair order.
# So, I check that Invoice has not been created for this repair order.
self.assertNotEqual(len(repair.invoice_id), 1, "Invoice should not exist for this repair order")
def test_03_repair_multicompany(self):
""" This test ensures that the correct taxes are selected when the user fills in the RO form """
company01 = self.env.company
company02 = self.env['res.company'].create({
'name': 'SuperCompany',
})
tax01 = self.env["account.tax"].create({
"name": "C01 Tax",
"amount": "0.00",
"company_id": company01.id
})
tax02 = self.env["account.tax"].create({
"name": "C02 Tax",
"amount": "0.00",
"company_id": company02.id
})
super_product = self.env['product.template'].create({
"name": "SuperProduct",
"taxes_id": [(4, tax01.id), (4, tax02.id)],
})
super_variant = super_product.product_variant_id
self.assertEqual(super_variant.taxes_id, tax01 | tax02)
ro_form = Form(self.env['repair.order'])
ro_form.product_id = super_variant
ro_form.partner_id = company01.partner_id
with ro_form.operations.new() as ro_line:
ro_line.product_id = super_variant
with ro_form.fees_lines.new() as fee_line:
fee_line.product_id = super_variant
repair_order = ro_form.save()
# tax02 should not be present since it belongs to the second company.
self.assertEqual(repair_order.operations.tax_id, tax01)
self.assertEqual(repair_order.fees_lines.tax_id, tax01)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment