From 6b396c84e56d635d76a2fa90fe41907d47961fa1 Mon Sep 17 00:00:00 2001 From: "Ricardo Gomes Rodrigues (rigr)" Date: Mon, 5 Dec 2022 11:01:39 +0000 Subject: [PATCH] [IMP] account,l10n_*: clean country-specific fields from views Many country-specific fields were displayed while a company with another country was selected (in case of a multi-company environment). These country-specific fields are now visible only if one of the selected companies with said country is selected. closes odoo/odoo#106221 Related: odoo/enterprise#34226 Signed-off-by: John Laterre (jol) --- addons/account/models/account_payment_term.py | 8 ++++++++ addons/account/models/partner.py | 10 ++++++++++ addons/account/models/product.py | 8 ++++++++ addons/account/models/res_currency.py | 8 +++++++- addons/account/views/account_payment_term_views.xml | 1 + addons/account/views/partner_view.xml | 5 +++++ addons/account/views/product_view.xml | 3 +++ addons/account/views/res_currency.xml | 5 ++++- addons/l10n_ar/views/account_fiscal_position_view.xml | 2 +- addons/l10n_ar/views/res_currency_view.xml | 2 +- addons/l10n_ar/views/res_partner_view.xml | 2 +- addons/l10n_br/views/res_partner_views.xml | 10 +++++----- addons/l10n_ca/views/res_partner_view.xml | 6 +++--- addons/l10n_cl/views/account_tax_view.xml | 8 ++++---- addons/l10n_cl/views/res_partner.xml | 6 +++--- .../l10n_eg_edi_eta/views/product_template_views.xml | 2 +- addons/l10n_fr/views/l10n_fr_view.xml | 4 ++-- addons/l10n_in/views/product_template_view.xml | 4 ++-- addons/l10n_in/views/res_partner_views.xml | 4 ++-- addons/l10n_it_edi/views/l10n_it_view.xml | 8 ++++---- addons/l10n_ph/views/account_tax_views.xml | 2 +- addons/l10n_ph/views/res_partner_views.xml | 10 +++++----- addons/l10n_ro/views/res_partner_view.xml | 2 +- addons/l10n_se/views/partner_view.xml | 2 +- addons/l10n_sg/views/account_invoice_view.xml | 4 ++-- addons/l10n_sg/views/res_partner_view.xml | 4 ++-- 26 files changed, 87 insertions(+), 43 deletions(-) diff --git a/addons/account/models/account_payment_term.py b/addons/account/models/account_payment_term.py index 98fb551eeb1..204cb55e195 100644 --- a/addons/account/models/account_payment_term.py +++ b/addons/account/models/account_payment_term.py @@ -26,6 +26,7 @@ class AccountPaymentTerm(models.Model): note = fields.Html(string='Description on the Invoice', translate=True) line_ids = fields.One2many('account.payment.term.line', 'payment_id', string='Terms', copy=True, default=_default_line_ids) company_id = fields.Many2one('res.company', string='Company') + fiscal_country_codes = fields.Char(compute='_compute_fiscal_country_codes') sequence = fields.Integer(required=True, default=10) display_on_invoice = fields.Boolean(string='Display terms on invoice', help="If set, the payment deadlines and respective due amounts will be detailed on invoices.") example_amount = fields.Float(default=_default_example_amount, store=False) @@ -33,6 +34,13 @@ class AccountPaymentTerm(models.Model): example_invalid = fields.Boolean(compute='_compute_example_invalid') example_preview = fields.Html(compute='_compute_example_preview') + @api.depends('company_id') + @api.depends_context('allowed_company_ids') + def _compute_fiscal_country_codes(self): + for record in self: + allowed_companies = record.company_id or self.env.companies + record.fiscal_country_codes = ",".join(allowed_companies.mapped('account_fiscal_country_id.code')) + @api.depends('line_ids') def _compute_example_invalid(self): for payment_term in self: diff --git a/addons/account/models/partner.py b/addons/account/models/partner.py index 97e49094896..1c5d4b2378f 100644 --- a/addons/account/models/partner.py +++ b/addons/account/models/partner.py @@ -33,6 +33,7 @@ class AccountFiscalPosition(models.Model): auto_apply = fields.Boolean(string='Detect Automatically', help="Apply tax & account mappings on invoices automatically if the matching criterias (VAT/Country) are met.") vat_required = fields.Boolean(string='VAT required', help="Apply only if partner has a VAT number.") company_country_id = fields.Many2one(string="Company Country", related='company_id.account_fiscal_country_id') + fiscal_country_codes = fields.Char(string="Company Fiscal Country Code", related='company_country_id.code') country_id = fields.Many2one('res.country', string='Country', help="Apply only if delivery country matches.") country_group_id = fields.Many2one('res.country.group', string='Country Group', @@ -293,6 +294,15 @@ class ResPartner(models.Model): _name = 'res.partner' _inherit = 'res.partner' + fiscal_country_codes = fields.Char(compute='_compute_fiscal_country_codes') + + @api.depends('company_id') + @api.depends_context('allowed_company_ids') + def _compute_fiscal_country_codes(self): + for record in self: + allowed_companies = record.company_id or self.env.companies + record.fiscal_country_codes = ",".join(allowed_companies.mapped('account_fiscal_country_id.code')) + @property def _order(self): res = super()._order diff --git a/addons/account/models/product.py b/addons/account/models/product.py index a898d7478b3..a1ddeea5620 100644 --- a/addons/account/models/product.py +++ b/addons/account/models/product.py @@ -41,6 +41,7 @@ class ProductTemplate(models.Model): comodel_name='account.account.tag', domain="[('applicability', '=', 'products')]", help="Tags to be set on the base and tax journal items created for this product.") + fiscal_country_codes = fields.Char(compute='_compute_fiscal_country_codes') def _get_product_accounts(self): return { @@ -60,6 +61,13 @@ class ProductTemplate(models.Model): fiscal_pos = self.env['account.fiscal.position'] return fiscal_pos.map_accounts(accounts) + @api.depends('company_id') + @api.depends_context('allowed_company_ids') + def _compute_fiscal_country_codes(self): + for record in self: + allowed_companies = record.company_id or self.env.companies + record.fiscal_country_codes = ",".join(allowed_companies.mapped('account_fiscal_country_id.code')) + @api.depends('taxes_id', 'list_price') def _compute_tax_string(self): for record in self: diff --git a/addons/account/models/res_currency.py b/addons/account/models/res_currency.py index 2cfad4fd2b3..e1de9912d54 100644 --- a/addons/account/models/res_currency.py +++ b/addons/account/models/res_currency.py @@ -10,7 +10,7 @@ class ResCurrency(models.Model): display_rounding_warning = fields.Boolean(string="Display Rounding Warning", compute='_compute_display_rounding_warning', help="The warning informs a rounding factor change might be dangerous on res.currency's form view.") - + fiscal_country_codes = fields.Char(compute='_compute_fiscal_country_codes') @api.depends('rounding') def _compute_display_rounding_warning(self): @@ -19,6 +19,12 @@ class ResCurrency(models.Model): and record._origin.rounding != record.rounding \ and record._origin._has_accounting_entries() + @api.depends_context('allowed_company_ids') + def _compute_fiscal_country_codes(self): + for record in self: + companies = self.env['res.company'].search([('id', 'in', self.env.context.get('allowed_company_ids', []))]) + record.fiscal_country_codes = ",".join(companies.mapped('account_fiscal_country_id.code')) + def write(self, vals): if 'rounding' in vals: rounding_val = vals['rounding'] diff --git a/addons/account/views/account_payment_term_views.xml b/addons/account/views/account_payment_term_views.xml index ac317cbd4b4..f704d0bcf1c 100644 --- a/addons/account/views/account_payment_term_views.xml +++ b/addons/account/views/account_payment_term_views.xml @@ -34,6 +34,7 @@
+