From 2091ed0fa8bcbf134f0052113efd51408b5b7ca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Marques?= Date: Mon, 7 Sep 2020 09:10:32 +0100 Subject: [PATCH] [IMP] partner_ref_unique: black, isort, prettier --- partner_ref_unique/__manifest__.py | 11 +--- partner_ref_unique/hooks.py | 7 +- partner_ref_unique/models/res_company.py | 11 ++-- partner_ref_unique/models/res_partner.py | 23 +++---- .../tests/test_res_partner_ref.py | 64 ++++++++----------- partner_ref_unique/views/res_company_view.xml | 26 ++++---- 6 files changed, 63 insertions(+), 79 deletions(-) diff --git a/partner_ref_unique/__manifest__.py b/partner_ref_unique/__manifest__.py index b9b7016ee..3e1efab1b 100644 --- a/partner_ref_unique/__manifest__.py +++ b/partner_ref_unique/__manifest__.py @@ -8,16 +8,11 @@ "version": "12.0.1.0.2", "category": "Customer Relationship Management", "website": "https://github.com/OCA/partner-contact/", - "author": "Tecnativa, " - "Odoo Community Association (OCA)", + "author": "Tecnativa, " "Odoo Community Association (OCA)", "license": "AGPL-3", "application": False, "installable": True, "pre_init_hook": "pre_init_hook", - "depends": [ - "base", - ], - "data": [ - "views/res_company_view.xml", - ], + "depends": ["base",], + "data": ["views/res_company_view.xml",], } diff --git a/partner_ref_unique/hooks.py b/partner_ref_unique/hooks.py index 2a51c94f5..d5512fa57 100644 --- a/partner_ref_unique/hooks.py +++ b/partner_ref_unique/hooks.py @@ -16,12 +16,9 @@ def pre_init_hook(cr): "COMMENT ON COLUMN public.res_company.partner_ref_unique " "IS 'Unique partner reference for';" ) - cr.execute( - "UPDATE res_company SET partner_ref_unique = 'none';" - ) + cr.execute("UPDATE res_company SET partner_ref_unique = 'none';") _logger.info( - "Creating res.partner.partner_ref_unique column with value from " - "res.company" + "Creating res.partner.partner_ref_unique column with value from " "res.company" ) cr.execute("ALTER TABLE res_partner ADD partner_ref_unique varchar NULL;") cr.execute( diff --git a/partner_ref_unique/models/res_company.py b/partner_ref_unique/models/res_company.py index 4537424d1..6992d3dc7 100644 --- a/partner_ref_unique/models/res_company.py +++ b/partner_ref_unique/models/res_company.py @@ -9,7 +9,10 @@ class ResCompany(models.Model): partner_ref_unique = fields.Selection( selection=[ - ('none', 'None'), - ('companies', 'Only companies'), - ('all', 'All partners'), - ], string="Unique partner reference for", default="none") + ("none", "None"), + ("companies", "Only companies"), + ("all", "All partners"), + ], + string="Unique partner reference for", + default="none", + ) diff --git a/partner_ref_unique/models/res_partner.py b/partner_ref_unique/models/res_partner.py index c248c4196..915b7baa3 100644 --- a/partner_ref_unique/models/res_partner.py +++ b/partner_ref_unique/models/res_partner.py @@ -11,28 +11,29 @@ class ResPartner(models.Model): # This related is needed in order to trigger the check when changing the # value on res.company partner_ref_unique = fields.Selection( - related='company_id.partner_ref_unique', store=True, + related="company_id.partner_ref_unique", store=True, ) @api.multi - @api.constrains('ref', 'is_company', 'company_id', 'partner_ref_unique') + @api.constrains("ref", "is_company", "company_id", "partner_ref_unique") def _check_ref(self): for partner in self: mode = partner.partner_ref_unique - if (partner.ref and ( - mode == 'all' or - (mode == 'companies' and partner.is_company))): + if partner.ref and ( + mode == "all" or (mode == "companies" and partner.is_company) + ): domain = [ - ('id', '!=', partner.id), - ('ref', '=', partner.ref), + ("id", "!=", partner.id), + ("ref", "=", partner.ref), ] - if mode == 'companies': - domain.append(('is_company', '=', True)) + if mode == "companies": + domain.append(("is_company", "=", True)) other = self.search(domain) # active_test is False when called from # base.partner.merge.automatic.wizard if other and self.env.context.get("active_test", True): raise ValidationError( - _("This reference is equal to partner '%s'") % - other[0].display_name) + _("This reference is equal to partner '%s'") + % other[0].display_name + ) diff --git a/partner_ref_unique/tests/test_res_partner_ref.py b/partner_ref_unique/tests/test_res_partner_ref.py index 39509fa42..3dac1bd5a 100644 --- a/partner_ref_unique/tests/test_res_partner_ref.py +++ b/partner_ref_unique/tests/test_res_partner_ref.py @@ -1,67 +1,57 @@ # Copyright 2017 Tecnativa - Vicent Cubells # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo.tests import common from odoo.exceptions import ValidationError +from odoo.tests import common class TestResPartnerRefUnique(common.SavepointCase): @classmethod def setUpClass(cls): super(TestResPartnerRefUnique, cls).setUpClass() - cls.company = cls.env.ref('base.main_company') - cls.partner_obj = cls.env['res.partner'] - cls.partner1 = cls.partner_obj.create({ - 'name': 'Partner1', - }) - cls.partner2 = cls.partner_obj.create({ - 'name': 'Partner2', - }) + cls.company = cls.env.ref("base.main_company") + cls.partner_obj = cls.env["res.partner"] + cls.partner1 = cls.partner_obj.create({"name": "Partner1",}) + cls.partner2 = cls.partner_obj.create({"name": "Partner2",}) def test_check_ref_company(self): # Test can create/modify partners with same ref - self.company.partner_ref_unique = 'none' - self.partner1.ref = 'same_ref' - self.partner2.ref = 'same_ref' + self.company.partner_ref_unique = "none" + self.partner1.ref = "same_ref" + self.partner2.ref = "same_ref" self.assertEqual(self.partner1.ref, self.partner2.ref) # Here there shouldn't be any problem - self.partner_obj.create({ - 'name': 'other', - 'ref': 'same_ref', - }) + self.partner_obj.create( + {"name": "other", "ref": "same_ref",} + ) self.partner2.ref = False with self.assertRaises(ValidationError): - self.company.partner_ref_unique = 'all' + self.company.partner_ref_unique = "all" def test_check_ref(self): - self.partner1.ref = 'same_ref' + self.partner1.ref = "same_ref" # Test can't create/modify partner with same ref - self.company.partner_ref_unique = 'all' + self.company.partner_ref_unique = "all" with self.assertRaises(ValidationError): - self.partner2.ref = 'same_ref' + self.partner2.ref = "same_ref" with self.assertRaises(ValidationError): - self.partner_obj.create({ - 'name': 'other', - 'ref': 'same_ref', - }) + self.partner_obj.create( + {"name": "other", "ref": "same_ref",} + ) # Test can't create/modify companies with same ref - self.company.partner_ref_unique = 'companies' - self.partner2.ref = 'same_ref' + self.company.partner_ref_unique = "companies" + self.partner2.ref = "same_ref" self.assertEqual(self.partner1.ref, self.partner2.ref) self.partner2.ref = False self.partner1.is_company = True self.partner2.is_company = True with self.assertRaises(ValidationError): - self.partner2.ref = 'same_ref' + self.partner2.ref = "same_ref" with self.assertRaises(ValidationError): - self.partner_obj.create({ - 'is_company': True, - 'name': 'other', - 'ref': 'same_ref', - }) + self.partner_obj.create( + {"is_company": True, "name": "other", "ref": "same_ref",} + ) # Here there shouldn't be any problem - self.partner_obj.create({ - 'is_company': False, - 'name': 'other', - 'ref': 'same_ref', - }) + self.partner_obj.create( + {"is_company": False, "name": "other", "ref": "same_ref",} + ) diff --git a/partner_ref_unique/views/res_company_view.xml b/partner_ref_unique/views/res_company_view.xml index 4091186bb..c791ec36a 100644 --- a/partner_ref_unique/views/res_company_view.xml +++ b/partner_ref_unique/views/res_company_view.xml @@ -1,20 +1,18 @@ - + - - - Add partner_ref_unique field - res.company - - - - - + + Add partner_ref_unique field + res.company + + + + + + - - - - + +