From 17610e8ca97b2e5315cc063ee3973f81ab910f5e Mon Sep 17 00:00:00 2001 From: oco-odoo Date: Tue, 23 Mar 2021 12:04:42 +0000 Subject: [PATCH] [IMP] account, account_edi, l10n_*, purchase, sale: Generalize the use of account_fiscal_country_id Before, account_fiscal_country_id was only use for tax operations; and country_id was used for all the other accounting stuff. Now, with the new ability to use foreign tax reports (with foreign VAT fiscal positions), we can generalize the fiscal country, sot that it is the one that needs to be used for the whole accounting. Since foreign tax reports were not supported before, account_fiscal_country_id is already set on existing database as the country for the "main" accounting, so the impact of this change is small. closes odoo/odoo#68349 Related: odoo/upgrade#2322 Related: odoo/enterprise#17299 Signed-off-by: Laurent Smet --- addons/account/models/account_bank_statement.py | 4 ++-- addons/account/models/account_journal.py | 2 +- addons/account/models/account_move.py | 2 +- addons/account/models/account_payment.py | 2 +- addons/account/models/partner.py | 2 +- addons/account/models/res_config_settings.py | 2 +- addons/account/views/report_invoice.xml | 2 +- .../account/wizard/account_payment_register.py | 8 ++++---- addons/account_edi/models/account_journal.py | 4 ++-- .../l10n_ae/views/report_invoice_templates.xml | 6 +++--- addons/l10n_ar/models/account_fiscal_position.py | 2 +- addons/l10n_ar/models/account_journal.py | 4 ++-- addons/l10n_ar/models/account_move.py | 16 ++++++++-------- addons/l10n_ar/views/report_invoice.xml | 2 +- addons/l10n_ca/views/report_invoice.xml | 2 +- addons/l10n_ch/models/account_bank_statement.py | 2 +- addons/l10n_ch/models/account_invoice.py | 2 +- addons/l10n_ch/models/res_bank.py | 6 +++--- addons/l10n_cl/models/account_chart_template.py | 2 +- addons/l10n_cl/models/account_move.py | 10 +++++----- addons/l10n_cl/models/res_company.py | 2 +- addons/l10n_cl/views/report_invoice.xml | 2 +- addons/l10n_de/models/chart_template.py | 4 ++-- addons/l10n_de/models/datev.py | 4 ++-- addons/l10n_de/report/din5008_report.xml | 2 +- addons/l10n_dk/models/account_chart_template.py | 2 +- addons/l10n_dk/models/account_journal.py | 2 +- addons/l10n_do/models/chart_template.py | 2 +- .../models/res_config_settings.py | 2 +- addons/l10n_eu_service/wizard/wizard.py | 4 ++-- addons/l10n_fr/models/account_chart_template.py | 2 +- addons/l10n_fr_fec/wizard/account_fr_fec.py | 2 +- addons/l10n_in/models/account.py | 6 +++--- addons/l10n_in/models/account_invoice.py | 9 ++++----- addons/l10n_in/views/account_invoice_views.xml | 6 +++--- addons/l10n_in/views/report_invoice.xml | 12 ++++++------ addons/l10n_in_pos/models/pos_order.py | 2 +- addons/l10n_in_purchase/models/purchase_order.py | 2 +- .../views/report_purchase_order.xml | 4 ++-- addons/l10n_in_sale/models/sale_order.py | 2 +- .../views/report_stockpicking_operations.xml | 2 +- .../l10n_it_stock_ddt/models/account_invoice.py | 2 +- addons/l10n_it_stock_ddt/models/stock_picking.py | 2 +- .../report/l10n_it_ddt_report.xml | 2 +- addons/l10n_latam_base/models/res_partner.py | 2 +- .../models/account_move.py | 2 +- addons/l10n_lu/models/account_chart_template.py | 2 +- addons/l10n_mx/models/account.py | 2 +- addons/l10n_mx/models/chart_template.py | 2 +- addons/l10n_nl/models/account_chart_template.py | 4 ++-- addons/l10n_nl/models/account_journal.py | 2 +- addons/l10n_se/models/res_company.py | 2 +- .../purchase/report/purchase_order_templates.xml | 2 +- .../report/purchase_quotation_templates.xml | 2 +- addons/sale/report/sale_report_templates.xml | 2 +- 55 files changed, 93 insertions(+), 94 deletions(-) diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py index 78ee2f6edc9..bbe44eb877a 100644 --- a/addons/account/models/account_bank_statement.py +++ b/addons/account/models/account_bank_statement.py @@ -249,7 +249,7 @@ class AccountBankStatement(models.Model): is_valid_balance_start = fields.Boolean(string="Is Valid Balance Start", store=True, compute="_compute_is_valid_balance_start", help="Technical field to display a warning message in case starting balance is different than previous ending balance") - country_code = fields.Char(related='company_id.country_id.code') + country_code = fields.Char(related='company_id.account_fiscal_country_id.code') def write(self, values): res = super(AccountBankStatement, self).write(values) @@ -549,7 +549,7 @@ class AccountBankStatementLine(models.Model): compute='_compute_is_reconciled', help="Technical field indicating if the statement line is already reconciled.") state = fields.Selection(related='statement_id.state', string='Status', readonly=True) - country_code = fields.Char(related='company_id.country_id.code') + country_code = fields.Char(related='company_id.account_fiscal_country_id.code') # ------------------------------------------------------------------------- # HELPERS diff --git a/addons/account/models/account_journal.py b/addons/account/models/account_journal.py index 152ab075121..2bb565b9a32 100644 --- a/addons/account/models/account_journal.py +++ b/addons/account/models/account_journal.py @@ -118,7 +118,7 @@ class AccountJournal(models.Model): currency_id = fields.Many2one('res.currency', help='The currency used to enter statement', string="Currency") company_id = fields.Many2one('res.company', string='Company', required=True, readonly=True, index=True, default=lambda self: self.env.company, help="Company related to this journal") - country_code = fields.Char(related='company_id.country_id.code', readonly=True) + country_code = fields.Char(related='company_id.account_fiscal_country_id.code', readonly=True) refund_sequence = fields.Boolean(string='Dedicated Credit Note Sequence', help="Check this box if you don't want to share the same sequence for invoices and credit notes made from this journal", default=False) sequence_override_regex = fields.Text(help="Technical field used to enforce complex sequence composition that the system would normally misunderstand.\n"\ diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index a599d5e63d1..5f365b4d833 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -184,7 +184,7 @@ class AccountMove(models.Model): string='Partner', change_default=True) commercial_partner_id = fields.Many2one('res.partner', string='Commercial Entity', store=True, readonly=True, compute='_compute_commercial_partner_id') - country_code = fields.Char(related='company_id.country_id.code', readonly=True) + country_code = fields.Char(related='company_id.account_fiscal_country_id.code', readonly=True) user_id = fields.Many2one(string='User', related='invoice_user_id', help='Technical field used to fit the generic behavior in mail templates.') is_move_sent = fields.Boolean( diff --git a/addons/account/models/account_payment.py b/addons/account/models/account_payment.py index 992b0d322ee..b409b5a7247 100644 --- a/addons/account/models/account_payment.py +++ b/addons/account/models/account_payment.py @@ -129,7 +129,7 @@ class AccountPayment(models.Model): require_partner_bank_account = fields.Boolean( compute='_compute_show_require_partner_bank', help="Technical field used to know whether the field `partner_bank_id` needs to be required or not in the payments form views") - country_code = fields.Char(related='company_id.country_id.code') + country_code = fields.Char(related='company_id.account_fiscal_country_id.code') _sql_constraints = [ ( diff --git a/addons/account/models/partner.py b/addons/account/models/partner.py index 7eb1564da42..2ae789a5327 100644 --- a/addons/account/models/partner.py +++ b/addons/account/models/partner.py @@ -61,7 +61,7 @@ class AccountFiscalPosition(models.Model): raise ValidationError(_("You cannot create a fiscal position within your fiscal country with the same VAT number as the main one set on your company.")) if not record.state_ids: - if record.company_id.country_id.state_ids: + if record.company_id.account_fiscal_country_id.state_ids: raise ValidationError(_("You cannot create a fiscal position with a foreign VAT within your fiscal country without assigning it a state.")) else: raise ValidationError(_("You cannot create a fiscal position with a foreign VAT within your fiscal country.")) diff --git a/addons/account/models/res_config_settings.py b/addons/account/models/res_config_settings.py index a6efcb1ac34..88c746172b0 100644 --- a/addons/account/models/res_config_settings.py +++ b/addons/account/models/res_config_settings.py @@ -134,7 +134,7 @@ class ResConfigSettings(models.TransientModel): config_parameter='account.use_invoice_terms') # Technical field to hide country specific fields from accounting configuration - country_code = fields.Char(related='company_id.country_id.code', readonly=True) + country_code = fields.Char(related='company_id.account_fiscal_country_id.code', readonly=True) def set_values(self): super(ResConfigSettings, self).set_values() diff --git a/addons/account/views/report_invoice.xml b/addons/account/views/report_invoice.xml index 0cd4d19becf..df7f244ef6a 100644 --- a/addons/account/views/report_invoice.xml +++ b/addons/account/views/report_invoice.xml @@ -8,7 +8,7 @@
- + Tax ID:
diff --git a/addons/account/wizard/account_payment_register.py b/addons/account/wizard/account_payment_register.py index ce94197e7d4..84117880c67 100644 --- a/addons/account/wizard/account_payment_register.py +++ b/addons/account/wizard/account_payment_register.py @@ -103,7 +103,7 @@ class AccountPaymentRegister(models.TransientModel): require_partner_bank_account = fields.Boolean( compute='_compute_show_require_partner_bank', help="Technical field used to know whether the field `partner_bank_id` needs to be required or not in the payments form views") - country_code = fields.Char(related='company_id.country_id.code', readonly=True) + country_code = fields.Char(related='company_id.account_fiscal_country_id.code', readonly=True) # ------------------------------------------------------------------------- # HELPERS @@ -353,12 +353,12 @@ class AccountPaymentRegister(models.TransientModel): # ------------------------------------------------------------------------- # LOW-LEVEL METHODS # ------------------------------------------------------------------------- - + @api.model def default_get(self, fields_list): # OVERRIDE res = super().default_get(fields_list) - + if 'line_ids' in fields_list and 'line_ids' not in res: # Retrieve moves to pay from the context. @@ -397,7 +397,7 @@ class AccountPaymentRegister(models.TransientModel): raise UserError(_("You can't register payments for journal items being either all inbound, either all outbound.")) res['line_ids'] = [(6, 0, available_lines.ids)] - + return res # ------------------------------------------------------------------------- diff --git a/addons/account_edi/models/account_journal.py b/addons/account_edi/models/account_journal.py index a40a90b27bd..20f03b380ba 100644 --- a/addons/account_edi/models/account_journal.py +++ b/addons/account_edi/models/account_journal.py @@ -37,7 +37,7 @@ class AccountJournal(models.Model): else: return super().write(vals) - @api.depends('type', 'company_id', 'company_id.country_id') + @api.depends('type', 'company_id', 'company_id.account_fiscal_country_id') def _compute_compatible_edi_ids(self): edi_formats = self.env['account.edi.format'].search([]) @@ -45,7 +45,7 @@ class AccountJournal(models.Model): compatible_edis = edi_formats.filtered(lambda e: e._is_compatible_with_journal(journal)) journal.compatible_edi_ids += compatible_edis - @api.depends('type', 'company_id', 'company_id.country_id') + @api.depends('type', 'company_id', 'company_id.account_fiscal_country_id') def _compute_edi_format_ids(self): edi_formats = self.env['account.edi.format'].search([]) diff --git a/addons/l10n_ae/views/report_invoice_templates.xml b/addons/l10n_ae/views/report_invoice_templates.xml index 0018bc69a62..cfa40cca539 100644 --- a/addons/l10n_ae/views/report_invoice_templates.xml +++ b/addons/l10n_ae/views/report_invoice_templates.xml @@ -2,16 +2,16 @@