Browse Source

[IMP] partner_vat_unique: black, isort

14.0
Manuel Calero 4 years ago
committed by newtratip
parent
commit
0b8f3fd804
  1. 3
      partner_vat_unique/__manifest__.py
  2. 27
      partner_vat_unique/models/res_partner.py
  3. 18
      partner_vat_unique/tests/test_vat_unique.py

3
partner_vat_unique/__manifest__.py

@ -2,8 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Partner VAT Unique",
"summary":
"Module to make the VAT number unique for customers and suppliers.",
"summary": "Module to make the VAT number unique for customers and suppliers.",
"version": "12.0.1.0.1",
"category": "Customer Relationship Management",
"website": "https://github.com/OCA/partner-contact",

27
partner_vat_unique/models/res_partner.py

@ -7,25 +7,28 @@ from odoo.tools import config
class ResPartner(models.Model):
_inherit = 'res.partner'
_inherit = "res.partner"
vat = fields.Char(copy=False)
@api.constrains('vat')
@api.constrains("vat")
def _check_vat_unique(self):
for record in self:
if record.parent_id or not record.vat:
continue
test_condition = (config['test_enable'] and
not self.env.context.get('test_vat'))
test_condition = config["test_enable"] and not self.env.context.get(
"test_vat"
)
if test_condition:
continue
results = self.env['res.partner'].search_count([
('parent_id', '=', False),
('vat', '=', record.vat),
('id', '!=', record.id)
])
results = self.env["res.partner"].search_count(
[
("parent_id", "=", False),
("vat", "=", record.vat),
("id", "!=", record.id),
]
)
if results:
raise ValidationError(_(
"The VAT %s already exists in another "
"partner.") % record.vat)
raise ValidationError(
_("The VAT %s already exists in another " "partner.") % record.vat
)

18
partner_vat_unique/tests/test_vat_unique.py

@ -1,26 +1,24 @@
# Copyright 2017 Grant Thornton Spain - Ismael Calvo <ismael.calvo@es.gt.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.tests.common import SavepointCase
from odoo.exceptions import ValidationError
from odoo.tests.common import SavepointCase
class TestVatUnique(SavepointCase):
@classmethod
def setUpClass(cls):
super(TestVatUnique, cls).setUpClass()
cls.partner_model = cls.env['res.partner']
cls.partner = cls.partner_model.create({
'name': 'Test partner',
'vat': 'ESA12345674'
})
cls.partner_model = cls.env["res.partner"]
cls.partner = cls.partner_model.create(
{"name": "Test partner", "vat": "ESA12345674"}
)
def test_duplicated_vat_creation(self):
with self.assertRaises(ValidationError):
self.partner_model.with_context(test_vat=True).create({
'name': 'Second partner',
'vat': 'ESA12345674'
})
self.partner_model.with_context(test_vat=True).create(
{"name": "Second partner", "vat": "ESA12345674"}
)
def test_duplicate_partner(self):
partner_copied = self.partner.copy()

Loading…
Cancel
Save