From 39faa49e486d4360c30ec01fecc80ad65070f4a6 Mon Sep 17 00:00:00 2001 From: Fekete Mihai Date: Fri, 24 Apr 2015 12:47:30 +0300 Subject: [PATCH 01/42] [ADD] hr_employee_firstname --- hr_employee_firstname/README.rst | 50 +++++++++++ hr_employee_firstname/__init__.py | 23 ++++++ hr_employee_firstname/__openerp__.py | 43 ++++++++++ hr_employee_firstname/i18n/de.po | 32 +++++++ hr_employee_firstname/i18n/fr.po | 32 +++++++ .../i18n/hr_employee_firstname.pot | 32 +++++++ hr_employee_firstname/i18n/ro.po | 32 +++++++ hr_employee_firstname/models/__init__.py | 23 ++++++ hr_employee_firstname/models/hr.py | 78 ++++++++++++++++++ .../static/description/icon.png | Bin 0 -> 5938 bytes hr_employee_firstname/tests/__init__.py | 1 + .../tests/test_hr_employee_firstname.py | 78 ++++++++++++++++++ hr_employee_firstname/views/hr_view.xml | 27 ++++++ 13 files changed, 451 insertions(+) create mode 100644 hr_employee_firstname/README.rst create mode 100644 hr_employee_firstname/__init__.py create mode 100644 hr_employee_firstname/__openerp__.py create mode 100644 hr_employee_firstname/i18n/de.po create mode 100644 hr_employee_firstname/i18n/fr.po create mode 100644 hr_employee_firstname/i18n/hr_employee_firstname.pot create mode 100644 hr_employee_firstname/i18n/ro.po create mode 100644 hr_employee_firstname/models/__init__.py create mode 100644 hr_employee_firstname/models/hr.py create mode 100644 hr_employee_firstname/static/description/icon.png create mode 100644 hr_employee_firstname/tests/__init__.py create mode 100644 hr_employee_firstname/tests/test_hr_employee_firstname.py create mode 100644 hr_employee_firstname/views/hr_view.xml diff --git a/hr_employee_firstname/README.rst b/hr_employee_firstname/README.rst new file mode 100644 index 00000000000..ba584a39c40 --- /dev/null +++ b/hr_employee_firstname/README.rst @@ -0,0 +1,50 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + +HR Employee First Name, Last Name +================================= + +This module allows you to add firstname and lastname in employee form, +and concatenate both in name field. + +Installation +============ + +To install this module, you need to: + +* clone the branch 8.0 of the repository https://github.com/OCA/hr +* add the path to this repository in your configuration (addons-path) +* update the module list +* search for "HR Employee First Name, Last Name" in your addons +* install the module + +Usage +===== + +On the employee form view you will have 2 separate fields, one for Firstname, +second for Lastname, both required. + +Credits +======= + +Contributors +------------ + +* El Hadji Dem (elhadji.dem@savoirfairelinux.com) +* Sandy Carter (sandy.carter@savoirfairelinux.com) +* Fekete Mihai + +Maintainer +---------- + +.. image:: http://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: http://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/hr_employee_firstname/__init__.py b/hr_employee_firstname/__init__.py new file mode 100644 index 00000000000..8a84e445229 --- /dev/null +++ b/hr_employee_firstname/__init__.py @@ -0,0 +1,23 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2010 - 2014 Savoir-faire Linux +# (). +# +# 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 diff --git a/hr_employee_firstname/__openerp__.py b/hr_employee_firstname/__openerp__.py new file mode 100644 index 00000000000..09c011bd8a2 --- /dev/null +++ b/hr_employee_firstname/__openerp__.py @@ -0,0 +1,43 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2010 - 2014 Savoir-faire Linux +# (). +# +# 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 . +# +############################################################################## + +{ + 'name': 'HR Employee First Name, Last Name', + 'version': '0.1', + 'author': "Savoir-faire Linux, " + "Fekete Mihai (Forest and Biomass Services Romania), " + "Odoo Community Association (OCA)", + 'maintainer': 'Savoir-faire Linux', + 'website': 'http://www.savoirfairelinux.com', + 'license': 'AGPL-3', + 'category': 'Human Resources', + 'summary': 'Adds First Name to Employee', + 'depends': [ + 'hr', + ], + 'data': [ + 'views/hr_view.xml', + ], + 'demo': [], + 'test': [], + 'installable': True, +} diff --git a/hr_employee_firstname/i18n/de.po b/hr_employee_firstname/i18n/de.po new file mode 100644 index 00000000000..1f03c294dee --- /dev/null +++ b/hr_employee_firstname/i18n/de.po @@ -0,0 +1,32 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_employee_firstname +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-04-24 10:20+0000\n" +"PO-Revision-Date: 2015-04-24 10:20+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: hr_employee_firstname +#: model:ir.model,name:hr_employee_firstname.model_hr_employee +msgid "Employee" +msgstr "Angestellter" + +#. module: hr_employee_firstname +#: field:hr.employee,firstname:0 +msgid "Firstname" +msgstr "Vorname" + +#. module: hr_employee_firstname +#: field:hr.employee,lastname:0 +msgid "Lastname" +msgstr "Nachname" + diff --git a/hr_employee_firstname/i18n/fr.po b/hr_employee_firstname/i18n/fr.po new file mode 100644 index 00000000000..36d16120c3d --- /dev/null +++ b/hr_employee_firstname/i18n/fr.po @@ -0,0 +1,32 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_employee_firstname +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-04-24 10:20+0000\n" +"PO-Revision-Date: 2015-04-24 10:20+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: hr_employee_firstname +#: model:ir.model,name:hr_employee_firstname.model_hr_employee +msgid "Employee" +msgstr "Employé" + +#. module: hr_employee_firstname +#: field:hr.employee,firstname:0 +msgid "Firstname" +msgstr "Prénom" + +#. module: hr_employee_firstname +#: field:hr.employee,lastname:0 +msgid "Lastname" +msgstr "Nom" + diff --git a/hr_employee_firstname/i18n/hr_employee_firstname.pot b/hr_employee_firstname/i18n/hr_employee_firstname.pot new file mode 100644 index 00000000000..6b13f0cf122 --- /dev/null +++ b/hr_employee_firstname/i18n/hr_employee_firstname.pot @@ -0,0 +1,32 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_employee_firstname +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-04-24 10:20+0000\n" +"PO-Revision-Date: 2015-04-24 10:20+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: hr_employee_firstname +#: model:ir.model,name:hr_employee_firstname.model_hr_employee +msgid "Employee" +msgstr "" + +#. module: hr_employee_firstname +#: field:hr.employee,firstname:0 +msgid "Firstname" +msgstr "" + +#. module: hr_employee_firstname +#: field:hr.employee,lastname:0 +msgid "Lastname" +msgstr "" + diff --git a/hr_employee_firstname/i18n/ro.po b/hr_employee_firstname/i18n/ro.po new file mode 100644 index 00000000000..e8d7be091fc --- /dev/null +++ b/hr_employee_firstname/i18n/ro.po @@ -0,0 +1,32 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_employee_firstname +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-04-24 10:20+0000\n" +"PO-Revision-Date: 2015-04-24 10:20+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: hr_employee_firstname +#: model:ir.model,name:hr_employee_firstname.model_hr_employee +msgid "Employee" +msgstr "Angajat" + +#. module: hr_employee_firstname +#: field:hr.employee,firstname:0 +msgid "Firstname" +msgstr "Prenume" + +#. module: hr_employee_firstname +#: field:hr.employee,lastname:0 +msgid "Lastname" +msgstr "Nume" + diff --git a/hr_employee_firstname/models/__init__.py b/hr_employee_firstname/models/__init__.py new file mode 100644 index 00000000000..a5f6a47b477 --- /dev/null +++ b/hr_employee_firstname/models/__init__.py @@ -0,0 +1,23 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2010 - 2014 Savoir-faire Linux +# (). +# +# 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 hr diff --git a/hr_employee_firstname/models/hr.py b/hr_employee_firstname/models/hr.py new file mode 100644 index 00000000000..67458d6434f --- /dev/null +++ b/hr_employee_firstname/models/hr.py @@ -0,0 +1,78 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2010 - 2014 Savoir-faire Linux +# (). +# +# 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 openerp import models, fields, api + + +class hr_employee(models.Model): + _inherit = 'hr.employee' + + @api.cr_context + def _auto_init(self, cr, context=None): + res = super(hr_employee, self)._auto_init(cr, context=context) + cr.execute(""" +UPDATE hr_employee +SET firstname = COALESCE(LEFT(trim(name_related), + COALESCE(POSITION(' ' IN trim(name_related))-1, + CHAR_LENGTH(trim(name_related)))), + ' '), + lastname = COALESCE(RIGHT(trim(name_related), + CHAR_LENGTH(trim(name_related))- + POSITION(' ' IN trim(name_related))), + ' ') +WHERE name_related IS NOT NULL OR name_related != ' ' AND + (firstname IS NULL OR firstname = ' ') AND + (lastname IS NULL or lastname = ' ')""") + return res + + @api.one + @api.onchange('firstname', 'lastname') + def get_name(self): + if self.firstname and self.lastname: + self.name_related = self.firstname + ' ' + self.lastname + + @api.one + @api.depends('firstname', 'lastname') + def _get_name(self): + if self.firstname and self.lastname: + self.name_related = self.firstname + ' ' + self.lastname + + firstname = fields.Char("Firstname", required=True) + lastname = fields.Char("Lastname", required=True) + name_related = fields.Char(string="Name", readonly=True, + compute="_get_name", + store=True) + + @api.model + def create(self, vals): + if vals.get('firstname', ' ') != ' ' and vals.get('lastname', + ' ') != ' ': + vals['name'] = vals['firstname'] + ' ' + vals['lastname'] + if vals['name'] and vals.get('firstname', ' ') and vals.get('lastname', + ' '): + if len(vals['name'].strip().split(' ', 1)) > 1: + vals['firstname'] = vals['name'].strip().split(' ', 1)[0] + vals['lastname'] = vals['name'].strip().split(' ', 1)[1] + else: + vals['firstname'] = vals['name'] + vals['lastname'] = ' ' + return super(hr_employee, self).create(vals) diff --git a/hr_employee_firstname/static/description/icon.png b/hr_employee_firstname/static/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..297dc71c85c5fdd8deafabfbb46093e04adc32d1 GIT binary patch literal 5938 zcmZ{oWmFXI^Y&S~Q@W%NlQZ+2a^I50RaI=RYgJPA7%a%I_ke%>+HSx52!Zk$_fat|3z_c zRp!46hL?)5??0;iPfBC1QvVhGy<{E#QRaU-zJ^;NAdm>DD#+>uuAb#%d@$Y59w{n} zV@#J(iOk|Fp-kV&k~3Y^QH$!(b+Vq~dGD0q{}wxo1QD4Ps4`oh%BjA|XuNqJw)KbU zmpavmsg3xhhiZr2#20(@&3p63$LZ&9j3cTAh>i|#FLw%kr!zU3W-neY9@ut3l-qwa z#k^E@g@A`1VZjown>hzQ!q3=j>*ndcspz`~cX97qSv}6)AC;AA@7E#4tV-J2{*Hha z)r3^~l!T6WtKR|f=s>a~gDr;nr)*aNd2P!8qI( zt@@jCF0-niv+}!9!YT1ys6a}j=R&qeYbXcKL^aareQJmn zt*AYTL#Hk6JWoOVVwM}p9j|>vl2v zj7Z~drXXFMN6y3u55X24pj*p`8-1JyGw}9{MVh`$Q-YlcgP-2c-JsjrQ)%X@)XvO@ z=k4sM?J(iU9B-bGdb!sT%9-m;cSwJTIJO04K4;Lnu;VPXfzl;APGBN?`uau zFkV!VR*dwmL?ErsR?bk?9`nuF7V?~OXX*8}I~2qCMDF*XHJ2^Q0LxR#F0Rx-16x}7 zrl(JH)ci$U1p^>-{%jjblml7BX5LQ{6?Y49E(!=q_B=mN_JK!n*)60X9WiQqjW8wO zYIr1H6nWkMEz9hl-kqY6q8tU;RfYUW#50W0)IZ*I{>lJn!-2ON4kY+S|Nh(btN8>K zTT~lIq>lhN+io33zP>sIqeOVh%@+>PqqkJwmi9A5P8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`BHhClkx;H`JSk~Ttd5GY({L&1e?@ro;X?i4Ydl);F;wRVRx9Bn&kc!o)Sl~z_ z5CQ#86V0KQ-(9hBGUwud@rXduz%Mk|H{?8!wKzZ-O|LnpQ?+E;o^A!~V>^k6D6xnd zIH(qQ2<1O5{oVuI+Z|4ljOkl$8fWCQoRVkuv)in~o164Wzg-7S+U)G*09}+29bg-k z6|fFK0<%QNWb+Fb+3iD13oqZpvlsX3_mojiiInYFH`6Hf7)O~;ahL_4ubvp9`%UGp z$4M(6d~&)2-lA0-nLOpnwZuxjB`(iIufhdS;V%yiTBR5ca;J7Iwk%4mY5;+dFI7V; zz7^=|Q!NMo{@GM4@(t6Bw4yNg>M1as7 z(YKyLW4AaK(X=h#HMD}7BWG+}9EgNBfcL11b-Jw{g-ZnBAypD%V{C=a_RP9+%&mXv zYA!=`cuYK?S`G+ECwenaSJ^Yf?T3E1pL`42z?_cH$B1^Uy`R%FUR#geTc;oQU4v5O zDWGtLejeaw9f<(a^=oi+1*;)Np4onst25!+{sHy+FbRRd zPn{b1<`{#;i4{Pd-v>#1N^|3=j~2yNm1MJzAOMP%14VIuUuBixf~dO?jso!wj36qN#&u}7i( z(&mmB*QfBxJUKMh_Wbz~@Oh@10!Aik%d(Qjwj{icpZ#2S^1pDcuy{pM!1qsjWuJci zcS>gZplI~L&iaGBn5~cfKOpe&@Q8B$d%XO5yaHmp{9-&j>^yw`@*g!m+W*Jk?rG=j z5cK~yWRfPA{WFmNH$m6a;X{D6k3B*_KmeDshpVrxwU<4Yr;lU)xdg?(CInSQ4TVNI HtLXm&e3x`` literal 0 HcmV?d00001 diff --git a/hr_employee_firstname/tests/__init__.py b/hr_employee_firstname/tests/__init__.py new file mode 100644 index 00000000000..a9df4e5c6e2 --- /dev/null +++ b/hr_employee_firstname/tests/__init__.py @@ -0,0 +1 @@ +from . import test_hr_employee_firstname diff --git a/hr_employee_firstname/tests/test_hr_employee_firstname.py b/hr_employee_firstname/tests/test_hr_employee_firstname.py new file mode 100644 index 00000000000..e87e3278c53 --- /dev/null +++ b/hr_employee_firstname/tests/test_hr_employee_firstname.py @@ -0,0 +1,78 @@ +# -*- coding:utf-8 -*- +############################################################################## +# +# Copyright (C) 2014 Savoir-faire Linux. All Rights Reserved. +# +# 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 openerp.tests.common import TransactionCase + + +class TestEmployeeFirstname(TransactionCase): + def setUp(self): + super(TestEmployeeFirstname, self).setUp() + self.employee_model = self.env['hr.employee'] + + # Create 3 employees to concatenate the firstname and lastname + # in name_related + self.employee1_id = self.employee_model.create( + {'firstname': 'Jan', 'lastname': 'Van Eyck'}) + self.employee2_id = self.employee_model.create( + {'firstname': 'Jean-Pierre', 'lastname': 'Carnaud'}) + self.employee3_id = self.employee_model.create( + {'firstname': 'Famke', 'lastname': 'Jenssens'}) + + # Create 3 employees for split the name_related to + # firstname and lastname + self.employee10_id = self.employee_model.create( + {'name': ' Jan Van Eyck', 'firstname': ' ', 'lastname': ' '}) + self.employee20_id = self.employee_model.create( + {'name': 'Jean-Pierre Carnaud', 'firstname': ' ', 'lastname': ' '}) + self.employee30_id = self.employee_model.create( + {'name': 'FamkeJenssens', 'firstname': ' ', 'lastname': ' '}) + + def test_get_name(self): + """ + Validate the _get_name method is concatenating + the firstname and lastname + """ + # Check for employee1 + self.assertTrue(self.employee1_id.name_related == 'Jan Van Eyck') + + # Check for employee2 + self.assertTrue(self.employee2_id.name_related == 'Jean-Pierre ' + 'Carnaud') + + # Check for employee3 + self.assertTrue(self.employee3_id.name_related == 'Famke Jenssens') + + def test_auto_init_name(self): + """ + Validate the _auto_init if the name related is split + in firstname and lastname + """ + # Check for employee10 + self.assertTrue(self.employee10_id.firstname == "Jan") + self.assertTrue(self.employee10_id.lastname == 'Van Eyck') + + # Check for employee20 + self.assertTrue(self.employee20_id.firstname == 'Jean-Pierre') + self.assertTrue(self.employee20_id.lastname == 'Carnaud') + + # Check for employee30 + self.assertTrue(self.employee30_id.firstname == 'FamkeJenssens') + self.assertTrue(self.employee30_id.lastname == ' ') diff --git a/hr_employee_firstname/views/hr_view.xml b/hr_employee_firstname/views/hr_view.xml new file mode 100644 index 00000000000..105296c6c70 --- /dev/null +++ b/hr_employee_firstname/views/hr_view.xml @@ -0,0 +1,27 @@ + + + + + + hr.employee + + + + + + From 4e55fbd736bd516418c1466d00ece5d917488d24 Mon Sep 17 00:00:00 2001 From: dufresnedavid Date: Sun, 3 May 2015 07:31:49 -0400 Subject: [PATCH 02/42] Remove field name related, change init script, add unittests --- hr_employee_firstname/README.rst | 5 +- hr_employee_firstname/models/__init__.py | 2 +- hr_employee_firstname/models/hr.py | 78 ---------------- hr_employee_firstname/models/hr_employee.py | 89 +++++++++++++++++++ .../tests/test_hr_employee_firstname.py | 61 ++++++++++--- 5 files changed, 140 insertions(+), 95 deletions(-) delete mode 100644 hr_employee_firstname/models/hr.py create mode 100644 hr_employee_firstname/models/hr_employee.py diff --git a/hr_employee_firstname/README.rst b/hr_employee_firstname/README.rst index ba584a39c40..7ccfc5ab980 100644 --- a/hr_employee_firstname/README.rst +++ b/hr_employee_firstname/README.rst @@ -30,9 +30,10 @@ Credits Contributors ------------ -* El Hadji Dem (elhadji.dem@savoirfairelinux.com) -* Sandy Carter (sandy.carter@savoirfairelinux.com) +* El Hadji Dem +* Sandy Carter * Fekete Mihai +* David Dufresne Maintainer ---------- diff --git a/hr_employee_firstname/models/__init__.py b/hr_employee_firstname/models/__init__.py index a5f6a47b477..47d73b16366 100644 --- a/hr_employee_firstname/models/__init__.py +++ b/hr_employee_firstname/models/__init__.py @@ -20,4 +20,4 @@ # ############################################################################## -from . import hr +from . import hr_employee diff --git a/hr_employee_firstname/models/hr.py b/hr_employee_firstname/models/hr.py deleted file mode 100644 index 67458d6434f..00000000000 --- a/hr_employee_firstname/models/hr.py +++ /dev/null @@ -1,78 +0,0 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2010 - 2014 Savoir-faire Linux -# (). -# -# 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 openerp import models, fields, api - - -class hr_employee(models.Model): - _inherit = 'hr.employee' - - @api.cr_context - def _auto_init(self, cr, context=None): - res = super(hr_employee, self)._auto_init(cr, context=context) - cr.execute(""" -UPDATE hr_employee -SET firstname = COALESCE(LEFT(trim(name_related), - COALESCE(POSITION(' ' IN trim(name_related))-1, - CHAR_LENGTH(trim(name_related)))), - ' '), - lastname = COALESCE(RIGHT(trim(name_related), - CHAR_LENGTH(trim(name_related))- - POSITION(' ' IN trim(name_related))), - ' ') -WHERE name_related IS NOT NULL OR name_related != ' ' AND - (firstname IS NULL OR firstname = ' ') AND - (lastname IS NULL or lastname = ' ')""") - return res - - @api.one - @api.onchange('firstname', 'lastname') - def get_name(self): - if self.firstname and self.lastname: - self.name_related = self.firstname + ' ' + self.lastname - - @api.one - @api.depends('firstname', 'lastname') - def _get_name(self): - if self.firstname and self.lastname: - self.name_related = self.firstname + ' ' + self.lastname - - firstname = fields.Char("Firstname", required=True) - lastname = fields.Char("Lastname", required=True) - name_related = fields.Char(string="Name", readonly=True, - compute="_get_name", - store=True) - - @api.model - def create(self, vals): - if vals.get('firstname', ' ') != ' ' and vals.get('lastname', - ' ') != ' ': - vals['name'] = vals['firstname'] + ' ' + vals['lastname'] - if vals['name'] and vals.get('firstname', ' ') and vals.get('lastname', - ' '): - if len(vals['name'].strip().split(' ', 1)) > 1: - vals['firstname'] = vals['name'].strip().split(' ', 1)[0] - vals['lastname'] = vals['name'].strip().split(' ', 1)[1] - else: - vals['firstname'] = vals['name'] - vals['lastname'] = ' ' - return super(hr_employee, self).create(vals) diff --git a/hr_employee_firstname/models/hr_employee.py b/hr_employee_firstname/models/hr_employee.py new file mode 100644 index 00000000000..e527c1562e9 --- /dev/null +++ b/hr_employee_firstname/models/hr_employee.py @@ -0,0 +1,89 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2010 - 2014 Savoir-faire Linux +# (). +# +# 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 openerp import models, fields, api, SUPERUSER_ID + + +class HrEmployee(models.Model): + _inherit = 'hr.employee' + + def split_name(self, name): + new_name = [w for w in name.split(' ') if w] + firstname = new_name[0] + lastname = ' '.join(new_name[1:]) or ' ' + return firstname, lastname + + @api.cr_context + def _auto_init(self, cr, context=None): + super(HrEmployee, self)._auto_init(cr, context=context) + self._update_employee_names(cr, SUPERUSER_ID, context=context) + + @api.model + def _update_employee_names(self): + employees = self.search([ + ('firstname', '=', ' '), ('lastname', '=', ' ')]) + + for ee in employees: + firstname, lastname = self.split_name(ee.name) + ee.write({ + 'firstname': firstname, + 'lastname': lastname, + }) + + @api.one + @api.onchange('firstname', 'lastname') + def get_name(self): + if self.firstname and self.lastname: + self.name = ' '.join([self.firstname, self.lastname]) + + def _firstname_default(self): + return ' ' if self.env.context.get('module') else False + + firstname = fields.Char( + "Firstname", required=True, default=_firstname_default) + lastname = fields.Char( + "Lastname", required=True, default=_firstname_default) + + @api.model + def create(self, vals): + if vals.get('firstname') and vals.get('lastname'): + vals['name'] = ' '.join([vals['firstname'], vals['lastname']]) + + elif vals.get('name'): + vals['firstname'], vals['lastname'] = self.split_name(vals['name']) + + return super(HrEmployee, self).create(vals) + + @api.multi + def write(self, vals): + if vals.get('firstname') or vals.get('lastname'): + self.ensure_one() + + vals['name'] = ' '.join([ + vals.get('firstname') or self.firstname or ' ', + vals.get('lastname') or self.lastname or ' ', + ]) + + elif vals.get('name'): + vals['firstname'], vals['lastname'] = self.split_name(vals['name']) + + return super(HrEmployee, self).write(vals) diff --git a/hr_employee_firstname/tests/test_hr_employee_firstname.py b/hr_employee_firstname/tests/test_hr_employee_firstname.py index e87e3278c53..e4334744fcf 100644 --- a/hr_employee_firstname/tests/test_hr_employee_firstname.py +++ b/hr_employee_firstname/tests/test_hr_employee_firstname.py @@ -39,11 +39,11 @@ def setUp(self): # Create 3 employees for split the name_related to # firstname and lastname self.employee10_id = self.employee_model.create( - {'name': ' Jan Van Eyck', 'firstname': ' ', 'lastname': ' '}) + {'name': ' Jan Van Eyck'}) self.employee20_id = self.employee_model.create( - {'name': 'Jean-Pierre Carnaud', 'firstname': ' ', 'lastname': ' '}) + {'name': 'Jean-Pierre Carnaud'}) self.employee30_id = self.employee_model.create( - {'name': 'FamkeJenssens', 'firstname': ' ', 'lastname': ' '}) + {'name': 'FamkeJenssens'}) def test_get_name(self): """ @@ -51,28 +51,61 @@ def test_get_name(self): the firstname and lastname """ # Check for employee1 - self.assertTrue(self.employee1_id.name_related == 'Jan Van Eyck') + self.assertEqual(self.employee1_id.name, 'Jan Van Eyck') # Check for employee2 - self.assertTrue(self.employee2_id.name_related == 'Jean-Pierre ' - 'Carnaud') + self.assertEqual(self.employee2_id.name, 'Jean-Pierre Carnaud') # Check for employee3 - self.assertTrue(self.employee3_id.name_related == 'Famke Jenssens') + self.assertEqual(self.employee3_id.name, 'Famke Jenssens') def test_auto_init_name(self): """ - Validate the _auto_init if the name related is split + Validate the create method if the name is split in firstname and lastname """ # Check for employee10 - self.assertTrue(self.employee10_id.firstname == "Jan") - self.assertTrue(self.employee10_id.lastname == 'Van Eyck') + self.assertEqual(self.employee10_id.firstname, "Jan") + self.assertEqual(self.employee10_id.lastname, 'Van Eyck') # Check for employee20 - self.assertTrue(self.employee20_id.firstname == 'Jean-Pierre') - self.assertTrue(self.employee20_id.lastname == 'Carnaud') + self.assertEqual(self.employee20_id.firstname, 'Jean-Pierre') + self.assertEqual(self.employee20_id.lastname, 'Carnaud') # Check for employee30 - self.assertTrue(self.employee30_id.firstname == 'FamkeJenssens') - self.assertTrue(self.employee30_id.lastname == ' ') + self.assertEqual(self.employee30_id.firstname, 'FamkeJenssens') + self.assertEqual(self.employee30_id.lastname, ' ') + + def test_change_name(self): + self.employee1_id.write({'name': 'Jean-Pierre Carnaud Eyck'}) + self.employee1_id.refresh() + + self.assertEqual(self.employee1_id.firstname, 'Jean-Pierre') + self.assertEqual(self.employee1_id.lastname, 'Carnaud Eyck') + + def test_change_name_with_space(self): + self.employee1_id.write({'name': ' Jean-Pierre Carnaud Eyck'}) + self.employee1_id.refresh() + + self.assertEqual(self.employee1_id.firstname, 'Jean-Pierre') + self.assertEqual(self.employee1_id.lastname, 'Carnaud Eyck') + + def test_change_firstname(self): + self.employee1_id.write({'firstname': 'Jean-Pierre'}) + self.employee1_id.refresh() + + self.assertEqual(self.employee1_id.name, 'Jean-Pierre Van Eyck') + + def test_change_lastname(self): + self.employee1_id.write({'lastname': 'Carnaud'}) + self.employee1_id.refresh() + + self.assertEqual(self.employee1_id.name, 'Jan Carnaud') + + def test_change_firstname_and_lastname(self): + self.employee1_id.write({ + 'firstname': 'Jean-Pierre', + 'lastname': 'Carnaud'}) + self.employee1_id.refresh() + + self.assertEqual(self.employee1_id.name, 'Jean-Pierre Carnaud') From 5646b75c067e5e58bdc8a4d73f7804e638305133 Mon Sep 17 00:00:00 2001 From: "Adrien Peiffer (ACSONE)" Date: Thu, 13 Aug 2015 13:34:34 +0200 Subject: [PATCH 03/42] [FIX+IMP] hr_employee_firstname: Several things: * remove ensure one * Add decorator * Update name on write and update related partner firstname lastname * Modify README file * Change version format * Consistency with partner_firstname module * Check if the partner isn't already in the list * Remove check on partner_firstname installation --- hr_employee_firstname/README.rst | 9 ++++ hr_employee_firstname/__openerp__.py | 3 +- hr_employee_firstname/i18n/en.po | 33 ++++++++++++ hr_employee_firstname/i18n/es.po | 33 ++++++++++++ hr_employee_firstname/i18n/sl.po | 34 ++++++++++++ hr_employee_firstname/models/hr_employee.py | 52 +++++++++++-------- .../tests/test_hr_employee_firstname.py | 34 ++++++------ hr_employee_firstname/views/hr_view.xml | 8 +-- 8 files changed, 163 insertions(+), 43 deletions(-) create mode 100644 hr_employee_firstname/i18n/en.po create mode 100644 hr_employee_firstname/i18n/es.po create mode 100644 hr_employee_firstname/i18n/sl.po diff --git a/hr_employee_firstname/README.rst b/hr_employee_firstname/README.rst index 7ccfc5ab980..c0ff8a600cd 100644 --- a/hr_employee_firstname/README.rst +++ b/hr_employee_firstname/README.rst @@ -24,6 +24,14 @@ Usage On the employee form view you will have 2 separate fields, one for Firstname, second for Lastname, both required. +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 ======= @@ -34,6 +42,7 @@ Contributors * Sandy Carter * Fekete Mihai * David Dufresne +* Adrien Peiffer (ACSONE) Maintainer ---------- diff --git a/hr_employee_firstname/__openerp__.py b/hr_employee_firstname/__openerp__.py index 09c011bd8a2..4209d6dfe12 100644 --- a/hr_employee_firstname/__openerp__.py +++ b/hr_employee_firstname/__openerp__.py @@ -22,7 +22,7 @@ { 'name': 'HR Employee First Name, Last Name', - 'version': '0.1', + 'version': '8.0.0.0.1', 'author': "Savoir-faire Linux, " "Fekete Mihai (Forest and Biomass Services Romania), " "Odoo Community Association (OCA)", @@ -33,6 +33,7 @@ 'summary': 'Adds First Name to Employee', 'depends': [ 'hr', + 'partner_firstname', ], 'data': [ 'views/hr_view.xml', diff --git a/hr_employee_firstname/i18n/en.po b/hr_employee_firstname/i18n/en.po new file mode 100644 index 00000000000..e049538b44d --- /dev/null +++ b/hr_employee_firstname/i18n/en.po @@ -0,0 +1,33 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_employee_firstname +# +# Translators: +msgid "" +msgstr "" +"Project-Id-Version: hr (8.0)\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-08-18 13:10+0000\n" +"PO-Revision-Date: 2015-08-13 14:31+0000\n" +"Last-Translator: OCA Transbot \n" +"Language-Team: English (http://www.transifex.com/oca/OCA-hr-8-0/language/en/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: en\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: hr_employee_firstname +#: model:ir.model,name:hr_employee_firstname.model_hr_employee +msgid "Employee" +msgstr "Employee" + +#. module: hr_employee_firstname +#: field:hr.employee,firstname:0 +msgid "Firstname" +msgstr "Firstname" + +#. module: hr_employee_firstname +#: field:hr.employee,lastname:0 +msgid "Lastname" +msgstr "Lastname" diff --git a/hr_employee_firstname/i18n/es.po b/hr_employee_firstname/i18n/es.po new file mode 100644 index 00000000000..ba248107472 --- /dev/null +++ b/hr_employee_firstname/i18n/es.po @@ -0,0 +1,33 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_employee_firstname +# +# Translators: +msgid "" +msgstr "" +"Project-Id-Version: hr (8.0)\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-08-18 13:10+0000\n" +"PO-Revision-Date: 2015-08-13 14:31+0000\n" +"Last-Translator: <>\n" +"Language-Team: Spanish (http://www.transifex.com/oca/OCA-hr-8-0/language/es/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: es\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: hr_employee_firstname +#: model:ir.model,name:hr_employee_firstname.model_hr_employee +msgid "Employee" +msgstr "Empleado" + +#. module: hr_employee_firstname +#: field:hr.employee,firstname:0 +msgid "Firstname" +msgstr "" + +#. module: hr_employee_firstname +#: field:hr.employee,lastname:0 +msgid "Lastname" +msgstr "" diff --git a/hr_employee_firstname/i18n/sl.po b/hr_employee_firstname/i18n/sl.po new file mode 100644 index 00000000000..122a067c389 --- /dev/null +++ b/hr_employee_firstname/i18n/sl.po @@ -0,0 +1,34 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_employee_firstname +# +# Translators: +# Matjaž Mozetič , 2015 +msgid "" +msgstr "" +"Project-Id-Version: hr (8.0)\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-08-18 13:10+0000\n" +"PO-Revision-Date: 2015-08-16 11:40+0000\n" +"Last-Translator: Matjaž Mozetič \n" +"Language-Team: Slovenian (http://www.transifex.com/oca/OCA-hr-8-0/language/sl/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: sl\n" +"Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3);\n" + +#. module: hr_employee_firstname +#: model:ir.model,name:hr_employee_firstname.model_hr_employee +msgid "Employee" +msgstr "Kader" + +#. module: hr_employee_firstname +#: field:hr.employee,firstname:0 +msgid "Firstname" +msgstr "Ime" + +#. module: hr_employee_firstname +#: field:hr.employee,lastname:0 +msgid "Lastname" +msgstr "Priimek" diff --git a/hr_employee_firstname/models/hr_employee.py b/hr_employee_firstname/models/hr_employee.py index e527c1562e9..40fd70e9c93 100644 --- a/hr_employee_firstname/models/hr_employee.py +++ b/hr_employee_firstname/models/hr_employee.py @@ -26,11 +26,10 @@ class HrEmployee(models.Model): _inherit = 'hr.employee' + @api.model def split_name(self, name): - new_name = [w for w in name.split(' ') if w] - firstname = new_name[0] - lastname = ' '.join(new_name[1:]) or ' ' - return firstname, lastname + clean_name = u" ".join(name.split(None)) if name else name + return self.env['res.partner']._get_inverse_name(clean_name) @api.cr_context def _auto_init(self, cr, context=None): @@ -43,47 +42,58 @@ def _update_employee_names(self): ('firstname', '=', ' '), ('lastname', '=', ' ')]) for ee in employees: - firstname, lastname = self.split_name(ee.name) + lastname, firstname = self.split_name(ee.name) ee.write({ 'firstname': firstname, 'lastname': lastname, }) + @api.model + def _update_partner_firstname(self, employee): + partners = employee.mapped('user_id.partner_id') + for partner in employee.mapped('address_home_id'): + if partner not in partners: + partners += partner + partners.write({'firstname': employee.firstname, + 'lastname': employee.lastname}) + + @api.model + def _get_name(self, lastname, firstname): + return self.env['res.partner']._get_computed_name(lastname, firstname) + @api.one @api.onchange('firstname', 'lastname') def get_name(self): if self.firstname and self.lastname: - self.name = ' '.join([self.firstname, self.lastname]) + self.name = self._get_name(self.lastname, self.firstname) def _firstname_default(self): return ' ' if self.env.context.get('module') else False firstname = fields.Char( - "Firstname", required=True, default=_firstname_default) + "Firstname", default=_firstname_default) lastname = fields.Char( "Lastname", required=True, default=_firstname_default) @api.model def create(self, vals): if vals.get('firstname') and vals.get('lastname'): - vals['name'] = ' '.join([vals['firstname'], vals['lastname']]) + vals['name'] = self._get_name(vals['lastname'], vals['firstname']) elif vals.get('name'): - vals['firstname'], vals['lastname'] = self.split_name(vals['name']) - - return super(HrEmployee, self).create(vals) + vals['lastname'], vals['firstname'] = self.split_name(vals['name']) + res = super(HrEmployee, self).create(vals) + self._update_partner_firstname(res) + return res @api.multi def write(self, vals): if vals.get('firstname') or vals.get('lastname'): - self.ensure_one() - - vals['name'] = ' '.join([ - vals.get('firstname') or self.firstname or ' ', - vals.get('lastname') or self.lastname or ' ', - ]) - + lastname = vals.get('lastname') or self.lastname or ' ' + firstname = vals.get('firstname') or self.firstname or ' ' + vals['name'] = self._get_name(lastname, firstname) elif vals.get('name'): - vals['firstname'], vals['lastname'] = self.split_name(vals['name']) - - return super(HrEmployee, self).write(vals) + vals['lastname'], vals['firstname'] = self.split_name(vals['name']) + res = super(HrEmployee, self).write(vals) + self._update_partner_firstname(self) + return res diff --git a/hr_employee_firstname/tests/test_hr_employee_firstname.py b/hr_employee_firstname/tests/test_hr_employee_firstname.py index e4334744fcf..0ce4a7f8bdf 100644 --- a/hr_employee_firstname/tests/test_hr_employee_firstname.py +++ b/hr_employee_firstname/tests/test_hr_employee_firstname.py @@ -30,7 +30,7 @@ def setUp(self): # Create 3 employees to concatenate the firstname and lastname # in name_related self.employee1_id = self.employee_model.create( - {'firstname': 'Jan', 'lastname': 'Van Eyck'}) + {'firstname': 'Jan', 'lastname': 'Van-Eyck'}) self.employee2_id = self.employee_model.create( {'firstname': 'Jean-Pierre', 'lastname': 'Carnaud'}) self.employee3_id = self.employee_model.create( @@ -39,11 +39,11 @@ def setUp(self): # Create 3 employees for split the name_related to # firstname and lastname self.employee10_id = self.employee_model.create( - {'name': ' Jan Van Eyck'}) + {'name': ' Van-Eyck Jan'}) self.employee20_id = self.employee_model.create( - {'name': 'Jean-Pierre Carnaud'}) + {'name': 'Carnaud Jean-Pierre'}) self.employee30_id = self.employee_model.create( - {'name': 'FamkeJenssens'}) + {'name': 'JenssensFamke'}) def test_get_name(self): """ @@ -51,13 +51,13 @@ def test_get_name(self): the firstname and lastname """ # Check for employee1 - self.assertEqual(self.employee1_id.name, 'Jan Van Eyck') + self.assertEqual(self.employee1_id.name, 'Van-Eyck Jan') # Check for employee2 - self.assertEqual(self.employee2_id.name, 'Jean-Pierre Carnaud') + self.assertEqual(self.employee2_id.name, 'Carnaud Jean-Pierre') # Check for employee3 - self.assertEqual(self.employee3_id.name, 'Famke Jenssens') + self.assertEqual(self.employee3_id.name, 'Jenssens Famke') def test_auto_init_name(self): """ @@ -66,41 +66,41 @@ def test_auto_init_name(self): """ # Check for employee10 self.assertEqual(self.employee10_id.firstname, "Jan") - self.assertEqual(self.employee10_id.lastname, 'Van Eyck') + self.assertEqual(self.employee10_id.lastname, 'Van-Eyck') # Check for employee20 self.assertEqual(self.employee20_id.firstname, 'Jean-Pierre') self.assertEqual(self.employee20_id.lastname, 'Carnaud') # Check for employee30 - self.assertEqual(self.employee30_id.firstname, 'FamkeJenssens') - self.assertEqual(self.employee30_id.lastname, ' ') + self.assertEqual(self.employee30_id.firstname, False) + self.assertEqual(self.employee30_id.lastname, 'JenssensFamke') def test_change_name(self): - self.employee1_id.write({'name': 'Jean-Pierre Carnaud Eyck'}) + self.employee1_id.write({'name': 'Carnaud-Eyck Jean-Pierre'}) self.employee1_id.refresh() self.assertEqual(self.employee1_id.firstname, 'Jean-Pierre') - self.assertEqual(self.employee1_id.lastname, 'Carnaud Eyck') + self.assertEqual(self.employee1_id.lastname, 'Carnaud-Eyck') def test_change_name_with_space(self): - self.employee1_id.write({'name': ' Jean-Pierre Carnaud Eyck'}) + self.employee1_id.write({'name': ' Carnaud-Eyck Jean-Pierre'}) self.employee1_id.refresh() self.assertEqual(self.employee1_id.firstname, 'Jean-Pierre') - self.assertEqual(self.employee1_id.lastname, 'Carnaud Eyck') + self.assertEqual(self.employee1_id.lastname, 'Carnaud-Eyck') def test_change_firstname(self): self.employee1_id.write({'firstname': 'Jean-Pierre'}) self.employee1_id.refresh() - self.assertEqual(self.employee1_id.name, 'Jean-Pierre Van Eyck') + self.assertEqual(self.employee1_id.name, 'Van-Eyck Jean-Pierre') def test_change_lastname(self): self.employee1_id.write({'lastname': 'Carnaud'}) self.employee1_id.refresh() - self.assertEqual(self.employee1_id.name, 'Jan Carnaud') + self.assertEqual(self.employee1_id.name, 'Carnaud Jan') def test_change_firstname_and_lastname(self): self.employee1_id.write({ @@ -108,4 +108,4 @@ def test_change_firstname_and_lastname(self): 'lastname': 'Carnaud'}) self.employee1_id.refresh() - self.assertEqual(self.employee1_id.name, 'Jean-Pierre Carnaud') + self.assertEqual(self.employee1_id.name, 'Carnaud Jean-Pierre') diff --git a/hr_employee_firstname/views/hr_view.xml b/hr_employee_firstname/views/hr_view.xml index 105296c6c70..16aa496fb0a 100644 --- a/hr_employee_firstname/views/hr_view.xml +++ b/hr_employee_firstname/views/hr_view.xml @@ -7,17 +7,17 @@