[FIX] base: More rigorous duplicated VAT check in contacts
Three cases were not covered: - If the partner with duplicated VAT is inactive (false negative). - If there are specific contact record rules that hides some of the results for that user (false negative). - If the user have several companies viewed at the same time, but the contacts don't overlap the company scope (false positive). We cover all of them with this modification. Was PR #53701 closes odoo/odoo#57859 X-original-commit: 35cd931735e2092e08b2cf59434fb3bd579b12ea Signed-off-by: Quentin De Paoli (qdp) <qdp@openerp.com>
This commit is contained in:
@@ -268,15 +268,21 @@ 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')
|
||||
@api.depends('vat', 'company_id')
|
||||
def _compute_same_vat_partner_id(self):
|
||||
for partner in self:
|
||||
# use _origin to deal with onchange()
|
||||
partner_id = partner._origin.id
|
||||
domain = [('vat', '=', partner.vat)]
|
||||
#active_test = False because if a partner has been deactivated you still want to raise the error,
|
||||
#so that you can reactivate it instead of creating a new one, which would loose its history.
|
||||
Partner = self.with_context(active_test=False).sudo()
|
||||
domain = [
|
||||
('vat', '=', partner.vat),
|
||||
('company_id', 'in', [False, partner.company_id.id]),
|
||||
]
|
||||
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 self.env['res.partner'].search(domain, limit=1)
|
||||
partner.same_vat_partner_id = bool(partner.vat) and not partner.parent_id and Partner.search(domain, limit=1)
|
||||
|
||||
@api.depends(lambda self: self._display_address_depends())
|
||||
def _compute_contact_address(self):
|
||||
|
||||
Reference in New Issue
Block a user