[IMP] base,l10n_be: move the company_registry from res_company to res_partner
This commit: - moves the "Company Registry Number" from `res_company` to `res_partner` (which might be different from the VAT in some localizations). This must be unique among all partners of the same country. - allows the search of partner by using their "VAT" or their "Company Registry Number" Task-id: 2857253 Community PR: odoo#91938 Enterprise PR: odoo/enterprise#27605 Upgrade PR: odoo/upgrade#3570 closes odoo/odoo#91938 Signed-off-by: Quentin De Paoli <qdp@odoo.com>
This commit is contained in:
committed by
qdp-odoo
parent
17d44d6617
commit
c4bfaf3336
@@ -4,4 +4,4 @@
|
||||
from . import account_chart_template
|
||||
from . import account_journal
|
||||
from . import account_move
|
||||
from . import res_company
|
||||
from . import res_partner
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
# -*- 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
|
||||
@@ -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 ResPartner(models.Model):
|
||||
_inherit = 'res.partner'
|
||||
|
||||
@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()._compute_company_registry()
|
||||
for partner in self.filtered(lambda p: p.country_id.code == 'BE' and p.vat):
|
||||
vat_country, vat_number = self._split_vat(partner.vat)
|
||||
if vat_country == 'be' and self.simple_vat_check(vat_country, vat_number):
|
||||
partner.company_registry = vat_number
|
||||
@@ -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(compute='_compute_company_registry', store=True, readonly=False)
|
||||
company_registry = fields.Char(related='partner_id.company_registry', string="Company ID", 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([
|
||||
@@ -117,11 +117,6 @@ class Company(models.Model):
|
||||
def _get_company_address_update(self, partner):
|
||||
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
|
||||
|
||||
@@ -129,7 +129,7 @@ class Partner(models.Model):
|
||||
_inherit = ['format.address.mixin', 'avatar.mixin']
|
||||
_name = "res.partner"
|
||||
_order = "display_name, id"
|
||||
_rec_names_search = ['display_name', 'email', 'ref', 'vat'] # TODO vat must be sanitized the same way for storing/searching
|
||||
_rec_names_search = ['display_name', 'email', 'ref', 'vat', 'company_registry'] # TODO vat must be sanitized the same way for storing/searching
|
||||
|
||||
def _default_category(self):
|
||||
return self.env['res.partner.category'].browse(self._context.get('category_id'))
|
||||
@@ -172,6 +172,9 @@ class Partner(models.Model):
|
||||
help='The internal user in charge of this contact.')
|
||||
vat = fields.Char(string='Tax ID', index=True, help="The Tax Identification Number. Complete it if the contact is subjected to government taxes. Used in some legal statements.")
|
||||
same_vat_partner_id = fields.Many2one('res.partner', string='Partner with same Tax ID', compute='_compute_same_vat_partner_id', store=False)
|
||||
same_company_registry_partner_id = fields.Many2one('res.partner', string='Partner with same Company Registry', compute='_compute_same_vat_partner_id', store=False)
|
||||
company_registry = fields.Char(string="Company ID", compute='_compute_company_registry', store=True, readonly=False,
|
||||
help="The registry number of the company. Use it if it is different from the Tax ID. It must be unique across all partners of a same country")
|
||||
bank_ids = fields.One2many('res.partner.bank', 'partner_id', string='Banks')
|
||||
website = fields.Char('Website Link')
|
||||
comment = fields.Html(string='Notes')
|
||||
@@ -309,7 +312,7 @@ class Partner(models.Model):
|
||||
for partner in self - super_partner:
|
||||
partner.partner_share = not partner.user_ids or not any(not user.share for user in partner.user_ids)
|
||||
|
||||
@api.depends('vat', 'company_id')
|
||||
@api.depends('vat', 'company_id', 'company_registry')
|
||||
def _compute_same_vat_partner_id(self):
|
||||
for partner in self:
|
||||
# use _origin to deal with onchange()
|
||||
@@ -324,6 +327,14 @@ class Partner(models.Model):
|
||||
if partner_id:
|
||||
domain += [('id', '!=', partner_id), '!', ('id', 'child_of', partner_id)]
|
||||
partner.same_vat_partner_id = bool(partner.vat) and not partner.parent_id and Partner.search(domain, limit=1)
|
||||
# check company_registry
|
||||
domain = [
|
||||
('company_registry', '=', partner.company_registry),
|
||||
('company_id', 'in', [False, partner.company_id.id]),
|
||||
]
|
||||
if partner_id:
|
||||
domain += [('id', '!=', partner_id), '!', ('id', 'child_of', partner_id)]
|
||||
partner.same_company_registry_partner_id = bool(partner.company_registry) and not partner.parent_id and Partner.search(domain, limit=1)
|
||||
|
||||
@api.depends(lambda self: self._display_address_depends())
|
||||
def _compute_contact_address(self):
|
||||
@@ -348,6 +359,11 @@ class Partner(models.Model):
|
||||
p = partner.commercial_partner_id
|
||||
partner.commercial_company_name = p.is_company and p.name or partner.company_name
|
||||
|
||||
def _compute_company_registry(self):
|
||||
# exists to allow overrides
|
||||
for company in self:
|
||||
company.company_registry = company.company_registry
|
||||
|
||||
@api.model
|
||||
def _get_view(self, view_id=None, view_type='form', **options):
|
||||
if (not view_id) and (view_type == 'form') and self._context.get('force_email'):
|
||||
@@ -484,7 +500,7 @@ class Partner(models.Model):
|
||||
partners that aren't `commercial entities` themselves, and will be
|
||||
delegated to the parent `commercial entity`. The list is meant to be
|
||||
extended by inheriting classes. """
|
||||
return ['vat']
|
||||
return ['vat', 'company_registry']
|
||||
|
||||
def _commercial_sync_from_company(self):
|
||||
""" Handle sync of commercial fields when a new parent commercial entity is set,
|
||||
|
||||
@@ -156,6 +156,9 @@
|
||||
<div class="alert alert-warning oe_edit_only" role="alert" attrs="{'invisible': [('same_vat_partner_id', '=', False)]}">
|
||||
A partner with the same <span><span class="o_vat_label">Tax ID</span></span> already exists (<field name="same_vat_partner_id"/>), are you sure to create a new one?
|
||||
</div>
|
||||
<div class="alert alert-warning oe_edit_only" role="alert" attrs="{'invisible': [('same_company_registry_partner_id', '=', False)]}">
|
||||
A partner with the same <span><span class="o_vat_label">Company Registry</span></span> already exists (<field name="same_company_registry_partner_id"/>), are you sure to create a new one?
|
||||
</div>
|
||||
<sheet>
|
||||
<div class="oe_button_box" name="button_box"/>
|
||||
<widget name="web_ribbon" title="Archived" bg_color="bg-danger" attrs="{'invisible': [('active', '=', True)]}"/>
|
||||
@@ -341,6 +344,7 @@
|
||||
<group string="Purchase" name="purchase" priority="2">
|
||||
</group>
|
||||
<group name="misc" string="Misc">
|
||||
<field name="company_registry" attrs="{'invisible': [('parent_id','!=',False)]}"/>
|
||||
<field name="ref" string="Reference"/>
|
||||
<field name="company_id" groups="base.group_multi_company" options="{'no_create': True}" attrs="{'readonly': [('parent_id', '!=', False)]}" force_save="1"/>
|
||||
<field name="industry_id" attrs="{'invisible': [('is_company', '=', False)]}" options="{'no_create': True}"/>
|
||||
@@ -409,7 +413,7 @@
|
||||
<field name="arch" type="xml">
|
||||
<search string="Search Partner">
|
||||
<field name="name"
|
||||
filter_domain="['|', '|', ('display_name', 'ilike', self), ('ref', '=', self), ('email', 'ilike', self)]"/>
|
||||
filter_domain="['|', '|', '|', '|', ('display_name', 'ilike', self), ('ref', '=', self), ('email', 'ilike', self), ('vat', 'ilike', self), ('company_registry', 'ilike', self)]"/>
|
||||
<field name="parent_id" domain="[('is_company', '=', True)]" operator="child_of"/>
|
||||
<field name="email" filter_domain="[('email', 'ilike', self)]"/>
|
||||
<field name="phone" filter_domain="['|', ('phone', 'ilike', self), ('mobile', 'ilike', self)]"/>
|
||||
|
||||
Reference in New Issue
Block a user