diff --git a/addons/account/__init__.py b/addons/account/__init__.py
index 7b967482ed0..27c64772919 100644
--- a/addons/account/__init__.py
+++ b/addons/account/__init__.py
@@ -10,9 +10,17 @@ from odoo import api, SUPERUSER_ID
SYSCOHADA_LIST = ['BJ', 'BF', 'CM', 'CF', 'KM', 'CG', 'CI', 'GA', 'GN', 'GW', 'GQ', 'ML', 'NE', 'CD', 'SN', 'TD', 'TG']
-def _auto_install_l10n(cr, registry):
+def _set_fiscal_country(env):
+ """ Sets the fiscal country on existing companies when installing the module.
+ That field is an editable computed field. It doesn't automatically get computed
+ on existing records by the ORM when installing the module, so doing that by hand
+ ensures existing records will get a value for it if needed.
+ """
+ env['res.company'].search([]).compute_account_tax_fiscal_country()
+
+
+def _auto_install_l10n(env):
#check the country of the main company (only) and eventually load some module needed in that country
- env = api.Environment(cr, SUPERUSER_ID, {})
country_code = env.company.country_id.code
if country_code:
#auto install localization module(s) if available
@@ -63,3 +71,8 @@ def _auto_install_l10n(cr, registry):
module_list.append('account_bank_statement_import_camt')
module_ids = env['ir.module.module'].search([('name', 'in', module_list), ('state', '=', 'uninstalled')])
module_ids.sudo().button_install()
+
+def _account_post_init(cr, registry):
+ env = api.Environment(cr, SUPERUSER_ID, {})
+ _auto_install_l10n(env)
+ _set_fiscal_country(env)
diff --git a/addons/account/__manifest__.py b/addons/account/__manifest__.py
index 0ebd0cac36f..d452cd5d10b 100644
--- a/addons/account/__manifest__.py
+++ b/addons/account/__manifest__.py
@@ -93,5 +93,5 @@ You could use this simplified accounting in case you work with an (external) acc
'installable': True,
'application': True,
'auto_install': False,
- 'post_init_hook': '_auto_install_l10n',
+ 'post_init_hook': '_account_post_init',
}
diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py
index f917ae40c55..2ea7494b4fc 100644
--- a/addons/account/models/account_move.py
+++ b/addons/account/models/account_move.py
@@ -2696,7 +2696,7 @@ class AccountMoveLine(models.Model):
company_currency_id = fields.Many2one(related='company_id.currency_id', string='Company Currency',
readonly=True, store=True,
help='Utility field to express amount currency')
- country_id = fields.Many2one(comodel_name='res.country', related='move_id.company_id.country_id')
+ tax_fiscal_country_id = fields.Many2one(comodel_name='res.country', related='move_id.company_id.account_tax_fiscal_country_id')
account_id = fields.Many2one('account.account', string='Account',
index=True, ondelete="cascade",
domain="[('deprecated', '=', False), ('company_id', '=', 'company_id'),('is_off_balance', '=', False)]",
diff --git a/addons/account/models/account_tax.py b/addons/account/models/account_tax.py
index d599d06f788..4e389fcd89f 100644
--- a/addons/account/models/account_tax.py
+++ b/addons/account/models/account_tax.py
@@ -91,7 +91,7 @@ class AccountTax(models.Model):
help="Account used to transition the tax amount for cash basis taxes. It will contain the tax amount as long as the original invoice has not been reconciled ; at reconciliation, this amount cancelled on this account and put on the regular tax account.")
invoice_repartition_line_ids = fields.One2many(string="Repartition for Invoices", comodel_name="account.tax.repartition.line", inverse_name="invoice_tax_id", copy=True, help="Repartition when the tax is used on an invoice")
refund_repartition_line_ids = fields.One2many(string="Repartition for Refund Invoices", comodel_name="account.tax.repartition.line", inverse_name="refund_tax_id", copy=True, help="Repartition when the tax is used on a refund")
- country_id = fields.Many2one(string='Country', comodel_name='res.country', related='company_id.country_id', help="Technical field used to restrict the domain of account tags for tax repartition lines created for this tax.")
+ tax_fiscal_country_id = fields.Many2one(string='Fiscal Country', comodel_name='res.country', related='company_id.account_tax_fiscal_country_id', help="Technical field used to restrict the domain of account tags for tax repartition lines created for this tax.")
_sql_constraints = [
('name_company_uniq', 'unique(name, company_id, type_tax_use, tax_scope)', 'Tax names must be unique !'),
@@ -108,15 +108,15 @@ class AccountTax(models.Model):
if 'refund_repartition_line_ids' in fields_list:
# We write on the related country_id field so that the field is recomputed. Without that, it will stay empty until we save the record.
rslt['refund_repartition_line_ids'] = [
- (0, 0, {'repartition_type': 'base', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': company_id, 'country_id': company.country_id.id}),
- (0, 0, {'repartition_type': 'tax', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': company_id, 'country_id': company.country_id.id}),
+ (0, 0, {'repartition_type': 'base', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': company_id, 'tax_fiscal_country_id': company.country_id.id}),
+ (0, 0, {'repartition_type': 'tax', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': company_id, 'tax_fiscal_country_id': company.country_id.id}),
]
if 'invoice_repartition_line_ids' in fields_list:
# We write on the related country_id field so that the field is recomputed. Without that, it will stay empty until we save the record.
rslt['invoice_repartition_line_ids'] = [
- (0, 0, {'repartition_type': 'base', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': company_id, 'country_id': company.country_id.id}),
- (0, 0, {'repartition_type': 'tax', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': company_id, 'country_id': company.country_id.id}),
+ (0, 0, {'repartition_type': 'base', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': company_id, 'tax_fiscal_country_id': company.country_id.id}),
+ (0, 0, {'repartition_type': 'tax', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': company_id, 'tax_fiscal_country_id': company.country_id.id}),
]
return rslt
@@ -636,7 +636,7 @@ class AccountTaxRepartitionLine(models.Model):
check_company=True,
help="The tax set to apply this repartition on refund invoices. Mutually exclusive with invoice_tax_id")
tax_id = fields.Many2one(comodel_name='account.tax', compute='_compute_tax_id')
- country_id = fields.Many2one(string="Country", comodel_name='res.country', related='company_id.country_id', help="Technical field used to restrict tags domain in form view.")
+ tax_fiscal_country_id = fields.Many2one(string="Fiscal Country", comodel_name='res.country', related='company_id.account_tax_fiscal_country_id', help="Technical field used to restrict tags domain in form view.")
company_id = fields.Many2one(string="Company", comodel_name='res.company', compute="_compute_company", store=True, help="The company this repartition line belongs to.")
sequence = fields.Integer(string="Sequence", default=1, help="The order in which display and match repartition lines. For refunds to work properly, invoice repartition lines should be arranged in the same order as the credit note repartition lines they correspond to.")
use_in_tax_closing = fields.Boolean(string="Tax Closing Entry")
diff --git a/addons/account/models/company.py b/addons/account/models/company.py
index 86e449db642..89cb05ab1a6 100644
--- a/addons/account/models/company.py
+++ b/addons/account/models/company.py
@@ -77,6 +77,7 @@ class ResCompany(models.Model):
property_stock_valuation_account_id = fields.Many2one('account.account', string="Account Template for Stock Valuation")
bank_journal_ids = fields.One2many('account.journal', 'company_id', domain=[('type', '=', 'bank')], string='Bank Journals')
tax_exigibility = fields.Boolean(string='Use Cash Basis')
+ account_tax_fiscal_country_id = fields.Many2one('res.country', string="Fiscal Country", compute='compute_account_tax_fiscal_country', store=True, readonly=False, help="The country to use the tax reports from for this company")
incoterm_id = fields.Many2one('account.incoterms', string='Default incoterm',
help='International Commercial Terms are a series of predefined commercial terms used in international transactions.')
@@ -147,6 +148,11 @@ class ResCompany(models.Model):
if rec.fiscalyear_last_day > max_day:
raise ValidationError(_("Invalid fiscal year last day"))
+ @api.depends('country_id')
+ def compute_account_tax_fiscal_country(self):
+ for record in self:
+ record.account_tax_fiscal_country_id = record.country_id
+
def get_and_update_account_invoice_onboarding_state(self):
""" This method is called on the controller rendering method and ensures that the animations
are displayed only one time. """
@@ -244,6 +250,7 @@ class ResCompany(models.Model):
if values.get('bank_account_code_prefix'):
new_bank_code = values.get('bank_account_code_prefix') or company.bank_account_code_prefix
company.reflect_code_prefix_change(company.bank_account_code_prefix, new_bank_code)
+
if values.get('cash_account_code_prefix'):
new_cash_code = values.get('cash_account_code_prefix') or company.cash_account_code_prefix
company.reflect_code_prefix_change(company.cash_account_code_prefix, new_cash_code)
@@ -589,16 +596,3 @@ class ResCompany(models.Model):
results_by_journal['results'].append(rslt)
return results_by_journal
-
- def get_fiscal_country(self):
- """ Returns the country to be used for this company's tax report.
- By default, it'll be the one from the address; but a config parameter
- may be used for each company to customize that behavior.
- """
- self.ensure_one()
-
- fiscal_country_key = 'account_fiscal_country_%s' % self.id
- forced_country_code = self.env['ir.config_parameter'].sudo().get_param(fiscal_country_key)
- forced_country = forced_country_code and self.env['res.country'].search([('code', 'ilike', forced_country_code)], limit=1)
-
- return forced_country or self.country_id
diff --git a/addons/account/views/account_move_views.xml b/addons/account/views/account_move_views.xml
index aed046689f0..2a70e60d9a3 100644
--- a/addons/account/views/account_move_views.xml
+++ b/addons/account/views/account_move_views.xml
@@ -953,8 +953,8 @@
-
-
+
+
-
+
-
+
@@ -133,7 +133,7 @@