From e723d0908faa19075cf3da95dcb661b15d63364e Mon Sep 17 00:00:00 2001 From: jbw Date: Wed, 16 Sep 2020 15:03:13 +0000 Subject: [PATCH] [IMP] account : defaults belgian company registry to vat number In Belgium, the company registry and the VAT number (no country code) are identic. The company registry field is not mandatory, but is needed to export the belgian Intrastat XML file. Now: - belgian company registry is set by default to vat number. - missing company registry warning message redirects to company settings. closes odoo/odoo#58047 Task: 2335088 Related: odoo/enterprise#15270 Signed-off-by: Laurent Smet --- addons/l10n_be/models/__init__.py | 1 + addons/l10n_be/models/res_company.py | 20 ++++++++++++++++++++ odoo/addons/base/models/res_company.py | 7 ++++++- 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 addons/l10n_be/models/res_company.py diff --git a/addons/l10n_be/models/__init__.py b/addons/l10n_be/models/__init__.py index 6ad2218aca8..ed727aa0a41 100644 --- a/addons/l10n_be/models/__init__.py +++ b/addons/l10n_be/models/__init__.py @@ -4,3 +4,4 @@ from . import account_chart_template from . import account_journal from . import account_move +from . import res_company diff --git a/addons/l10n_be/models/res_company.py b/addons/l10n_be/models/res_company.py new file mode 100644 index 00000000000..a8d7c92c6b7 --- /dev/null +++ b/addons/l10n_be/models/res_company.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +# Copyright (c) 2011 Noviat nv/sa (www.noviat.be). All rights reserved. + +from odoo import api, models + + +class ResCompany(models.Model): + _inherit = 'res.company' + + @api.depends('vat', 'country_id') + def _compute_company_registry(self): + # OVERRIDE + # If a belgian company has a VAT number then it's company registry is it's VAT Number (without country code). + super(ResCompany, self)._compute_company_registry() + for company in self.filtered(lambda comp: comp.country_id.code == 'BE' and comp.vat): + vat_country, vat_number = self.env['res.partner']._split_vat(company.vat) + if vat_country == 'be' and self.env['res.partner'].simple_vat_check(vat_country, vat_number): + company.company_registry = vat_number diff --git a/odoo/addons/base/models/res_company.py b/odoo/addons/base/models/res_company.py index a63458508b8..23c87f7859e 100644 --- a/odoo/addons/base/models/res_company.py +++ b/odoo/addons/base/models/res_company.py @@ -85,7 +85,7 @@ class Company(models.Model): mobile = fields.Char(related='partner_id.mobile', store=True, readonly=False) website = fields.Char(related='partner_id.website', readonly=False) vat = fields.Char(related='partner_id.vat', string="Tax ID", readonly=False) - company_registry = fields.Char() + company_registry = fields.Char(compute='_compute_company_registry', store=True, readonly=False) paperformat_id = fields.Many2one('report.paperformat', 'Paper format', default=lambda self: self.env.ref('base.paperformat_euro', raise_if_not_found=False)) external_report_layout_id = fields.Many2one('ir.ui.view', 'Document Template') base_onboarding_company_state = fields.Selection([ @@ -116,6 +116,11 @@ class Company(models.Model): return dict((fname, partner[fname]) for fname in self._get_company_address_field_names()) + def _compute_company_registry(self): + # exists to allow overrides + for company in self: + company.company_registry = company.company_registry + # TODO @api.depends(): currently now way to formulate the dependency on the # partner's contact address def _compute_address(self):