Browse Source

[MIG] partner_vat_unique: Migration to 10.0

pull/663/head
cubells 7 years ago
committed by Koen Loodts
parent
commit
71687a05fe
  1. 20
      partner_vat_unique/README.rst
  2. 9
      partner_vat_unique/models/res_partner.py
  3. 2
      partner_vat_unique/tests/test_vat_unique.py

20
partner_vat_unique/README.rst

@ -1,5 +1,5 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: https://www.gnu.org/licenses/agpl
:alt: License: AGPL-3 :alt: License: AGPL-3
@ -27,6 +27,22 @@ check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback. help us smash it by providing detailed and welcomed feedback.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://odoo-community.org/logo.png>`_.
Contributors
------------
* Ismael Calvo <ismael.calvo@es.gt.com>
* Vicent Cubells <vicent.cubells@tecnativa.com>
Do not contact contributors directly about support or help with technical issues.
Maintainer Maintainer
---------- ----------

9
partner_vat_unique/models/res_partner.py

@ -4,6 +4,7 @@
from odoo import api, models, _ from odoo import api, models, _
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError
from odoo.tools import config
class ResPartner(models.Model): class ResPartner(models.Model):
@ -12,9 +13,13 @@ class ResPartner(models.Model):
@api.constrains('vat') @api.constrains('vat')
def _check_vat_unique(self): def _check_vat_unique(self):
for record in self: for record in self:
if record.parent_id:
if record.parent_id or not record.vat:
continue continue
results = self.env['res.partner'].search([
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), ('parent_id', '=', False),
('vat', '=', record.vat), ('vat', '=', record.vat),
('id', '!=', record.id) ('id', '!=', record.id)

2
partner_vat_unique/tests/test_vat_unique.py

@ -17,7 +17,7 @@ class TestVatUnique(SavepointCase):
def test_duplicated_vat_creation(self): def test_duplicated_vat_creation(self):
with self.assertRaises(ValidationError): with self.assertRaises(ValidationError):
self.env['res.partner'].create({
self.env['res.partner'].with_context(test_vat=True).create({
'name': 'Second partner', 'name': 'Second partner',
'vat': 'ESA12345674' 'vat': 'ESA12345674'
}) })
Loading…
Cancel
Save