From 533a5e90f93cfd7fe3f60cb7b73eb90b1f3aae76 Mon Sep 17 00:00:00 2001 From: payen000 Date: Mon, 23 May 2022 22:55:34 +0000 Subject: [PATCH 1/2] [REF] partner_firstname,partner_second_lastname: Avoid _inverse_name when recalculating names The modification to action_recalculate_partners_name prevents the _inverse_name method from triggering when recalculating the names of partners, leaving the firstname, lastname and lastname2 fields intact. --- partner_firstname/models/base_config_settings.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/partner_firstname/models/base_config_settings.py b/partner_firstname/models/base_config_settings.py index 76c2f1f91..7f44c147b 100644 --- a/partner_firstname/models/base_config_settings.py +++ b/partner_firstname/models/base_config_settings.py @@ -62,7 +62,10 @@ class ResConfigSettings(models.TransientModel): ) partners = self._partners_for_recalculating() _logger.info("Recalculating names for %d partners.", len(partners)) - partners._compute_name() + # Use add_to_compute instead of _compute_name to avoid triggering + # _inverse_name_after_cleaning_whitespace, which can + # modify a partner's firstname, lastname and lastname2 + self.env.add_to_compute(self.env["res.partner"]._fields["name"], partners) self.partner_names_order_changed = False self.execute() _logger.info("%d partners updated.", len(partners)) From d9ecc5c15206f1b643281e2cce385c12cb050ab8 Mon Sep 17 00:00:00 2001 From: payen000 Date: Wed, 25 May 2022 01:16:36 +0000 Subject: [PATCH 2/2] [REF] partner_second_lastname: Added unittest related to name recalculation This unittest was added to ensure that, after pressing on 'Recalculate Names' button in 'partner_names_order' setting: 1 - firstname, lastname and lastname2 fields are not modified, and 2 - name field is computed correctly. --- partner_second_lastname/tests/test_name.py | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/partner_second_lastname/tests/test_name.py b/partner_second_lastname/tests/test_name.py index 9756ca868..054c8b56d 100644 --- a/partner_second_lastname/tests/test_name.py +++ b/partner_second_lastname/tests/test_name.py @@ -197,3 +197,33 @@ class UserCase(PersonCase, MailInstalled): # Skip if ``mail`` is installed if not self.mail_installed(): super(UserCase, self).tearDown() + + +class TestRecalculateNames(TransactionCase): + def setUp(self): + super().setUp() + self.config_settings = self.env["res.config.settings"].create({}) + + def test_recalculate_names(self): + firstname = "Xavier De Jesús" + lastname = "Payen" + lastname2 = "Sandoval" + correct_names = { + "first_last": f"{firstname} {lastname} {lastname2}", + "last_first": f"{lastname} {lastname2} {firstname}", + "last_first_comma": f"{lastname} {lastname2}, {firstname}", + } + partner = self.env["res.partner"].create( + { + "firstname": firstname, + "lastname": lastname, + "lastname2": lastname2, + } + ) + for order in correct_names: + self.config_settings.partner_names_order = order + self.config_settings.action_recalculate_partners_name() + self.assertEqual(partner.name, correct_names[order]) + self.assertEqual(partner.firstname, firstname) + self.assertEqual(partner.lastname, lastname) + self.assertEqual(partner.lastname2, lastname2)