summaryrefslogtreecommitdiff
path: root/addons/utm/models/utm.py
diff options
context:
space:
mode:
Diffstat (limited to 'addons/utm/models/utm.py')
-rw-r--r--addons/utm/models/utm.py99
1 files changed, 99 insertions, 0 deletions
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