summaryrefslogtreecommitdiff
path: root/addons/utm/models
diff options
context:
space:
mode:
authorJulien De Coster <jdc@odoo.com>2014-08-12 14:54:26 +0530
committerJulien De Coster <jdc@odoo.com>2014-12-17 17:14:33 +0100
commitddac26cdbb3535239f5dbb41f5b464366065f3ba (patch)
treeb54e4d34060f1c7f80a8c6404f7f4fd56d914e52 /addons/utm/models
parent7f97bf4ec07329e58c818632bf23017b390bb099 (diff)
[ADD] Add the website_links module.
This module tracks clicks in mass mailing mails and allow the generation of trackable links in a website interface. Modules modifications --------------------- Refractoring of the crm_tracking_* classes in a new module. * Extract the crm_tracking_* from the crm module into a new module "utm" * Remove the crm_mass_mailing bridge module * New dependencies of mass_mailing and website_links to utm.
Diffstat (limited to 'addons/utm/models')
-rw-r--r--addons/utm/models/__init__.py2
-rw-r--r--addons/utm/models/utm.py99
2 files changed, 101 insertions, 0 deletions
diff --git a/addons/utm/models/__init__.py b/addons/utm/models/__init__.py
new file mode 100644
index 00000000000..2ee8f89fad8
--- /dev/null
+++ b/addons/utm/models/__init__.py
@@ -0,0 +1,2 @@
+# -*- coding: utf-8 -*-
+import utm \ No newline at end of file
diff --git a/addons/utm/models/utm.py b/addons/utm/models/utm.py
new file mode 100644
index 00000000000..4f4d905795d
--- /dev/null
+++ b/addons/utm/models/utm.py
@@ -0,0 +1,99 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-today Odoo SA (<http://www.odoo.com>)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+from openerp.osv import osv, fields
+from openerp.http import request
+
+
+class utm_medium(osv.Model):
+ # OLD crm.case.channel
+ _name = "utm.medium"
+ _description = "Channels"
+ _order = 'name'
+ _columns = {
+ 'name': fields.char('Channel Name', required=True),
+ 'active': fields.boolean('Active'),
+ }
+ _defaults = {
+ 'active': lambda *a: 1,
+ }
+
+
+class utm_campaign(osv.Model):
+ # OLD crm.case.resource.type
+ _name = "utm.campaign"
+ _description = "Campaign"
+ _rec_name = "name"
+ _columns = {
+ 'name': fields.char('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 utm_mixin(osv.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'),
+ }
+
+ def tracking_fields(self):
+ return [('utm_campaign', 'campaign_id'), ('utm_source', 'source_id'), ('utm_medium', 'medium_id')]
+
+ def tracking_get_values(self, cr, uid, vals, context=None):
+ for key, fname in self.tracking_fields():
+ field = self._fields[fname]
+ value = vals.get(fname) or (request and request.httprequest.cookies.get(key)) # params.get should be always in session by the dispatch from ir_http
+ if field.type == 'many2one' and isinstance(value, basestring):
+ # 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),
+ } \ No newline at end of file