From 954f05367e4db28eab5745940bab2fd1099ccda5 Mon Sep 17 00:00:00 2001 From: aliya Date: Wed, 29 Dec 2021 10:23:46 +0000 Subject: [PATCH] [IMP] account, l10n_generic: change default fiscal country Task ID: 2717840 Currently: - Generic_coa has country_id US, which is not valid for non-supported localizations. This creates a bug as the country on taxes and account_fiscal_country_id becomes different. - Users who only have Invoicing installed can't change the fiscal country setting as it's only available in Accounting. Desired: - Set account_fiscal_country_id the same as country_id - Remove base.us from l10n_generic_coa - Adjust the error message to make the issue more clear for users - Allow changing fiscal country in Invoicing closes odoo/odoo#91363 Related: odoo/enterprise#27332 Related: odoo/upgrade#3264 Signed-off-by: Laurent Smet --- addons/account/models/account_move.py | 4 +++- addons/account/models/chart_template.py | 11 +++++++---- addons/account/models/res_config_settings.py | 1 + addons/account/views/res_config_settings_views.xml | 13 +++++++++++++ addons/l10n_generic_coa/data/l10n_generic_coa.xml | 2 +- .../l10n_generic_coa/data/l10n_generic_coa_post.xml | 1 - 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 0ec323c7ba3..2dff3accf66 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -1960,7 +1960,9 @@ class AccountMove(models.Model): amls = record.line_ids impacted_countries = amls.tax_ids.country_id | amls.tax_line_id.country_id | amls.tax_tag_ids.country_id if impacted_countries and impacted_countries != record.tax_country_id: - raise ValidationError(_("This entry contains some tax from an unallowed country. Please check its fiscal position and your tax configuration.")) + if record.fiscal_position_id and impacted_countries != record.fiscal_position_id.country_id: + raise ValidationError(_("This entry contains taxes that are not compatible with your fiscal position. Check the country set in fiscal position and in your tax configuration.")) + raise ValidationError(_("This entry contains one or more taxes that are incompatible with your fiscal country. Check company fiscal country in the settings and tax country in taxes configuration.")) # ------------------------------------------------------------------------- # LOW-LEVEL METHODS diff --git a/addons/account/models/chart_template.py b/addons/account/models/chart_template.py index ce02ddb3e90..41b728af59b 100644 --- a/addons/account/models/chart_template.py +++ b/addons/account/models/chart_template.py @@ -275,6 +275,13 @@ class AccountChartTemplate(models.Model): except ValueError: pass + # Set the fiscal country before generating taxes in case the company does not have a country_id set yet + if self.country_id: + # If this CoA is made for only one country, set it as the fiscal country of the company. + company.account_fiscal_country_id = self.country_id + elif not company.account_fiscal_country_id: + company.account_fiscal_country_id = self.env.ref('base.us') + # Install all the templates objects and generate the real objects acc_template_ref, taxes_ref = self._install_template(company, code_digits=self.code_digits) @@ -333,10 +340,6 @@ class AccountChartTemplate(models.Model): company.account_sale_tax_id = self.env['account.tax'].search([('type_tax_use', 'in', ('sale', 'all')), ('company_id', '=', company.id)], limit=1).id company.account_purchase_tax_id = self.env['account.tax'].search([('type_tax_use', 'in', ('purchase', 'all')), ('company_id', '=', company.id)], limit=1).id - if self.country_id: - # If this CoA is made for only one country, set it as the fiscal country of the company. - company.account_fiscal_country_id = self.country_id - return {} @api.model diff --git a/addons/account/models/res_config_settings.py b/addons/account/models/res_config_settings.py index 14a013c462d..f9acdd443dd 100644 --- a/addons/account/models/res_config_settings.py +++ b/addons/account/models/res_config_settings.py @@ -126,6 +126,7 @@ class ResConfigSettings(models.TransientModel): readonly=False, related='company_id.account_cash_basis_base_account_id', domain=[('deprecated', '=', False)]) + account_fiscal_country_id = fields.Many2one(string="Fiscal Country Code", related="company_id.account_fiscal_country_id", readonly=False, store=False) qr_code = fields.Boolean(string='Display SEPA QR-code', related='company_id.qr_code', readonly=False) invoice_is_print = fields.Boolean(string='Print', related='company_id.invoice_is_print', readonly=False) diff --git a/addons/account/views/res_config_settings_views.xml b/addons/account/views/res_config_settings_views.xml index 16852b6381e..aa407f9cb8d 100644 --- a/addons/account/views/res_config_settings_views.xml +++ b/addons/account/views/res_config_settings_views.xml @@ -130,6 +130,19 @@ +
+
+
+ Fiscal Country + +
+ Domestic country of your accounting +
+
+ +
+
+

Currencies

diff --git a/addons/l10n_generic_coa/data/l10n_generic_coa.xml b/addons/l10n_generic_coa/data/l10n_generic_coa.xml index 5dcf99fcb69..417250bf93b 100644 --- a/addons/l10n_generic_coa/data/l10n_generic_coa.xml +++ b/addons/l10n_generic_coa/data/l10n_generic_coa.xml @@ -8,6 +8,6 @@ 1015 1017 - + diff --git a/addons/l10n_generic_coa/data/l10n_generic_coa_post.xml b/addons/l10n_generic_coa/data/l10n_generic_coa_post.xml index e46d7e89641..8d8145ebd9d 100644 --- a/addons/l10n_generic_coa/data/l10n_generic_coa_post.xml +++ b/addons/l10n_generic_coa/data/l10n_generic_coa_post.xml @@ -4,7 +4,6 @@ Tax 15% -