From 9e071ac34caf810dc10c205a0b438fd63c33f0ca Mon Sep 17 00:00:00 2001 From: Adrien Schoffeniels Date: Thu, 12 Jan 2023 08:27:46 +0000 Subject: [PATCH] [FIX] utm, *: allow quick creation of campaigns MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Purpose: ======== Since the introduction of the required "title" field in the utm_campaign model in commit [1], quick creation of campaigns from many2ones is not possible anymore (the slow creation modal is opened when clicking on "Create"), and the name value entered is not copied into the name field of the creation form. This is because the model now has a field "name", and a field "title", which are both required. The creation using the many2one widget tries to create a record using the entered value as title and no name, which fails. It fails because the create method replaces this empty name by a False value, since it could not generate a unique name given no name. This commit makes sure that if a title but no name is given when creating a new campaign record, one does not set the name value to False anymore. It also makes sure that the value entered before clicking on the "create and edit" button is copied in the form, by adding the "create_name_field" option on the many2one fields (the form uses the title field, not the name). The "always_reload" option has also been added because without it, the many2one shows the name of the created record instead of showing the title. [1]: https://github.com/odoo/odoo/commit/4dbcefb5e5b1878e81fe9be9fe48a785f813334f Task-3113954 closes odoo/odoo#110474 X-original-commit: 869208cd09b6ceb5dcda55b6fe4131d7cc8d43e8 Signed-off-by: Warnon Aurélien (awa) --- addons/crm/views/crm_lead_views.xml | 4 ++-- addons/link_tracker/views/link_tracker_views.xml | 2 +- addons/mass_mailing/views/mailing_mailing_views.xml | 1 + addons/sale/views/account_views.xml | 2 +- addons/sale/views/sale_order_views.xml | 2 +- addons/utm/models/utm_campaign.py | 3 ++- addons/utm/tests/test_utm.py | 4 ++++ 7 files changed, 12 insertions(+), 6 deletions(-) diff --git a/addons/crm/views/crm_lead_views.xml b/addons/crm/views/crm_lead_views.xml index 8b8c5730bab..c04283a08a9 100644 --- a/addons/crm/views/crm_lead_views.xml +++ b/addons/crm/views/crm_lead_views.xml @@ -273,7 +273,7 @@ - + @@ -319,7 +319,7 @@ - + diff --git a/addons/link_tracker/views/link_tracker_views.xml b/addons/link_tracker/views/link_tracker_views.xml index 0270b003e99..b4e338c3ef4 100644 --- a/addons/link_tracker/views/link_tracker_views.xml +++ b/addons/link_tracker/views/link_tracker_views.xml @@ -44,7 +44,7 @@ - + diff --git a/addons/mass_mailing/views/mailing_mailing_views.xml b/addons/mass_mailing/views/mailing_mailing_views.xml index d59996437e3..893e7ea77cd 100644 --- a/addons/mass_mailing/views/mailing_mailing_views.xml +++ b/addons/mass_mailing/views/mailing_mailing_views.xml @@ -341,6 +341,7 @@ - + diff --git a/addons/sale/views/sale_order_views.xml b/addons/sale/views/sale_order_views.xml index c518ab929c4..865b5ec2c46 100644 --- a/addons/sale/views/sale_order_views.xml +++ b/addons/sale/views/sale_order_views.xml @@ -644,7 +644,7 @@ - + diff --git a/addons/utm/models/utm_campaign.py b/addons/utm/models/utm_campaign.py index b4548ba4844..ecf5f77a73f 100644 --- a/addons/utm/models/utm_campaign.py +++ b/addons/utm/models/utm_campaign.py @@ -44,7 +44,8 @@ class UtmCampaign(models.Model): vals['title'] = vals['name'] new_names = self.env['utm.mixin']._get_unique_names(self._name, [vals.get('name') for vals in vals_list]) for vals, new_name in zip(vals_list, new_names): - vals['name'] = new_name + if new_name: + vals['name'] = new_name return super().create(vals_list) @api.model diff --git a/addons/utm/tests/test_utm.py b/addons/utm/tests/test_utm.py index 71d9c5505e9..5a05724061c 100644 --- a/addons/utm/tests/test_utm.py +++ b/addons/utm/tests/test_utm.py @@ -61,3 +61,7 @@ class TestUtm(TestUTMCommon): utm_8 = utm_7.copy() self.assertEqual(utm_8.name, 'UTM d [2]', msg='Must add a counter as suffix to ensure uniqueness') + + # Test name uniqueness when creating a campaign using a title (quick creation) + utm_9 = self.env['utm.campaign'].create({'title': 'UTM dup'}) + self.assertEqual(utm_9.name, 'UTM dup [6]', msg='Even if the record has been created using a title, the name must be unique')