From d410657e609bca037faff42199ba8296f46b4002 Mon Sep 17 00:00:00 2001 From: Simone Rubino Date: Mon, 22 Apr 2024 10:30:43 +0200 Subject: [PATCH] [FIX] partner_firstname: Multiple creation with "name" Otherwise the following is raised > odoo.addons.partner_firstname.exceptions.EmptyNamesError: ("Error(s) with partner 1425's name.", 'No name is set.') --- partner_firstname/README.rst | 122 +++++++++--------- partner_firstname/models/res_partner.py | 3 +- partner_firstname/readme/CONTRIBUTORS.md | 2 + .../static/description/index.html | 5 + partner_firstname/tests/test_name.py | 29 +++++ 5 files changed, 98 insertions(+), 63 deletions(-) diff --git a/partner_firstname/README.rst b/partner_firstname/README.rst index 14dda2d9fb1..88616f20c8f 100644 --- a/partner_firstname/README.rst +++ b/partner_firstname/README.rst @@ -7,7 +7,7 @@ Partner first name and last name !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:547c95a6de4508c96e86e379cfb2d96346381f4b965614d586b2cd48a0eed9b9 + !! source digest: sha256:3488c0565691627a30d74647ddd160cead71719973fc68d77008bbb91af2445f !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png @@ -17,19 +17,19 @@ Partner first name and last name :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpartner--contact-lightgray.png?logo=github - :target: https://github.com/OCA/partner-contact/tree/17.0/partner_firstname + :target: https://github.com/OCA/partner-contact/tree/16.0/partner_firstname :alt: OCA/partner-contact .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/partner-contact-17-0/partner-contact-17-0-partner_firstname + :target: https://translation.odoo-community.org/projects/partner-contact-16-0/partner-contact-16-0-partner_firstname :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png - :target: https://runboat.odoo-community.org/builds?repo=OCA/partner-contact&target_branch=17.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/partner-contact&target_branch=16.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| -This module was written to extend the functionality of contacts to -support having separate last name and first name. +This module was written to extend the functionality of contacts to support +having separate last name and first name. **Table of contents** @@ -39,49 +39,44 @@ support having separate last name and first name. Configuration ============= -You can configure some common name patterns for the inverse function in -Settings > General settings: +You can configure some common name patterns for the inverse function +in Settings > General settings: -- Lastname Firstname: For example 'Anderson Robert' -- Lastname, Firstname: For example 'Anderson, Robert' -- Firstname Lastname: For example 'Robert Anderson' +* Lastname Firstname: For example 'Anderson Robert' +* Lastname, Firstname: For example 'Anderson, Robert' +* Firstname Lastname: For example 'Robert Anderson' -After applying the changes, you can recalculate all partners name -clicking "Recalculate names" button. Note: This process could take so -much time depending how many partners there are in database. +After applying the changes, you can recalculate all partners name clicking +"Recalculate names" button. Note: This process could take so much time depending +how many partners there are in database. -You can use *\_get_inverse_name* method to get lastname and firstname -from a simple string and also *\_get_computed_name* to get a name form -the lastname and firstname. These methods can be overridden to change -the format specified above. +You can use *_get_inverse_name* method to get lastname and firstname from a simple string +and also *_get_computed_name* to get a name form the lastname and firstname. +These methods can be overridden to change the format specified above. Usage ===== -The field *name* becomes a stored function field concatenating the *last -name* and the *first name*. This avoids breaking compatibility with -other modules. +The field *name* becomes a stored function field concatenating the *last name* +and the *first name*. This avoids breaking compatibility with other modules. -Users should fulfill manually the separate fields for *last name* and -*first name*, but in case you edit just the *name* field in some -unexpected module, there is an inverse function that tries to split that -automatically. It assumes that you write the *name* in format configured -(*"Lastname Firstname"*, by default), but it could lead to wrong -splitting (because it's just blindly trying to guess what you meant), so -you better specify it manually. +Users should fulfill manually the separate fields for *last name* and *first +name*, but in case you edit just the *name* field in some unexpected module, +there is an inverse function that tries to split that automatically. It assumes +that you write the *name* in format configured (*"Lastname Firstname"*, by default), +but it could lead to wrong splitting (because it's just blindly trying to +guess what you meant), so you better specify it manually. -For the same reason, after installing, previous names for contacts will -stay in the *name* field, and the first time you edit any of them you -will be asked to supply the *last name* and *first name* (just once per -contact). +For the same reason, after installing, previous names for contacts will stay in +the *name* field, and the first time you edit any of them you will be asked to +supply the *last name* and *first name* (just once per contact). Known issues / Roadmap ====================== -Patterns for the inverse function are configurable only at system level. -Maybe this configuration could depend on partner language, country or -company, as discussed at `this OCA -issue `__ +Patterns for the inverse function are configurable only at system level. Maybe +this configuration could depend on partner language, country or company, +as discussed at `this OCA issue `_ Bug Tracker =========== @@ -89,7 +84,7 @@ 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 to smash it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -97,7 +92,7 @@ Credits ======= Authors -------- +~~~~~~~ * Camptocamp * Grupo ESOC IngenierĂ­a de Servicios @@ -107,31 +102,34 @@ Authors * DynApps NV 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 -- Dave Lasley -- Graeme Gellatly -- Laurent Mignon -- Bjorn Billen +~~~~~~~~~~~~ + +* 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 +* Dave Lasley +* Graeme Gellatly +* Laurent Mignon +* Bjorn Billen +* `Aion Tech `_: + + * Simone Rubino Maintainers ------------ +~~~~~~~~~~~ This module is maintained by the OCA. @@ -143,6 +141,6 @@ 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. -This module is part of the `OCA/partner-contact `_ project on GitHub. +This module is part of the `OCA/partner-contact `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/partner_firstname/models/res_partner.py b/partner_firstname/models/res_partner.py index 73dc29c4edd..67824a23ce2 100644 --- a/partner_firstname/models/res_partner.py +++ b/partner_firstname/models/res_partner.py @@ -1,6 +1,7 @@ # Copyright 2013 Nicolas Bessi (Camptocamp SA) # Copyright 2014 Agile Business Group () # Copyright 2015 Grupo ESOC () +# Copyright 2024 Simone Rubino - Aion Tech # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import logging @@ -73,7 +74,7 @@ def create(self, vals_list): # pylint: disable=W8121 created_partners |= super( ResPartner, self.with_context(partner_context) - ).create(vals_list) + ).create([vals]) return created_partners def get_extra_default_copy_values(self, order): diff --git a/partner_firstname/readme/CONTRIBUTORS.md b/partner_firstname/readme/CONTRIBUTORS.md index 7319ca55dde..b944b370823 100644 --- a/partner_firstname/readme/CONTRIBUTORS.md +++ b/partner_firstname/readme/CONTRIBUTORS.md @@ -18,3 +18,5 @@ - Graeme Gellatly \<\> - Laurent Mignon \<\> - Bjorn Billen \<\> +- Aion Tech \<\>: + - Simone Rubino \<\> diff --git a/partner_firstname/static/description/index.html b/partner_firstname/static/description/index.html index 72d6ad8de96..70056ad162d 100644 --- a/partner_firstname/static/description/index.html +++ b/partner_firstname/static/description/index.html @@ -1,3 +1,4 @@ + @@ -471,6 +472,10 @@

