@ -1,4 +1,5 @@
# Copyright 2017 Grant Thornton Spain - Ismael Calvo <ismael.calvo@es.gt.com>
# Copyright 2017 Grant Thornton Spain - Ismael Calvo <ismael.calvo@es.gt.com>
# Copyright 2020 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import _ , api , fields , models
from odoo import _ , api , fields , models
@ -20,12 +21,19 @@ class ResPartner(models.Model):
not self . env . context . get ( ' test_vat ' ) )
not self . env . context . get ( ' test_vat ' ) )
if test_condition :
if test_condition :
continue
continue
results = self . env [ ' res.partner ' ] . search_count ( [
if self . env [ ' res.partner ' ] . sudo ( ) . with_context (
active_test = False ,
) . search_count ( [
( ' parent_id ' , ' = ' , False ) ,
( ' parent_id ' , ' = ' , False ) ,
( ' vat ' , ' = ' , record . vat ) ,
( ' vat ' , ' = ' , record . vat ) ,
( ' id ' , ' != ' , record . id )
] )
if results :
( ' id ' , ' != ' , record . id ) ,
" | " ,
( " company_id " , " = " , False ) ,
( " company_id " , " = " , record . company_id . id ) ,
] ) :
raise ValidationError ( _ (
raise ValidationError ( _ (
" The VAT %s already exists in another "
" The VAT %s already exists in another "
" partner. " ) % record . vat )
" partner. "
) + " " + _ (
" NOTE: This partner may be archived. "
) % record . vat )