[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) <jol@odoo.com>
This commit is contained in:
Ricardo Gomes Rodrigues (rigr)
2022-12-09 11:48:42 +01:00
parent 5376b60af0
commit 6b396c84e5
26 changed files with 87 additions and 43 deletions
@@ -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:
+10
View File
@@ -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
+8
View File
@@ -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:
+7 -1
View File
@@ -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']
@@ -34,6 +34,7 @@
<form string="Payment Terms">
<sheet>
<field name="active" invisible="1"/>
<field name="fiscal_country_codes" invisible="1"/>
<widget name="web_ribbon" title="Archived" bg_color="bg-danger" attrs="{'invisible': [('active', '=', True)]}"/>
<div class="oe_title">
<label for="name" string="Payment Terms Name"/>
+5
View File
@@ -43,6 +43,7 @@
<field name="company_id" invisible="1"/>
<field name="states_count" invisible="1"/>
<field name="company_country_id" invisible="1"/>
<field name="fiscal_country_codes" invisible="1"/>
<field name="foreign_vat_header_mode" invisible="1"/>
<field name="name"/>
<field name="company_id" options="{'no_create': True}" groups="base.group_multi_company"/>
@@ -192,6 +193,9 @@
<field name="priority">2</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='company_id']" position="after">
<field name="fiscal_country_codes" invisible="1"/>
</xpath>
<xpath expr="//sheet" position="before">
<div groups="account.group_account_invoice,account.group_account_readonly" class="alert alert-warning" role="alert" style="margin-bottom:0px;"
attrs="{'invisible': [('duplicated_bank_account_partners_count', '=', 0)]}">
@@ -264,6 +268,7 @@
<field name="inherit_id" ref="base.view_res_partner_filter"/>
<field name="arch" type="xml">
<xpath expr="//filter[@name='inactive']" position="before">
<field name="fiscal_country_codes" invisible="1"/>
<filter string="Customer Invoices" name="customer" domain="[('customer_rank','>', 0)]"/>
<filter string="Vendor Bills" name="supplier" domain="[('supplier_rank','>', 0)]"/>
<separator/>
+3
View File
@@ -54,6 +54,9 @@
<xpath expr="//page[@name='purchase']" position="attributes">
<attribute name="invisible">0</attribute>
</xpath>
<xpath expr="//field[@name='company_id']" position="after">
<field name="fiscal_country_codes" invisible="1"/>
</xpath>
<page name="inventory" position="after">
<page string="Accounting" name="invoicing" groups="account.group_account_readonly,account.group_account_invoice">
<group name="properties" groups="account.group_account_readonly">
+4 -1
View File
@@ -7,6 +7,9 @@
<field name="model">res.currency</field>
<field name="inherit_id" ref="base.view_currency_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='is_current_company_currency']" position="after">
<field name="fiscal_country_codes" invisible="1"/>
</xpath>
<xpath expr="//sheet" position="before">
<field name="display_rounding_warning" invisible="1"/>
<div class="alert alert-warning" role="alert" attrs="{'invisible': [('display_rounding_warning', '=', False)]}">
@@ -18,4 +21,4 @@
</record>
</data>
</odoo>
</odoo>
@@ -7,7 +7,7 @@
<field name="inherit_id" ref="account.view_account_position_form"/>
<field name="arch" type="xml">
<field name="auto_apply" position="after">
<field name="l10n_ar_afip_responsibility_type_ids" options="{'no_open': True, 'no_create': True}" attrs="{'invisible': [('auto_apply', '!=', True)]}" groups="base.group_no_one" widget="many2many_tags"/>
<field name="l10n_ar_afip_responsibility_type_ids" options="{'no_open': True, 'no_create': True}" attrs="{'invisible': ['|', ('fiscal_country_codes', 'not ilike', 'AR'), ('auto_apply', '!=', True)]}" groups="base.group_no_one" widget="many2many_tags"/>
</field>
</field>
</record>
+1 -1
View File
@@ -7,7 +7,7 @@
<field name="model">res.currency</field>
<field name="arch" type="xml">
<field name="name" position="after">
<field name="l10n_ar_afip_code"/>
<field name="l10n_ar_afip_code" attrs="{'invisible': [('fiscal_country_codes', 'not ilike', 'AR')]}"/>
</field>
</field>
</record>
+1 -1
View File
@@ -19,7 +19,7 @@
<field name="arch" type="xml">
<xpath expr="//page[@name='accounting']/group" position="inside">
<group string="Accounting Documents" name="accounting_documents">
<group string="Accounting Documents" name="accounting_documents" attrs="{'invisible': [('fiscal_country_codes', 'not ilike', 'AR')]}">
<field name="l10n_ar_special_purchase_document_type_ids" widget="many2many_tags"/>
</group>
</xpath>
+5 -5
View File
@@ -4,13 +4,13 @@
<record id="br_partner_tax_fields_form" model="ir.ui.view">
<field name="name">res.partner.form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="inherit_id" ref="account.view_partner_property_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='vat']" position="after">
<field name="l10n_br_cpf_code" attrs="{'invisible': [('country_id', '!=', %(base.br)d)]}"/>
<field name="l10n_br_ie_code" attrs="{'invisible': [('country_id', '!=', %(base.br)d)]}"/>
<field name="l10n_br_im_code" attrs="{'invisible': [('country_id', '!=', %(base.br)d)]}"/>
<field name="l10n_br_isuf_code" attrs="{'invisible': [('country_id', '!=', %(base.br)d)]}"/>
<field name="l10n_br_cpf_code" attrs="{'invisible': [('fiscal_country_codes', 'not ilike', 'BR')]}"/>
<field name="l10n_br_ie_code" attrs="{'invisible': [('fiscal_country_codes', 'not ilike', 'BR')]}"/>
<field name="l10n_br_im_code" attrs="{'invisible': [('fiscal_country_codes', 'not ilike', 'BR')]}"/>
<field name="l10n_br_isuf_code" attrs="{'invisible': [('fiscal_country_codes', 'not ilike', 'BR')]}"/>
</xpath>
</field>
</record>
+3 -3
View File
@@ -4,12 +4,12 @@
<record id="res_partner_form_inherit_ca" model="ir.ui.view">
<field name="name">res.partner.form.inherit.l10n.ca</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="inherit_id" ref="account.view_partner_property_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='vat']" position="after">
<field name="l10n_ca_pst"/>
<field name="l10n_ca_pst" attrs="{'invisible': [('fiscal_country_codes', 'not ilike', 'CA')]}"/>
</xpath>
</field>
</record>
</data>
</odoo>
</odoo>
+4 -4
View File
@@ -18,7 +18,7 @@
<field name="inherit_id" ref="account.view_tax_tree" />
<field name="arch" type="xml">
<field name="name" position="before">
<field name="l10n_cl_sii_code" options="{'format': false}"/>
<field name="l10n_cl_sii_code" options="{'format': false}" optional="hide"/>
</field>
</field>
</record>
@@ -29,7 +29,7 @@
<field name="inherit_id" ref="account.view_account_tax_template_form"/>
<field name="arch" type="xml">
<field name="name" position="after">
<field name="l10n_cl_sii_code" options="{'format': false}"/>
<field name="l10n_cl_sii_code" options="{'format': false}" optional="hide"/>
</field>
</field>
</record>
@@ -40,9 +40,9 @@
<field name="inherit_id" ref="account.view_account_tax_template_tree" />
<field name="arch" type="xml">
<field name="name" position="before">
<field name="l10n_cl_sii_code" options="{'format': false}"/>
<field name="l10n_cl_sii_code" options="{'format': false}" optional="hide"/>
</field>
</field>
</record>
</data>
</odoo>
</odoo>
+3 -3
View File
@@ -3,7 +3,7 @@
<record id="view_move_form" model="ir.ui.view">
<field name="name">res.partner.placeholders.l10n_cl.form</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="inherit_id" ref="account.view_partner_property_form"/>
<field name="model">res.partner</field>
<field name="arch" type="xml">
<field name="street2" position="attributes">
@@ -16,8 +16,8 @@
<attribute name="placeholder">Región</attribute>
</field>
<field name="vat" position="after">
<field name="l10n_cl_sii_taxpayer_type" attrs="{'readonly': [('parent_id', '!=', False)]}"/>
<field name="l10n_cl_activity_description" placeholder="Activity Description"/>
<field name="l10n_cl_sii_taxpayer_type" attrs="{'readonly': [('parent_id', '!=', False)], 'invisible': [('fiscal_country_codes', 'not ilike', 'CL')]}"/>
<field name="l10n_cl_activity_description" placeholder="Activity Description" attrs="{'invisible': [('fiscal_country_codes', 'not ilike', 'CL')]}"/>
</field>
</field>
</record>
@@ -8,7 +8,7 @@
<field name="inherit_id" ref="product.product_template_only_form_view"/>
<field name="arch" type="xml">
<page name="invoicing" position="inside">
<group name="l10n_eg_eta_edi" string="Egyptian Electronic Invoicing" attrs="{'invisible': [('product_variant_count', '>', 1)]}">
<group name="l10n_eg_eta_edi" string="Egyptian Electronic Invoicing" attrs="{'invisible': ['|', ('fiscal_country_codes', 'not ilike', 'EG'), ('product_variant_count', '>', 1)]}">
<field name="l10n_eg_eta_code" help="ETA Field for GS1/EGS product codes. Please use the barcode field to store GS1/EGS ETA code if possible"/>
</group>
</page>
+2 -2
View File
@@ -19,11 +19,11 @@
<field name="name">res.partner.form.l10n.fr</field>
<field name="model">res.partner</field>
<field name="priority">20</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="inherit_id" ref="account.view_partner_property_form"/>
<field name="arch" type="xml">
<data>
<xpath expr="//field[@name='ref']" position="after">
<field name="siret" attrs="{'invisible': [('is_company', '=', False)]}"/>
<field name="siret" attrs="{'invisible': ['|', ('fiscal_country_codes', 'not ilike', 'FR'), ('is_company', '=', False)]}"/>
</xpath>
</data>
</field>
@@ -7,8 +7,8 @@
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<field name="categ_id" position="after">
<field name="l10n_in_hsn_code"/>
<field name="l10n_in_hsn_description"/>
<field name="l10n_in_hsn_code" attrs="{'invisible': [('fiscal_country_codes', 'not ilike', 'IN')]}"/>
<field name="l10n_in_hsn_description" attrs="{'invisible': [('fiscal_country_codes', 'not ilike', 'IN')]}"/>
</field>
</field>
</record>
+2 -2
View File
@@ -4,13 +4,13 @@
<field name="name">l10n.in.res.partner.vat.inherit</field>
<field name="model">res.partner</field>
<field name="priority" eval="90"/>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="inherit_id" ref="account.view_partner_property_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='vat']" position="attributes">
<attribute name="attrs">{'required':[('l10n_in_gst_treatment', 'in', ['regular', 'composition', 'special_economic_zone', 'deemed_export'])], 'readonly': [('parent_id', '!=', False)]}</attribute>
</xpath>
<xpath expr="//field[@name='vat']" position="before">
<field name="l10n_in_gst_treatment" attrs="{'readonly': [('parent_id', '!=', False)]}"/>
<field name="l10n_in_gst_treatment" attrs="{'readonly': [('parent_id', '!=', False)], 'invisible': [('fiscal_country_codes', 'not ilike', 'IN')]}"/>
</xpath>
</field>
</record>
+4 -4
View File
@@ -25,13 +25,13 @@
<field name="name">res.partner.form.l10n.it</field>
<field name="model">res.partner</field>
<field name="priority">20</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="inherit_id" ref="account.view_partner_property_form"/>
<field name="arch" type="xml">
<data>
<xpath expr="//field[@name='category_id']" position="after">
<field name="l10n_it_pec_email" attrs="{'invisible': [('parent_id', '!=', False)]}"/>
<field name="l10n_it_codice_fiscale" attrs="{'invisible': [('parent_id', '!=', False)]}"/>
<field name="l10n_it_pa_index" attrs="{'invisible': [('parent_id', '!=', False)]}"/>
<field name="l10n_it_pec_email" attrs="{'invisible': ['|', ('fiscal_country_codes', 'not ilike', 'IT'), ('parent_id', '!=', False)]}"/>
<field name="l10n_it_codice_fiscale" attrs="{'invisible': ['|', ('fiscal_country_codes', 'not ilike', 'IT'), ('parent_id', '!=', False)]}"/>
<field name="l10n_it_pa_index" attrs="{'invisible': ['|', ('fiscal_country_codes', 'not ilike', 'IT'), ('parent_id', '!=', False)]}"/>
</xpath>
</data>
</field>
+1 -1
View File
@@ -6,7 +6,7 @@
<field name="inherit_id" ref="account.view_tax_form" />
<field name="arch" type="xml">
<notebook position="inside">
<page name="l10n_ph" string="Philippines">
<page name="l10n_ph" string="Philippines" attrs="{'invisible': [('country_code', '!=', 'PH')]}">
<group>
<group>
<field name="l10n_ph_atc" />
+5 -5
View File
@@ -3,13 +3,13 @@
<record id="view_partner_form" model="ir.ui.view">
<field name="name">res.partner.form.inherit.l10n_ph_bir</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="inherit_id" ref="account.view_partner_property_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='vat']" position="after">
<field name="branch_code"/>
<field name="first_name" attrs="{'invisible': [('is_company','=', True)]}"/>
<field name="middle_name" attrs="{'invisible': [('is_company','=', True)]}"/>
<field name="last_name" attrs="{'invisible': [('is_company','=', True)]}"/>
<field name="branch_code" attrs="{'invisible': [('fiscal_country_codes', 'not ilike', 'PH')]}"/>
<field name="first_name" attrs="{'invisible': ['|', ('fiscal_country_codes', 'not ilike', 'PH'), ('is_company','=', True)]}"/>
<field name="middle_name" attrs="{'invisible': ['|', ('fiscal_country_codes', 'not ilike', 'PH'), ('is_company','=', True)]}"/>
<field name="last_name" attrs="{'invisible': ['|', ('fiscal_country_codes', 'not ilike', 'PH'), ('is_company','=', True)]}"/>
</xpath>
</field>
</record>
+1 -1
View File
@@ -6,7 +6,7 @@
<field name="model">res.partner</field>
<field name="arch" type="xml">
<field name="vat" position="after">
<field name="nrc" placeholder="e.g. J12/1234/2012" class="oe_inline"/>
<field name="nrc" placeholder="e.g. J12/1234/2012" class="oe_inline" attrs="{'invisible': [('fiscal_country_codes', 'not ilike', 'RO')]}"/>
</field>
</field>
</record>
+1 -1
View File
@@ -7,7 +7,7 @@
<field name="inherit_id" ref="account.view_partner_property_form"/>
<field name="arch" type="xml">
<group name="accounting_entries" position="after">
<group string="Payment Options Sweden" name="payment_options">
<group string="Payment Options Sweden" name="payment_options" attrs="{'invisible': [('fiscal_country_codes', 'not ilike', 'SE')]}">
<field name="l10n_se_check_vendor_ocr"/>
<field name="l10n_se_default_vendor_payment_ref"/>
</group>
@@ -7,8 +7,8 @@
<field name="inherit_id" ref="account.view_move_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='fiscal_position_id']" position="after">
<field name="l10n_sg_permit_number"/>
<field name="l10n_sg_permit_number_date"/>
<field name="l10n_sg_permit_number" attrs="{'invisible': [('country_code', '!=', 'SG')]}"/>
<field name="l10n_sg_permit_number_date" attrs="{'invisible': [('country_code', '!=', 'SG')]}"/>
</xpath>
</field>
</record>
+2 -2
View File
@@ -4,10 +4,10 @@
<record id="view_partner_form_l10n_sg" model="ir.ui.view">
<field name="name">l10n_sg.partner.form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="inherit_id" ref="account.view_partner_property_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='vat']" position="before">
<field name="l10n_sg_unique_entity_number"/>
<field name="l10n_sg_unique_entity_number" attrs="{'invisible': [('fiscal_country_codes', 'not ilike', 'SG')]}"/>
</xpath>
</field>
</record>