[IMP] utm: allow archiving campaigns

Allow archiving campaigns from the form and kanban views.
Add the "Archived" filter.

Task-3240966

Part-of: odoo/odoo#116230
This commit is contained in:
amdi-odoo
2023-04-19 11:00:59 +02:00
parent 6540944fb4
commit 7f6c66bd5e
4 changed files with 18 additions and 1 deletions
+1
View File
@@ -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)
+1 -1
View File
@@ -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
+8
View File
@@ -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.
+8
View File
@@ -9,6 +9,7 @@
<field name="tag_ids"/>
<field name="user_id"/>
<field name="is_auto_campaign"/>
<filter string="Archived" name="filter_inactive" domain="[('active', '=', False)]"/>
<group expand="0" string="Group By">
<filter string="Stage" name="group_stage_id"
context="{'group_by': 'stage_id'}"/>
@@ -30,7 +31,9 @@
<sheet>
<div class="oe_button_box d-flex justify-content-end" name="button_box">
</div>
<widget name="web_ribbon" title="Archived" bg_color="bg-danger" attrs="{'invisible': [('active', '=', True)]}"/>
<group id="top-group">
<field name="active" invisible="1"/>
<field class="text-break" name="title" string="Campaign Name" placeholder="e.g. Black Friday"/>
<field name="name" invisible="1"/>
<field name="user_id" widget="many2one_avatar_user" domain="[('share', '=', False)]"/>
@@ -81,6 +84,7 @@
<field name='color'/>
<field name='user_id'/>
<field name="stage_id"/>
<field name='active'/>
<templates>
<t t-name="kanban-menu">
<t t-if="widget.editable">
@@ -89,6 +93,10 @@
<t t-if="widget.deletable">
<a role="menuitem" type="delete" class="dropdown-item">Delete</a>
</t>
<a role="menuitem" class="dropdown-item o_kanban_mailing_active" name="toggle_active" type="object">
<t t-if="record.active.raw_value">Archive</t>
<t t-else="">Restore</t>
</a>
<div role="separator" class="dropdown-divider"/>
<ul class="oe_kanban_colorpicker" data-field="color"/>
</t>