[MIG] utm:Migrated into new api.
This commit is contained in:
committed by
Thibault Delavallée
parent
2a13a6358a
commit
8913853377
@@ -1,6 +1,5 @@
|
||||
<?xml version="1.0"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<!-- UTM Campain -->
|
||||
<record model="utm.campaign" id="utm_campaign_fall_drive">
|
||||
<field name="name">Sale</field>
|
||||
@@ -60,5 +59,4 @@
|
||||
<record model="utm.medium" id="utm_medium_google_adwords">
|
||||
<field name="name">Google Adwords</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
</odoo>
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from openerp.http import request
|
||||
from openerp.osv import orm
|
||||
from odoo.http import request
|
||||
from odoo import models
|
||||
|
||||
|
||||
class ir_http(orm.AbstractModel):
|
||||
class IrHttp(models.AbstractModel):
|
||||
_inherit = 'ir.http'
|
||||
|
||||
def get_utm_domain_cookies(self):
|
||||
return request.httprequest.host
|
||||
|
||||
def _dispatch(self):
|
||||
response = super(ir_http, self)._dispatch()
|
||||
response = super(IrHttp, self)._dispatch()
|
||||
for var, dummy, cook in self.pool['utm.mixin'].tracking_fields():
|
||||
if var in request.params and request.httprequest.cookies.get(var) != request.params[var]:
|
||||
response.set_cookie(cook, request.params[var], domain=self.get_utm_domain_cookies())
|
||||
|
||||
+46
-60
@@ -1,86 +1,72 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from openerp.osv import osv, fields
|
||||
from openerp.http import request
|
||||
from odoo import api, fields, models
|
||||
from odoo.http import request
|
||||
|
||||
|
||||
class utm_medium(osv.Model):
|
||||
class UtmMedium(models.Model):
|
||||
# OLD crm.case.channel
|
||||
_name = "utm.medium"
|
||||
_description = "Channels"
|
||||
_name = 'utm.medium'
|
||||
_description = 'Channels'
|
||||
_order = 'name'
|
||||
_columns = {
|
||||
'name': fields.char('Channel Name', required=True),
|
||||
'active': fields.boolean('Active'),
|
||||
}
|
||||
_defaults = {
|
||||
'active': lambda *a: 1,
|
||||
}
|
||||
|
||||
name = fields.Char(string='Channel Name', required=True)
|
||||
active = fields.Boolean(default=True)
|
||||
|
||||
|
||||
class utm_campaign(osv.Model):
|
||||
class UtmCampaign(models.Model):
|
||||
# OLD crm.case.resource.type
|
||||
_name = "utm.campaign"
|
||||
_description = "Campaign"
|
||||
_rec_name = "name"
|
||||
_columns = {
|
||||
'name': fields.char('Campaign Name', required=True, translate=True),
|
||||
}
|
||||
_name = 'utm.campaign'
|
||||
_description = 'Campaign'
|
||||
|
||||
name = fields.Char(string='Campaign Name', required=True, translate=True)
|
||||
|
||||
|
||||
class utm_source(osv.Model):
|
||||
_name = "utm.source"
|
||||
_description = "Source"
|
||||
_rec_name = "name"
|
||||
_columns = {
|
||||
'name': fields.char('Source Name', required=True, translate=True),
|
||||
}
|
||||
class UtmSource(models.Model):
|
||||
_name = 'utm.source'
|
||||
_description = 'Source'
|
||||
|
||||
name = fields.Char(string='Source Name', required=True, translate=True)
|
||||
|
||||
|
||||
class utm_mixin(osv.AbstractModel):
|
||||
class UtmMixin(models.AbstractModel):
|
||||
|
||||
"""Mixin class for objects which can be tracked by marketing. """
|
||||
_name = 'utm.mixin'
|
||||
|
||||
_columns = {
|
||||
'campaign_id': fields.many2one('utm.campaign', 'Campaign', # old domain ="['|',('team_id','=',team_id),('team_id','=',False)]"
|
||||
help="This is a name that helps you keep track of your different campaign efforts Ex: Fall_Drive, Christmas_Special"),
|
||||
'source_id': fields.many2one('utm.source', 'Source', help="This is the source of the link Ex: Search Engine, another domain, or name of email list"),
|
||||
'medium_id': fields.many2one('utm.medium', 'Medium', help="This is the method of delivery. Ex: Postcard, Email, or Banner Ad", oldname='channel_id'),
|
||||
}
|
||||
campaign_id = fields.Many2one('utm.campaign', 'Campaign',
|
||||
help="This is a name that helps you keep track of your different campaign efforts Ex: Fall_Drive, Christmas_Special")
|
||||
source_id = fields.Many2one('utm.source', 'Source',
|
||||
help="This is the source of the link Ex:Search Engine, another domain,or name of email list")
|
||||
medium_id = fields.Many2one('utm.medium', 'Medium',
|
||||
help="This is the method of delivery.Ex: Postcard, Email, or Banner Ad", oldname='channel_id')
|
||||
|
||||
def tracking_fields(self):
|
||||
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')
|
||||
('utm_medium', 'medium_id', 'odoo_utm_medium'),
|
||||
]
|
||||
|
||||
def tracking_get_values(self, cr, uid, vals, context=None):
|
||||
for key, fname, cook in self.tracking_fields():
|
||||
field = self._fields[fname]
|
||||
value = vals.get(fname) or (request and request.httprequest.cookies.get(cook)) # params.get should be always in session by the dispatch from ir_http
|
||||
if field.type == 'many2one' and isinstance(value, basestring):
|
||||
@api.model
|
||||
def default_get(self, fields):
|
||||
values = super(UtmMixin, self).default_get(fields)
|
||||
|
||||
for url_param, field_name, cookie_name in self.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 value:
|
||||
Model = self.pool[field.comodel_name]
|
||||
rel_id = Model.name_search(cr, uid, value, context=context)
|
||||
if rel_id:
|
||||
rel_id = rel_id[0][0]
|
||||
else:
|
||||
rel_id = Model.create(cr, uid, {'name': value}, context=context)
|
||||
vals[fname] = rel_id
|
||||
else:
|
||||
# Here the code for others cases that many2one
|
||||
vals[fname] = value
|
||||
return vals
|
||||
|
||||
def _get_default_track(self, cr, uid, field, context=None):
|
||||
return self.tracking_get_values(cr, uid, {}, context=context).get(field)
|
||||
|
||||
_defaults = {
|
||||
'source_id': lambda self, cr, uid, ctx: self._get_default_track(cr, uid, 'source_id', ctx),
|
||||
'campaign_id': lambda self, cr, uid, ctx: self._get_default_track(cr, uid, 'campaign_id', ctx),
|
||||
'medium_id': lambda self, cr, uid, ctx: self._get_default_track(cr, uid, 'medium_id', ctx),
|
||||
}
|
||||
if field.type == 'many2one' and isinstance(value, basestring) 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
|
||||
values[field_name] = value
|
||||
return values
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<odoo>
|
||||
<menuitem id="menu_link_tracker_root" name="Link Tracker" groups="base.group_no_one" sequence="30"/>
|
||||
<menuitem name="UTMs" id="marketing_utm" groups="base.group_configuration" parent="menu_link_tracker_root" sequence="99"/>
|
||||
|
||||
@@ -108,5 +107,4 @@
|
||||
</record>
|
||||
|
||||
<menuitem action="utm_source_action" id="menu_utm_source" parent="marketing_utm" sequence="4" groups="base.group_no_one"/>
|
||||
</data>
|
||||
</openerp>
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user