summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorAdrien Widart <awt@odoo.com>2021-04-28 09:01:24 +0000
committerAdrien Widart <awt@odoo.com>2021-05-04 12:54:54 +0000
commit75a122bbae3a32bfa79da3506179fc63a8bced5d (patch)
treec2d2d7142fd566a586efed2da47c27a88f1681be /addons
parent2b3ad9bfa9459b8e39d769afa8fa61ceef925c75 (diff)
[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#70319 X-original-commit: 6b93d5aadc7ac8251468292c9e55eedfc95e9f64 Signed-off-by: Steve Van Essche <svs-odoo@users.noreply.github.com> Signed-off-by: Adrien Widart <adwid@users.noreply.github.com>
Diffstat (limited to 'addons')
-rw-r--r--addons/repair/models/repair.py6
-rw-r--r--addons/repair/tests/test_repair.py41
2 files changed, 44 insertions, 3 deletions
diff --git a/addons/repair/models/repair.py b/addons/repair/models/repair.py
index da2e03bd726..6110ea751fa 100644
--- a/addons/repair/models/repair.py
+++ b/addons/repair/models/repair.py
@@ -706,7 +706,8 @@ class RepairLine(models.Model):
if self.type != 'remove':
if partner:
fpos = self.env['account.fiscal.position'].get_fiscal_position(partner_invoice.id, delivery_id=self.repair_id.address_id.id)
- self.tax_id = fpos.map_tax(self.product_id.taxes_id, self.product_id, partner)
+ taxes = self.product_id.taxes_id.filtered(lambda x: x.company_id == self.repair_id.company_id)
+ self.tax_id = fpos.map_tax(taxes, self.product_id, partner).ids
warning = False
pricelist = self.repair_id.pricelist_id
if not pricelist:
@@ -781,7 +782,8 @@ class RepairFee(models.Model):
if partner and self.product_id:
fpos = self.env['account.fiscal.position'].get_fiscal_position(partner_invoice.id, delivery_id=self.repair_id.address_id.id)
- self.tax_id = fpos.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 = fpos.map_tax(taxes, self.product_id, partner).ids
if partner:
self.name = self.product_id.with_context(lang=partner.lang).display_name
else:
diff --git a/addons/repair/tests/test_repair.py b/addons/repair/tests/test_repair.py
index 101364407fb..ec7ef4f59f7 100644
--- a/addons/repair/tests/test_repair.py
+++ b/addons/repair/tests/test_repair.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
-from odoo.tests import tagged
+from odoo.tests import tagged, Form
@tagged('post_install', '-at_install')
@@ -282,3 +282,42 @@ class TestRepair(AccountTestInvoicingCommon):
repair.action_repair_cancel_draft()
# Linked invoice should be unlinked
self.assertEqual(len(repair.invoice_id), 0, "No invoice should be exists 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)