[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#70352
X-original-commit: 75a122bbae3a32bfa79da3506179fc63a8bced5d
Signed-off-by: Steve Van Essche <svs-odoo@users.noreply.github.com>
Signed-off-by: Adrien Widart <adwid@users.noreply.github.com>
This commit is contained in:
@@ -710,7 +710,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:
|
||||
@@ -785,7 +786,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:
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user