diff --git a/partner_firstname/README.rst b/partner_firstname/README.rst index 5602d35ee..7c9bf10e9 100644 --- a/partner_firstname/README.rst +++ b/partner_firstname/README.rst @@ -39,11 +39,28 @@ Contributors ------------ * Nicolas Bessi +* Yannick Vaucher +* Vincent Renaville +* Guewen Baconnier +* Holger Brunn * Jonathan Nemry * Olivier Laurent +* Sandy Carter +* Alexis de Lattre +* Lorenzo Battistini * Hans Henrik Gabelgaard * Jairo Llopis * Adrien Peiffer +* Ronald Portier +* Sylvain Van Hoof +* Pedro Baeza + +Translations +------------ + +* Danish: Hans Henrik Gabelgaard +* Italian: Leonardo Donelli +* Spanish: Antonio Espinosa Maintainer ---------- diff --git a/partner_firstname/__init__.py b/partner_firstname/__init__.py index 4cdd79b3f..8a9bba4af 100644 --- a/partner_firstname/__init__.py +++ b/partner_firstname/__init__.py @@ -1,21 +1,4 @@ # -*- coding: utf-8 -*- - -# Author: Nicolas Bessi. Copyright Camptocamp SA -# Copyright (C) -# 2014: Agile Business Group () -# 2015: Grupo ESOC -# -# 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 . - +# © 2013 Nicolas Bessi (Camptocamp SA) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import models diff --git a/partner_firstname/__openerp__.py b/partner_firstname/__openerp__.py index 6d8517cee..751f5eafe 100644 --- a/partner_firstname/__openerp__.py +++ b/partner_firstname/__openerp__.py @@ -1,31 +1,17 @@ # -*- coding: utf-8 -*- - -# Author: Nicolas Bessi. Copyright Camptocamp SA -# Copyright (C) -# 2014: Agile Business Group () -# 2015: Grupo ESOC -# -# 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 . +# © 2013 Nicolas Bessi (Camptocamp SA) +# © 2014 Agile Business Group () +# © 2015 Grupo ESOC () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { 'name': 'Partner first name and last name', 'summary': "Split first name and last name for non company partners", - 'version': '8.0.2.1.0', - "author": "Camptocamp, " + 'version': '9.0.1.0.0', + 'author': "Camptocamp, " "Grupo ESOC Ingeniería de Servicios, " "Odoo Community Association (OCA)", - "license": "AGPL-3", + 'license': "AGPL-3", 'maintainer': 'Camptocamp, Acsone', 'category': 'Extra Tools', 'website': @@ -39,6 +25,6 @@ 'demo': [], 'test': [], 'auto_install': False, - 'installable': False, + 'installable': True, 'images': [] } diff --git a/partner_firstname/exceptions.py b/partner_firstname/exceptions.py index a75429514..d2fdea566 100644 --- a/partner_firstname/exceptions.py +++ b/partner_firstname/exceptions.py @@ -1,20 +1,6 @@ # -*- coding: utf-8 -*- -# Odoo, Open Source Management Solution -# Copyright (C) 2014-2015 Grupo ESOC -# -# 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 . - +# © 2014-2015 Grupo ESOC () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp import _, exceptions diff --git a/partner_firstname/models/__init__.py b/partner_firstname/models/__init__.py new file mode 100644 index 000000000..95688f355 --- /dev/null +++ b/partner_firstname/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2013 Nicolas Bessi (Camptocamp SA) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import res_partner +from . import res_user diff --git a/partner_firstname/models.py b/partner_firstname/models/res_partner.py similarity index 87% rename from partner_firstname/models.py rename to partner_firstname/models/res_partner.py index fe2b5aa09..82acceb71 100644 --- a/partner_firstname/models.py +++ b/partner_firstname/models/res_partner.py @@ -1,26 +1,11 @@ # -*- coding: utf-8 -*- - -# Author: Nicolas Bessi. Copyright Camptocamp SA -# Copyright (C) -# 2014: Agile Business Group () -# 2015: Grupo ESOC -# -# 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 . - +# © 2013 Nicolas Bessi (Camptocamp SA) +# © 2014 Agile Business Group () +# © 2015 Grupo ESOC () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import logging from openerp import api, fields, models -from . import exceptions +from .. import exceptions _logger = logging.getLogger(__name__) @@ -161,7 +146,8 @@ class ResPartner(models.Model): @api.constrains("firstname", "lastname") def _check_name(self): """Ensure at least one name is set.""" - if not (self.firstname or self.lastname): + if ((self.type == 'contact' or self.is_company) and + not (self.firstname or self.lastname)): raise exceptions.EmptyNamesError(self) @api.one @@ -202,3 +188,11 @@ class ResPartner(models.Model): # Force calculations there records._inverse_name() _logger.info("%d partners updated installing module.", len(records)) + + # Disabling SQL constraint givint a more explicit error using a Python + # contstraint + _sql_constraints = [( + 'check_name', + "CHECK( 1=1 )", + 'Contacts require a name.' + )] diff --git a/partner_firstname/models/res_user.py b/partner_firstname/models/res_user.py new file mode 100644 index 000000000..efe6f9a9f --- /dev/null +++ b/partner_firstname/models/res_user.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +# © 2013 Nicolas Bessi (Camptocamp SA) +# © 2014 Agile Business Group () +# © 2015 Grupo ESOC () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +import logging +from openerp import api, models + + +_logger = logging.getLogger(__name__) + + +class ResUser(models.Model): + _inherit = 'res.users' + + @api.model + def default_get(self, fields_list): + """Invert name when getting default values.""" + result = super(ResUser, self).default_get(fields_list) + + partner_model = self.env['res.partner'] + inverted = partner_model._get_inverse_name( + partner_model._get_whitespace_cleaned_name(result.get("name", "")), + result.get("is_company", False)) + + for field in inverted.keys(): + if field in fields_list: + result[field] = inverted.get(field) + + return result + + @api.onchange("firstname", "lastname") + def _compute_name(self): + """Write the 'name' field according to splitted data.""" + for rec in self: + rec.name = rec.partner_id._get_computed_name( + rec.lastname, rec.firstname) diff --git a/partner_firstname/tests/__init__.py b/partner_firstname/tests/__init__.py index 69104a4e4..1fed38100 100644 --- a/partner_firstname/tests/__init__.py +++ b/partner_firstname/tests/__init__.py @@ -1,33 +1,6 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Authors: Nemry Jonathan -# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) -# 2015: Grupo ESOC -# All Rights Reserved -# -# WARNING: This program as such is intended to be used by professional -# programmers who take the whole responsibility of assessing all potential -# consequences resulting from its eventual inadequacies and bugs. -# End users who are looking for a ready-to-use solution with commercial -# guarantees and support are strongly advised to contact a Free Software -# Service Company. -# -# This program is Free Software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# 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 General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# -############################################################################## +# © 2014 Nemry Jonathan (Acsone SA/NV) (http://www.acsone.eu) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import ( test_create, @@ -35,5 +8,6 @@ from . import ( test_delete, test_empty, test_name, - test_onchange + test_onchange, + test_user_onchange ) diff --git a/partner_firstname/tests/base.py b/partner_firstname/tests/base.py index 2ca475620..15a2c795d 100644 --- a/partner_firstname/tests/base.py +++ b/partner_firstname/tests/base.py @@ -1,29 +1,6 @@ # -*- coding: utf-8 -*- - -# Authors: Nemry Jonathan -# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) -# All Rights Reserved -# -# WARNING: This program as such is intended to be used by professional -# programmers who take the whole responsibility of assessing all potential -# consequences resulting from its eventual inadequacies and bugs. -# End users who are looking for a ready-to-use solution with commercial -# guarantees and support are strongly advised to contact a Free Software -# Service Company. -# -# This program is Free Software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# 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 General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# © 2014 Nemry Jonathan (Acsone SA/NV) (http://www.acsone.eu) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp.tests.common import TransactionCase from .. import exceptions as ex diff --git a/partner_firstname/tests/test_empty.py b/partner_firstname/tests/test_empty.py index 168d987a5..4728ca20c 100644 --- a/partner_firstname/tests/test_empty.py +++ b/partner_firstname/tests/test_empty.py @@ -1,25 +1,11 @@ # -*- coding: utf-8 -*- -# Odoo, Open Source Management Solution -# Copyright (C) 2014-2015 Grupo ESOC -# -# 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 . - +# © 2014-2015 Grupo ESOC +# © 2016 Yannick Vaucher (Camptocamp) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). """Test situations where names are empty. To have more accurate results, remove the ``mail`` module before testing. """ - from openerp.tests.common import TransactionCase from .base import MailInstalled from .. import exceptions as ex @@ -33,8 +19,9 @@ class CompanyCase(TransactionCase): def tearDown(self): try: data = {"name": self.name} + model = self.env[self.model].with_context(**self.context) with self.assertRaises(ex.EmptyNamesError): - self.env[self.model].with_context(**self.context).create(data) + model.create(data) finally: super(CompanyCase, self).tearDown() @@ -49,7 +36,7 @@ class CompanyCase(TransactionCase): class PersonCase(CompanyCase): """Test ``res.partner`` when it is a person.""" - context = {"default_is_company": False} + context = {"default_is_company": False, "default_type": 'contact'} class UserCase(CompanyCase, MailInstalled): @@ -65,3 +52,23 @@ class UserCase(CompanyCase, MailInstalled): else: # Run tests super(UserCase, self).tearDown() + + +class AddressCase(TransactionCase): + """Test ``res.partner`` when it is a address.""" + + def test_new_empty_invoice_address(self): + """Create an invoice patner without name.""" + self.original = self.env["res.partner"].create({ + "is_company": False, + "type": 'invoice', + "lastname": "", + "firstname": ""}) + + def test_new_empty_shipping_address(self): + """Create an shipping patner without name.""" + self.original = self.env["res.partner"].create({ + "is_company": False, + "type": 'delivery', + "lastname": "", + "firstname": ""}) diff --git a/partner_firstname/tests/test_onchange.py b/partner_firstname/tests/test_onchange.py index 6d2ec278f..573f30522 100644 --- a/partner_firstname/tests/test_onchange.py +++ b/partner_firstname/tests/test_onchange.py @@ -1,4 +1,7 @@ # -*- coding: utf-8 -*- +# © 2015 Grupo ESOC +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + """These tests try to mimic the behavior of the UI form. The form operates in onchange mode, with its limitations. diff --git a/partner_firstname/tests/test_user_onchange.py b/partner_firstname/tests/test_user_onchange.py new file mode 100644 index 000000000..46fe41b74 --- /dev/null +++ b/partner_firstname/tests/test_user_onchange.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# © 2016 Yannick Vaucher (Camptocamp SA) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp.tests.common import TransactionCase + + +class UserOnchangeCase(TransactionCase): + + def test_create_from_form_only_firstname(self): + """In a new users form, a user set only the firstname.""" + firstname = u"Zoë" + with self.env.do_in_onchange(): + # Changes firstname, which triggers onchanges + self.user.firstname = firstname + self.user._compute_name() + + self.assertEqual(self.user.lastname, False) + self.assertEqual(self.user.firstname, firstname) + self.assertEqual(self.user.name, firstname) + + def test_create_from_form_only_lastname(self): + """In a new user form, a user set only the lastname.""" + lastname = u"Żywioł" + with self.env.do_in_onchange(): + # Changes lastname, which triggers onchanges + self.user.lastname = lastname + self.user._compute_name() + + self.assertEqual(self.user.firstname, False) + self.assertEqual(self.user.lastname, lastname) + self.assertEqual(self.user.name, lastname) + + def test_create_from_form_all(self): + """In a new user form, a user set all names.""" + firstname = u"Zoë" + lastname = u"Żywioł" + with self.env.do_in_onchange(): + # Changes firstname, which triggers onchanges + self.user.firstname = firstname + self.user._compute_name() + + # Changes lastname, which triggers onchanges + self.user.lastname = lastname + self.user._compute_name() + + self.assertEqual(self.user.lastname, lastname) + self.assertEqual(self.user.firstname, firstname) + self.assertEqual(self.user.name, u" ".join((lastname, firstname))) + + def setUp(self): + super(UserOnchangeCase, self).setUp() + self.user = self.env["res.users"].new() diff --git a/partner_firstname/views/res_partner.xml b/partner_firstname/views/res_partner.xml index 0838628eb..85c269613 100644 --- a/partner_firstname/views/res_partner.xml +++ b/partner_firstname/views/res_partner.xml @@ -15,7 +15,7 @@ } - + - - - - - - - - +
- -