Browse Source

[MIG] partner_vat_unique: Migration to 10.0

pull/663/head
cubells 6 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
@ -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.
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
----------

9
partner_vat_unique/models/res_partner.py

@ -4,6 +4,7 @@
from odoo import api, models, _
from odoo.exceptions import ValidationError
from odoo.tools import config
class ResPartner(models.Model):
@ -12,9 +13,13 @@ class ResPartner(models.Model):
@api.constrains('vat')
def _check_vat_unique(self):
for record in self:
if record.parent_id:
if record.parent_id or not record.vat:
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),
('vat', '=', record.vat),
('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):
with self.assertRaises(ValidationError):
self.env['res.partner'].create({
self.env['res.partner'].with_context(test_vat=True).create({
'name': 'Second partner',
'vat': 'ESA12345674'
})
Loading…
Cancel
Save