Contributors

  • Graeme Gellatly <graeme@o4sb.com>
  • Laurent Mignon <laurent.mignon@acsone.eu>
  • Bjorn Billen <bjorn.billen@dynapps.be>
  • +
  • Aion Tech: +
  • diff --git a/partner_firstname/tests/test_name.py b/partner_firstname/tests/test_name.py index 4b55d5626a8..6a1389182ca 100644 --- a/partner_firstname/tests/test_name.py +++ b/partner_firstname/tests/test_name.py @@ -23,6 +23,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# Copyright 2024 Simone Rubino - Aion Tech +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + """Test naming logic. To have more accurate results, remove the ``mail`` module before testing. @@ -50,6 +53,32 @@ def test_whitespace_cleanup(self): # Need this to refresh the ``name`` field self.original.invalidate_recordset(["name"]) + def test_multiple_name_creation(self): + """Create multiple partners at once, only with "name".""" + partners = self.env["res.partner"].create( + [ + { + "name": "Test partner1", + }, + { + "name": "Test partner2", + }, + ] + ) + self.assertRecordValues( + partners, + [ + { + "firstname": "Test", + "lastname": "partner1", + }, + { + "firstname": "Test", + "lastname": "partner2", + }, + ], + ) + class PartnerCompanyCase(BaseCase): def create_original(self):