diff options
| author | Thibault Delavallée <tde@odoo.com> | 2018-10-19 12:55:40 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2018-10-26 12:42:49 +0000 |
| commit | 65f9840fd2cb69ace065d50d2b9c6d2aebd703ef (patch) | |
| tree | 82a24e4ea5f27389a85800c4ac6fa04e9eecde96 /addons/utm/models/utm.py | |
| parent | d9c1cd42562a047107ccf474206105c47ab78edb (diff) | |
[MOV] utm: organize module structure according to guidelines
This module holds old code and is still not updated according to guidelines.
Let us update a bit the naming in this module to have readable code.
This commit is linked to task ID 1896681 and PR #27975. No functional change
should occur with this commit as it contains only renaming / move.
Diffstat (limited to 'addons/utm/models/utm.py')
| -rw-r--r-- | addons/utm/models/utm.py | 58 |
1 files changed, 1 insertions, 57 deletions
diff --git a/addons/utm/models/utm.py b/addons/utm/models/utm.py index 0627177ffd2..41efca78cf5 100644 --- a/addons/utm/models/utm.py +++ b/addons/utm/models/utm.py @@ -1,9 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import api, fields, models, SUPERUSER_ID -from odoo.http import request -from odoo.tools import pycompat +from odoo import fields, models class UtmMedium(models.Model): @@ -29,57 +27,3 @@ class UtmSource(models.Model): _description = 'UTM Source' name = fields.Char(string='Source Name', required=True, translate=True) - - -class UtmMixin(models.AbstractModel): - - """Mixin class for objects which can be tracked by marketing. """ - _name = 'utm.mixin' - _description = 'UTM Mixin' - - campaign_id = fields.Many2one('utm.campaign', 'Campaign', - help="This is a name that helps you keep track of your different campaign efforts, e.g. Fall_Drive, Christmas_Special") - source_id = fields.Many2one('utm.source', 'Source', - help="This is the source of the link, e.g. Search Engine, another domain, or name of email list") - medium_id = fields.Many2one('utm.medium', 'Medium', - help="This is the method of delivery, e.g. Postcard, Email, or Banner Ad", oldname='channel_id') - - def tracking_fields(self): - # This function cannot be overridden in a model which inherit utm.mixin - # Limitation by the heritage on AbstractModel - # record_crm_lead.tracking_fields() will call tracking_fields() from module utm.mixin (if not overridden on crm.lead) - # instead of the overridden method from utm.mixin. - # To force the call of overridden method, we use self.env['utm.mixin'].tracking_fields() which respects overridden - # methods of utm.mixin, but will ignore overridden method on crm.lead - return [ - # ("URL_PARAMETER", "FIELD_NAME_MIXIN", "NAME_IN_COOKIES") - ('utm_campaign', 'campaign_id', 'odoo_utm_campaign'), - ('utm_source', 'source_id', 'odoo_utm_source'), - ('utm_medium', 'medium_id', 'odoo_utm_medium'), - ] - - @api.model - def default_get(self, fields): - values = super(UtmMixin, self).default_get(fields) - - # We ignore UTM for salemen, except some requests that could be done as superuser_id to bypass access rights. - if self.env.uid != SUPERUSER_ID and self.env.user.has_group('sales_team.group_sale_salesman'): - return values - - for url_param, field_name, cookie_name in self.env['utm.mixin'].tracking_fields(): - if field_name in fields: - field = self._fields[field_name] - value = False - if request: - # ir_http dispatch saves the url params in a cookie - value = request.httprequest.cookies.get(cookie_name) - # if we receive a string for a many2one, we search/create the id - if field.type == 'many2one' and isinstance(value, pycompat.string_types) and value: - Model = self.env[field.comodel_name] - records = Model.search([('name', '=', value)], limit=1) - if not records: - records = Model.create({'name': value}) - value = records.id - if value: - values[field_name] = value - return values |
