Server IP : 127.0.0.2 / Your IP : 3.17.156.98 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /opt/odoo/addons/utm/models/ |
Upload File : |
# -*- 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 class UtmMedium(models.Model): # OLD crm.case.channel _name = 'utm.medium' _description = 'Channels' _order = 'name' name = fields.Char(string='Channel Name', required=True) active = fields.Boolean(default=True) class UtmCampaign(models.Model): # OLD crm.case.resource.type _name = 'utm.campaign' _description = 'Campaign' name = fields.Char(string='Campaign 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 UtmMixin(models.AbstractModel): """Mixin class for objects which can be tracked by marketing. """ _name = 'utm.mixin' 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): # 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, 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