From 71687a05fecff1f080646c99cb98282848e9178b Mon Sep 17 00:00:00 2001 From: cubells Date: Tue, 17 Apr 2018 16:07:12 +0200 Subject: [PATCH] [MIG] partner_vat_unique: Migration to 10.0 --- partner_vat_unique/README.rst | 20 ++++++++++++++++++-- partner_vat_unique/models/res_partner.py | 9 +++++++-- partner_vat_unique/tests/test_vat_unique.py | 2 +- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/partner_vat_unique/README.rst b/partner_vat_unique/README.rst index f8d701e03..7dded1583 100644 --- a/partner_vat_unique/README.rst +++ b/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 `_. + +Contributors +------------ + +* Ismael Calvo +* Vicent Cubells + +Do not contact contributors directly about support or help with technical issues. + Maintainer ---------- diff --git a/partner_vat_unique/models/res_partner.py b/partner_vat_unique/models/res_partner.py index c70b1a3d9..bfe4be9f2 100644 --- a/partner_vat_unique/models/res_partner.py +++ b/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) diff --git a/partner_vat_unique/tests/test_vat_unique.py b/partner_vat_unique/tests/test_vat_unique.py index 7d1cf1d96..cbf82242b 100644 --- a/partner_vat_unique/tests/test_vat_unique.py +++ b/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' })