[FIX] account: Fix tax & tax group country_id recomputation
When changing the fiscal country of the company, the country of all taxes and tax groups belonging to this company are recomputed. However, moving taxes from one country to another doesn't make any sense since they are part of a chart template specific to a single country. This becomes more annoying when there are custom fields that depends of the current country in some localization. In this case, changing the country of the company will also erased some data coming from the chart template. At this point, the user will be forced to reload the whole chart template to recover those data. closes odoo/odoo#145423 X-original-commit: 58393169fb51db387562baaa67e9c9ca52ed066b Related: odoo/enterprise#52331 Signed-off-by: Olivier Colson (oco) <oco@odoo.com> Signed-off-by: Laurent Smet (las) <las@odoo.com>
This commit is contained in:
@@ -59,7 +59,7 @@ class AccountTaxGroup(models.Model):
|
||||
"If not set, the tax group will be displayed after the 'Untaxed amount' subtotal.",
|
||||
)
|
||||
|
||||
@api.depends('company_id.account_fiscal_country_id')
|
||||
@api.depends('company_id')
|
||||
def _compute_country_id(self):
|
||||
for group in self:
|
||||
group.country_id = group.company_id.account_fiscal_country_id or group.company_id.country_id
|
||||
@@ -219,7 +219,7 @@ class AccountTax(models.Model):
|
||||
if tax.is_used:
|
||||
raise ValidationError(_("This tax has been used in transactions. For that reason, it is forbidden to modify this field."))
|
||||
|
||||
@api.depends('company_id.account_fiscal_country_id')
|
||||
@api.depends('company_id')
|
||||
def _compute_country_id(self):
|
||||
for tax in self:
|
||||
tax.country_id = tax.company_id.account_fiscal_country_id or tax.company_id.country_id or tax.country_id
|
||||
|
||||
@@ -178,6 +178,16 @@ class AccountTestInvoicingCommon(TransactionCase):
|
||||
cls.inbound_payment_method_line = bank_journal.inbound_payment_method_line_ids[0]
|
||||
cls.outbound_payment_method_line = bank_journal.outbound_payment_method_line_ids[0]
|
||||
|
||||
@classmethod
|
||||
def change_company_country(cls, company, country):
|
||||
company.country_id = country
|
||||
company.account_fiscal_country_id = country
|
||||
for model in ('account.tax', 'account.tax.group'):
|
||||
cls.env.add_to_compute(
|
||||
cls.env[model]._fields['country_id'],
|
||||
cls.env[model].search([('company_id', '=', company.id)]),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def setup_company_data(cls, company_name, chart_template=None, **kwargs):
|
||||
''' Create a new company having the name passed as parameter.
|
||||
|
||||
@@ -23,7 +23,13 @@ class TestSalePrices(SaleCommon):
|
||||
|
||||
# Needed when run without demo data
|
||||
# s.t. taxes creation doesn't fail
|
||||
cls.env.company.account_fiscal_country_id = cls.env.ref('base.be')
|
||||
belgium = cls.env.ref('base.be')
|
||||
cls.env.company.account_fiscal_country_id = belgium
|
||||
for model in ('account.tax', 'account.tax.group'):
|
||||
cls.env.add_to_compute(
|
||||
cls.env[model]._fields['country_id'],
|
||||
cls.env[model].search([('company_id', '=', cls.env.company.id)]),
|
||||
)
|
||||
|
||||
def _create_discount_pricelist_rule(self, **additional_values):
|
||||
return self.env['product.pricelist.item'].create({
|
||||
|
||||
Reference in New Issue
Block a user