From 6efc8ad6d8e9df02683cd91e4b4414a15859885f Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Wed, 28 Oct 2015 16:26:45 +0100 Subject: [PATCH 1/4] Fix module structure --- base_partner_sequence/__init__.py | 2 +- base_partner_sequence/__openerp__.py | 9 +++++---- base_partner_sequence/{ => data}/partner_sequence.xml | 0 base_partner_sequence/{ => models}/partner.py | 0 base_partner_sequence/{ => views}/partner_view.xml | 0 5 files changed, 6 insertions(+), 5 deletions(-) rename base_partner_sequence/{ => data}/partner_sequence.xml (100%) rename base_partner_sequence/{ => models}/partner.py (100%) rename base_partner_sequence/{ => views}/partner_view.xml (100%) diff --git a/base_partner_sequence/__init__.py b/base_partner_sequence/__init__.py index c6e9f2e38..78fb0ee66 100644 --- a/base_partner_sequence/__init__.py +++ b/base_partner_sequence/__init__.py @@ -19,4 +19,4 @@ # ############################################################################## -from . import partner +from . import models diff --git a/base_partner_sequence/__openerp__.py b/base_partner_sequence/__openerp__.py index 5eaa43580..fececf692 100644 --- a/base_partner_sequence/__openerp__.py +++ b/base_partner_sequence/__openerp__.py @@ -22,8 +22,9 @@ ############################################################################## { "name": "Add a sequence on customers' code", - "version": "8.0.1.1.0", - "author": "Tiny/initOS GmbH & Co. KG,Odoo Community Association (OCA)", + "version": "8.0.1.1.1", + "author": "Tiny/initOS GmbH & Co. KG," + "Odoo Community Association (OCA)", "category": "Generic Modules/Base", "website": "http://www.initos.com", "depends": ["base"], @@ -44,8 +45,8 @@ addon to OpenERP version 7.0. """, "data": [ - 'partner_sequence.xml', - 'partner_view.xml', + 'data/partner_sequence.xml', + 'views/partner_view.xml', ], "demo": [], "active": False, diff --git a/base_partner_sequence/partner_sequence.xml b/base_partner_sequence/data/partner_sequence.xml similarity index 100% rename from base_partner_sequence/partner_sequence.xml rename to base_partner_sequence/data/partner_sequence.xml diff --git a/base_partner_sequence/partner.py b/base_partner_sequence/models/partner.py similarity index 100% rename from base_partner_sequence/partner.py rename to base_partner_sequence/models/partner.py diff --git a/base_partner_sequence/partner_view.xml b/base_partner_sequence/views/partner_view.xml similarity index 100% rename from base_partner_sequence/partner_view.xml rename to base_partner_sequence/views/partner_view.xml From 792d6b850e3cdc21c9285f5965d1717f2b1be204 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Wed, 28 Oct 2015 18:06:32 +0100 Subject: [PATCH 2/4] Use new API --- base_partner_sequence/README.rst | 68 +++++++++++++ base_partner_sequence/__init__.py | 21 +--- base_partner_sequence/__openerp__.py | 19 +--- base_partner_sequence/models/__init__.py | 2 + base_partner_sequence/models/partner.py | 99 +++++++++---------- base_partner_sequence/tests/__init__.py | 2 + .../tests/test_base_partner_sequence.py | 19 ++++ 7 files changed, 139 insertions(+), 91 deletions(-) create mode 100644 base_partner_sequence/README.rst create mode 100644 base_partner_sequence/models/__init__.py create mode 100644 base_partner_sequence/tests/__init__.py create mode 100644 base_partner_sequence/tests/test_base_partner_sequence.py diff --git a/base_partner_sequence/README.rst b/base_partner_sequence/README.rst new file mode 100644 index 000000000..39c89d65d --- /dev/null +++ b/base_partner_sequence/README.rst @@ -0,0 +1,68 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +====================================== +Add a sequence on partner's reference. +====================================== + +This module adds the possibility to define a sequence for +the partner's reference. This reference is then set as default +when you create a new partner, using the defined sequence. + +The reference field is treated as a commercial field, i.e. it +is managed from the commercial partner and then propagated to +the partner's contacts. The field is visible on the contacts, +but it can only be modified from the commercial partner. + +No references are assigned for contacts such as shipping and +invoice addresses. +This module is a migration of the original base_partner_sequence +addon to OpenERP version 7.0. + + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/134/8.0 + + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed feedback +`here `_. + + +Credits +======= + +Contributors +------------ + +* Thomas Rehn +* Stefan Rijnhart +* Yannick Vaucher +* Sandy Carter +* Laurent Mignon (ACSONE) +* Guewen Baconnier +* Alexandre Fayolle + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit http://odoo-community.org. diff --git a/base_partner_sequence/__init__.py b/base_partner_sequence/__init__.py index 78fb0ee66..fcf98fb46 100644 --- a/base_partner_sequence/__init__.py +++ b/base_partner_sequence/__init__.py @@ -1,22 +1,3 @@ # -*- encoding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2009 Tiny SPRL (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - from . import models +from . import tests diff --git a/base_partner_sequence/__openerp__.py b/base_partner_sequence/__openerp__.py index fececf692..4d1213e45 100644 --- a/base_partner_sequence/__openerp__.py +++ b/base_partner_sequence/__openerp__.py @@ -24,32 +24,15 @@ "name": "Add a sequence on customers' code", "version": "8.0.1.1.1", "author": "Tiny/initOS GmbH & Co. KG," + "ACSONE SA/NV," "Odoo Community Association (OCA)", "category": "Generic Modules/Base", "website": "http://www.initos.com", - "depends": ["base"], "summary": "Sets customer's code from a sequence", - "description": """ - This module adds the possibility to define a sequence for - the partner code. This code is then set as default when you - create a new commercial partner, using the defined sequence. - - The reference field is treated as a commercial field, i.e. it - is managed from the commercial partner and then propagated to - the partner's contacts. The field is visible on the contacts, - but it can only be modified from the commercial partner. - - No codes are assigned for contacts such as shipping and - invoice addresses. - This module is a migration of the original base_partner_sequence - addon to OpenERP version 7.0. - """, "data": [ 'data/partner_sequence.xml', 'views/partner_view.xml', ], - "demo": [], "active": False, 'installable': False } -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/base_partner_sequence/models/__init__.py b/base_partner_sequence/models/__init__.py new file mode 100644 index 000000000..cb85880b7 --- /dev/null +++ b/base_partner_sequence/models/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import partner diff --git a/base_partner_sequence/models/partner.py b/base_partner_sequence/models/partner.py index 9f66b41d5..8a6f84274 100644 --- a/base_partner_sequence/models/partner.py +++ b/base_partner_sequence/models/partner.py @@ -1,76 +1,69 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2009 Tiny SPRL (). -# Copyright (C) 2013 initOS GmbH & Co. KG (). -# Author Thomas Rehn -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- +# © 2004-2009 Tiny SPRL (). +# © 2013 initOS GmbH & Co. KG (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp.osv import orm +from openerp import models, api -class ResPartner(orm.Model): +class ResPartner(models.Model): """Assigns 'ref' from a sequence on creation and copying""" _inherit = 'res.partner' - def create(self, cr, uid, vals, context=None): - context = context or {} - if not vals.get('ref') and self._needsRef(cr, uid, vals=vals, - context=context): - vals['ref'] = self.pool.get('ir.sequence')\ - .next_by_code(cr, uid, 'res.partner') - return super(ResPartner, self).create(cr, uid, vals, context) - - def copy(self, cr, uid, id, default=None, context=None): - default = default or {} - if self._needsRef(cr, uid, id=id, context=context): - default['ref'] = self.pool.get('ir.sequence')\ - .next_by_code(cr, uid, 'res.partner', - context=context) - return super(ResPartner, self).copy(cr, uid, id, default, - context=context) - - def _needsRef(self, cr, uid, id=None, vals=None, context=None): + @api.model + def _needsRef(self, partner_id=None, vals=None): """ Checks whether a sequence value should be assigned to a partner's 'ref' - :param cr: database cursor - :param uid: current user id - :param id: id of the partner object + :param parnter_id: id of the partner object :param vals: known field values of the partner object :return: true iff a sequence value should be assigned to the\ partner's 'ref' """ - if not vals and not id: + if not vals and not partner_id: raise Exception('Either field values or an id must be provided.') + vals = vals or {} # only assign a 'ref' to commercial partners - if id: - vals = self.read(cr, uid, id, ['parent_id', 'is_company'], - context=context) + if partner_id: + partner = self.browse(partner_id) + vals.setdefault('is_company', partner.is_company) + vals.setdefault('parent_id', partner.parent_id.id) return vals.get('is_company') or not vals.get('parent_id') - def _commercial_fields(self, cr, uid, context=None): + @api.model + def _commercial_fields(self): """ Make the partner reference a field that is propagated to the partner's contacts """ - return super(ResPartner, self)._commercial_fields( - cr, uid, context=context) + ['ref'] + return super(ResPartner, self)._commercial_fields() + ['ref'] + + @api.model + def _get_next_ref(self, partner=None, vals=None): + return self.env['ir.sequence'].get('res.partner') + + @api.model + def create(self, vals): + if not vals.get('ref') and self._needsRef(vals=vals): + vals['ref'] = self._get_next_ref(vals=vals) + return super(ResPartner, self).create(vals) + + @api.multi + def write(self, vals): + for partner in self: + ref = vals.get('ref') if 'ref' in vals else partner.ref + if not ref and self._needsRef(partner.id, vals): + vals['ref'] = self._get_next_ref(partner, vals) + super(ResPartner, partner).write(vals) + return True + + @api.one + def copy(self, default=None): + default = default or {} + if self._needsRef(self.id): + default.update({ + 'ref': self._get_next_ref(), + }) -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + return super(ResPartner, self).copy(default) diff --git a/base_partner_sequence/tests/__init__.py b/base_partner_sequence/tests/__init__.py new file mode 100644 index 000000000..8ef33bbfe --- /dev/null +++ b/base_partner_sequence/tests/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import test_base_partner_sequence diff --git a/base_partner_sequence/tests/test_base_partner_sequence.py b/base_partner_sequence/tests/test_base_partner_sequence.py new file mode 100644 index 000000000..24296253a --- /dev/null +++ b/base_partner_sequence/tests/test_base_partner_sequence.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# © 2015 ACSONE SA/NV (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import openerp.tests.common as common + + +class TestBasePartnerSequence(common.TransactionCase): + + def test_ref_sequence_on_partner(self): + res_partner = self.env['res.partner'] + partner = res_partner.create({ + 'name': "test1", + 'email': "test@test.com"}) + self.assertTrue(partner.ref, "A partner has always a ref.") + + copy = partner.copy() + self.assertTrue(copy.ref, "A partner with ref created by copy " + "has a ref by default.") From 0c6b94ddf8d8cb4742766383fa3a5605bc2e26c7 Mon Sep 17 00:00:00 2001 From: OCA Transbot Date: Sat, 30 Jan 2016 17:16:15 -0500 Subject: [PATCH 3/4] OCA Transbot updated translations from Transifex --- base_partner_sequence/i18n/fi.po | 31 +++++++++++++++++++++++++++++++ base_partner_sequence/i18n/it.po | 31 +++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 base_partner_sequence/i18n/fi.po create mode 100644 base_partner_sequence/i18n/it.po diff --git a/base_partner_sequence/i18n/fi.po b/base_partner_sequence/i18n/fi.po new file mode 100644 index 000000000..b52155278 --- /dev/null +++ b/base_partner_sequence/i18n/fi.po @@ -0,0 +1,31 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_partner_sequence +# +# Translators: +msgid "" +msgstr "" +"Project-Id-Version: partner-contact (8.0)\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-01-19 01:46+0000\n" +"PO-Revision-Date: 2015-05-21 21:57+0000\n" +"Last-Translator: <>\n" +"Language-Team: Finnish (http://www.transifex.com/oca/OCA-partner-contact-8-0/language/fi/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: fi\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: base_partner_sequence +#: model:ir.model,name:base_partner_sequence.model_res_partner +msgid "Partner" +msgstr "Kumppani" + +#. module: base_partner_sequence +#: view:res.partner:base_partner_sequence.view_partner_form +msgid "" +"{\n" +" 'readonly': [('is_company', '=', False),\n" +" ('parent_id', '!=', False)]}" +msgstr "" diff --git a/base_partner_sequence/i18n/it.po b/base_partner_sequence/i18n/it.po new file mode 100644 index 000000000..ff5845e1c --- /dev/null +++ b/base_partner_sequence/i18n/it.po @@ -0,0 +1,31 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_partner_sequence +# +# Translators: +msgid "" +msgstr "" +"Project-Id-Version: partner-contact (8.0)\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-02-27 23:26+0000\n" +"PO-Revision-Date: 2016-03-11 15:30+0000\n" +"Last-Translator: Maxime Chambreuil \n" +"Language-Team: Italian (http://www.transifex.com/oca/OCA-partner-contact-8-0/language/it/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: it\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: base_partner_sequence +#: model:ir.model,name:base_partner_sequence.model_res_partner +msgid "Partner" +msgstr "Partner" + +#. module: base_partner_sequence +#: view:res.partner:base_partner_sequence.view_partner_form +msgid "" +"{\n" +" 'readonly': [('is_company', '=', False),\n" +" ('parent_id', '!=', False)]}" +msgstr "" From 49e826db562533a2cd1eccd6dae640118f33f353 Mon Sep 17 00:00:00 2001 From: cubells Date: Fri, 16 Dec 2016 05:34:15 +0100 Subject: [PATCH 4/4] [9.0] [MIG] base_partner_sequence module --- base_partner_sequence/README.rst | 16 ++++--- base_partner_sequence/__init__.py | 7 +++- base_partner_sequence/__openerp__.py | 38 ++++++----------- .../data/partner_sequence.xml | 26 ++++-------- .../i18n/base_partner_sequence.pot | 21 ---------- base_partner_sequence/models/__init__.py | 5 +++ base_partner_sequence/models/partner.py | 42 +++++++++++-------- base_partner_sequence/tests/__init__.py | 5 +++ .../tests/test_base_partner_sequence.py | 28 ++++++++++--- base_partner_sequence/views/partner_view.xml | 26 +++++------- 10 files changed, 101 insertions(+), 113 deletions(-) delete mode 100644 base_partner_sequence/i18n/base_partner_sequence.pot diff --git a/base_partner_sequence/README.rst b/base_partner_sequence/README.rst index 39c89d65d..040ba9227 100644 --- a/base_partner_sequence/README.rst +++ b/base_partner_sequence/README.rst @@ -7,7 +7,7 @@ Add a sequence on partner's reference. ====================================== This module adds the possibility to define a sequence for -the partner's reference. This reference is then set as default +the partner's reference. This reference is then set as default when you create a new partner, using the defined sequence. The reference field is treated as a commercial field, i.e. it @@ -17,8 +17,6 @@ but it can only be modified from the commercial partner. No references are assigned for contacts such as shipping and invoice addresses. -This module is a migration of the original base_partner_sequence -addon to OpenERP version 7.0. Usage @@ -26,17 +24,16 @@ Usage .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/134/8.0 + :target: https://runbot.odoo-community.org/runbot/134/9.0 Bug Tracker =========== -Bugs are tracked on `GitHub Issues `_. -In case of trouble, please check there if your issue has already been reported. -If you spotted it first, help us smashing it by providing a detailed and welcomed feedback -`here `_. - +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed feedback. Credits ======= @@ -51,6 +48,7 @@ Contributors * Laurent Mignon (ACSONE) * Guewen Baconnier * Alexandre Fayolle +* Vicent Cubells Maintainer ---------- diff --git a/base_partner_sequence/__init__.py b/base_partner_sequence/__init__.py index fcf98fb46..062d23fcc 100644 --- a/base_partner_sequence/__init__.py +++ b/base_partner_sequence/__init__.py @@ -1,3 +1,8 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- +# Copyright 2004-2009 Tiny SPRL (). +# Copyright 2013 initOS GmbH & Co. KG (). +# Copyright 2016 Tecnativa - Vicent Cubells +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + from . import models from . import tests diff --git a/base_partner_sequence/__openerp__.py b/base_partner_sequence/__openerp__.py index 4d1213e45..5e3163105 100644 --- a/base_partner_sequence/__openerp__.py +++ b/base_partner_sequence/__openerp__.py @@ -1,38 +1,26 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2009 Tiny SPRL (). -# Copyright (C) 2013 initOS GmbH & Co. KG (). -# Author Thomas Rehn -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- +# Copyright 2004-2009 Tiny SPRL (). +# Copyright 2013 initOS GmbH & Co. KG (). +# Copyright 2016 Tecnativa - Vicent Cubells +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + { "name": "Add a sequence on customers' code", - "version": "8.0.1.1.1", + "version": "9.0.0.1.0", "author": "Tiny/initOS GmbH & Co. KG," "ACSONE SA/NV," + "Tecnativa, " "Odoo Community Association (OCA)", "category": "Generic Modules/Base", "website": "http://www.initos.com", + "depends": [ + 'base', + ], "summary": "Sets customer's code from a sequence", "data": [ 'data/partner_sequence.xml', 'views/partner_view.xml', ], - "active": False, - 'installable': False + "installable": True, + "license": "AGPL-3", } diff --git a/base_partner_sequence/data/partner_sequence.xml b/base_partner_sequence/data/partner_sequence.xml index 76f3d8bb7..aa053d1bd 100644 --- a/base_partner_sequence/data/partner_sequence.xml +++ b/base_partner_sequence/data/partner_sequence.xml @@ -1,21 +1,11 @@ - - + - # - # Sequences for res.partner - # + + Partner code + res.partner + P/ + 5 + - - Partner code - res.partner - - - Partner code - res.partner - P/ - 5 - - - - + diff --git a/base_partner_sequence/i18n/base_partner_sequence.pot b/base_partner_sequence/i18n/base_partner_sequence.pot deleted file mode 100644 index 769df21c8..000000000 --- a/base_partner_sequence/i18n/base_partner_sequence.pot +++ /dev/null @@ -1,21 +0,0 @@ -# Translation of OpenERP Server. -# This file contains the translation of the following modules: -# -msgid "" -msgstr "" -"Project-Id-Version: OpenERP Server 7.0-20131013-231025\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2013-11-13 13:47+0000\n" -"PO-Revision-Date: 2013-11-13 13:47+0000\n" -"Last-Translator: <>\n" -"Language-Team: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: \n" -"Plural-Forms: \n" - -#. module: base_partner_sequence -#: model:ir.model,name:base_partner_sequence.model_res_partner -msgid "Partner" -msgstr "" - diff --git a/base_partner_sequence/models/__init__.py b/base_partner_sequence/models/__init__.py index cb85880b7..9e8bfde26 100644 --- a/base_partner_sequence/models/__init__.py +++ b/base_partner_sequence/models/__init__.py @@ -1,2 +1,7 @@ # -*- coding: utf-8 -*- +# Copyright 2004-2009 Tiny SPRL (). +# Copyright 2013 initOS GmbH & Co. KG (). +# Copyright 2016 Tecnativa - Vicent Cubells +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + from . import partner diff --git a/base_partner_sequence/models/partner.py b/base_partner_sequence/models/partner.py index 8a6f84274..9dea8b649 100644 --- a/base_partner_sequence/models/partner.py +++ b/base_partner_sequence/models/partner.py @@ -1,9 +1,10 @@ # -*- coding: utf-8 -*- -# © 2004-2009 Tiny SPRL (). -# © 2013 initOS GmbH & Co. KG (). +# Copyright 2004-2009 Tiny SPRL (). +# Copyright 2013 initOS GmbH & Co. KG (). +# Copyright 2016 Tecnativa - Vicent Cubells # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import models, api +from openerp import models, api, exceptions, _ class ResPartner(models.Model): @@ -16,20 +17,24 @@ class ResPartner(models.Model): """ Checks whether a sequence value should be assigned to a partner's 'ref' - :param parnter_id: id of the partner object + :param partner_id: id of the partner object :param vals: known field values of the partner object - :return: true iff a sequence value should be assigned to the\ - partner's 'ref' + :return: true if a sequence value should be assigned to the + partner's 'ref' """ if not vals and not partner_id: - raise Exception('Either field values or an id must be provided.') - vals = vals or {} + raise exceptions.Warning( + _('Either field values or an id must be provided.') + ) + if vals is None: + vals = {} + values = vals.copy() # only assign a 'ref' to commercial partners if partner_id: partner = self.browse(partner_id) - vals.setdefault('is_company', partner.is_company) - vals.setdefault('parent_id', partner.parent_id.id) - return vals.get('is_company') or not vals.get('parent_id') + values.setdefault('is_company', partner.is_company) + values.setdefault('parent_id', partner.parent_id.id) + return values.get('is_company') or not values.get('parent_id') @api.model def _commercial_fields(self): @@ -41,7 +46,7 @@ class ResPartner(models.Model): @api.model def _get_next_ref(self, partner=None, vals=None): - return self.env['ir.sequence'].get('res.partner') + return self.env['ir.sequence'].next_by_code('res.partner') @api.model def create(self, vals): @@ -58,12 +63,13 @@ class ResPartner(models.Model): super(ResPartner, partner).write(vals) return True - @api.one + @api.multi def copy(self, default=None): - default = default or {} - if self._needsRef(self.id): - default.update({ - 'ref': self._get_next_ref(), - }) + for partner in self: + default = default or {} + if self._needsRef(self.id): + default.update({ + 'ref': self._get_next_ref(), + }) return super(ResPartner, self).copy(default) diff --git a/base_partner_sequence/tests/__init__.py b/base_partner_sequence/tests/__init__.py index 8ef33bbfe..675c51b6e 100644 --- a/base_partner_sequence/tests/__init__.py +++ b/base_partner_sequence/tests/__init__.py @@ -1,2 +1,7 @@ # -*- coding: utf-8 -*- +# Copyright 2004-2009 Tiny SPRL (). +# Copyright 2013 initOS GmbH & Co. KG (). +# Copyright 2016 Tecnativa - Vicent Cubells +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + from . import test_base_partner_sequence diff --git a/base_partner_sequence/tests/test_base_partner_sequence.py b/base_partner_sequence/tests/test_base_partner_sequence.py index 24296253a..32c68f2b1 100644 --- a/base_partner_sequence/tests/test_base_partner_sequence.py +++ b/base_partner_sequence/tests/test_base_partner_sequence.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# © 2015 ACSONE SA/NV (). +# Copyright 2015 ACSONE SA/NV (). +# Copyright 2016 Tecnativa - Vicent Cubells # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import openerp.tests.common as common @@ -7,13 +8,28 @@ import openerp.tests.common as common class TestBasePartnerSequence(common.TransactionCase): - def test_ref_sequence_on_partner(self): - res_partner = self.env['res.partner'] - partner = res_partner.create({ + def setUp(self): + super(TestBasePartnerSequence, self).setUp() + + self.res_partner = self.env['res.partner'] + self.partner = self.res_partner.create({ 'name': "test1", 'email': "test@test.com"}) - self.assertTrue(partner.ref, "A partner has always a ref.") - copy = partner.copy() + def test_ref_sequence_on_partner(self): + # Test sequence on creating partner and copying it + self.assertTrue(self.partner.ref, "A partner has always a ref.") + + copy = self.partner.copy() self.assertTrue(copy.ref, "A partner with ref created by copy " "has a ref by default.") + + def test_ref_sequence_on_contact(self): + # Test if sequence doesn't increase on creating a contact child + contact = self.res_partner.create({ + 'name': "contact1", + 'email': "contact@contact.com", + 'parent_id': self.partner.id}) + self.assertEqual( + self.partner.ref, contact.ref, "All it's ok as sequence doesn't " + "increase.") diff --git a/base_partner_sequence/views/partner_view.xml b/base_partner_sequence/views/partner_view.xml index 00dcb16bb..f4207a625 100644 --- a/base_partner_sequence/views/partner_view.xml +++ b/base_partner_sequence/views/partner_view.xml @@ -1,20 +1,16 @@ - - + - - Make partner reference readonly when non-commercial - res.partner - - - - { - 'readonly': [('is_company', '=', False), - ('parent_id', '!=', False)]} - + + Make partner reference readonly when non-commercial + res.partner + + + + {'readonly': [('is_company', '=', False), ('parent_id', '!=', False)]} + + - - - +