From c8d9dbe5f08b3deae3d0f3aab66903d7609a64f7 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Mon, 7 Sep 2015 13:56:10 +0200 Subject: [PATCH] Fix bug #154. --- partner_firstname/__openerp__.py | 4 +-- partner_firstname/models.py | 3 +- partner_firstname/tests/__init__.py | 2 +- partner_firstname/tests/test_delete.py | 39 ++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 partner_firstname/tests/test_delete.py diff --git a/partner_firstname/__openerp__.py b/partner_firstname/__openerp__.py index 264b3066e..601aad89c 100644 --- a/partner_firstname/__openerp__.py +++ b/partner_firstname/__openerp__.py @@ -21,8 +21,8 @@ { 'name': 'Partner first name and last name', 'summary': "Split first name and last name for non company partners", - 'version': '8.0.2.0.0', - 'author': "Camptocamp, Odoo Community Association (OCA)", + 'version': '8.0.2.1.0', + 'author': "Camptocamp,Odoo Community Association (OCA)", "license": "AGPL-3", 'maintainer': 'Camptocamp, Acsone', 'category': 'Extra Tools', diff --git a/partner_firstname/models.py b/partner_firstname/models.py index 48342b20d..fa1f1af75 100644 --- a/partner_firstname/models.py +++ b/partner_firstname/models.py @@ -79,7 +79,8 @@ class ResPartner(models.Model): @api.depends("firstname", "lastname") def _compute_name(self): """Write the 'name' field according to splitted data.""" - self.name = self._get_computed_name(self.lastname, self.firstname) + if self.exists(): + self.name = self._get_computed_name(self.lastname, self.firstname) @api.one def _inverse_name_after_cleaning_whitespace(self): diff --git a/partner_firstname/tests/__init__.py b/partner_firstname/tests/__init__.py index 239670f65..ddba87365 100644 --- a/partner_firstname/tests/__init__.py +++ b/partner_firstname/tests/__init__.py @@ -28,4 +28,4 @@ # ############################################################################## -from . import test_defaults, test_empty, test_name, test_onchange +from . import test_defaults, test_delete, test_empty, test_name, test_onchange diff --git a/partner_firstname/tests/test_delete.py b/partner_firstname/tests/test_delete.py new file mode 100644 index 000000000..e31a3f44f --- /dev/null +++ b/partner_firstname/tests/test_delete.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# © 2015 Grupo ESOC +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp.tests.common import TransactionCase +from .base import MailInstalled +from .. import exceptions as ex + + +class CompanyCase(TransactionCase): + model = "res.partner" + context = {"default_is_company": True} + + def test_computing_after_unlink(self): + """Test what happens if recomputed after unlinking. + + This test might seem useless, but really this happens when module + ``partner_relations`` is installed. + + See https://github.com/OCA/partner-contact/issues/154. + """ + data = {"name": u"Söme name"} + record = self.env[self.model].with_context(**self.context).create(data) + record.unlink() + record.recompute() + + +class PersonCase(CompanyCase): + context = {"default_is_company": False} + + +class UserCase(CompanyCase, MailInstalled): + model = "res.users" + context = {"default_login": "user@example.com"} + + def test_computing_after_unlink(self): + # Cannot create users if ``mail`` is installed + if not self.mail_installed(): + super(UserCase, self).test_computing_after_unlink()