diff --git a/addons/utm/models/utm_campaign.py b/addons/utm/models/utm_campaign.py index ecf5f77a73f..924a67a3214 100644 --- a/addons/utm/models/utm_campaign.py +++ b/addons/utm/models/utm_campaign.py @@ -9,6 +9,7 @@ class UtmCampaign(models.Model): _description = 'UTM Campaign' _rec_name = 'title' + active = fields.Boolean('Active', default=True) name = fields.Char(string='Campaign Identifier', required=True, compute='_compute_name', store=True, readonly=False, precompute=True, translate=False) title = fields.Char(string='Campaign Name', required=True, translate=True) diff --git a/addons/utm/models/utm_mixin.py b/addons/utm/models/utm_mixin.py index 515c244826c..afb4b78b975 100644 --- a/addons/utm/models/utm_mixin.py +++ b/addons/utm/models/utm_mixin.py @@ -62,7 +62,7 @@ class UtmMixin(models.AbstractModel): """Based on the model name and on the name of the record, retrieve the corresponding record or create it.""" Model = self.env[model_name] - record = Model.search([('name', '=', name)], limit=1) + record = Model.with_context(active_test=False).search([('name', '=', name)], limit=1) if not record: # No record found, create a new one diff --git a/addons/utm/tests/test_utm.py b/addons/utm/tests/test_utm.py index 5a05724061c..133490489d0 100644 --- a/addons/utm/tests/test_utm.py +++ b/addons/utm/tests/test_utm.py @@ -21,6 +21,14 @@ class TestUtm(TestUTMCommon): self.assertNotIn(source_4, source_1 | source_2) self.assertEqual(source_4.name, 'Source 3') + def test_find_or_create_with_archived_record(self): + archived_campaign = self.env['utm.campaign'].create([{ + 'active': False, + 'name': 'Archived Campaign', + }]) + campaign = self.env['utm.mixin']._find_or_create_record('utm.campaign', 'Archived Campaign') + self.assertEqual(archived_campaign, campaign, "An archived record must be found instead of re-created.") + def test_name_generation(self): """Test that the name is always unique. diff --git a/addons/utm/views/utm_campaign_views.xml b/addons/utm/views/utm_campaign_views.xml index b86561ed3f4..cb34c83235e 100644 --- a/addons/utm/views/utm_campaign_views.xml +++ b/addons/utm/views/utm_campaign_views.xml @@ -9,6 +9,7 @@ + @@ -30,7 +31,9 @@
+ + @@ -81,6 +84,7 @@ + @@ -89,6 +93,10 @@ Delete + + Archive + Restore +