예제 #1
0
 def init(self):
     """Mass Mail Statistical Report: based on mail.mail.statistics that models the various
     statistics collected for each mailing, and mail.mass_mailing model that models the
     various mailing performed. """
     tools.drop_view_if_exists(self.env.cr, 'mail_statistics_report')
     self.env.cr.execute("""
         CREATE OR REPLACE VIEW mail_statistics_report AS (
             SELECT
                 min(ms.id) as id,
                 ms.scheduled as scheduled_date,
                 utm_source.name as name,
                 utm_campaign.name as campaign,
                 count(ms.bounced) as bounced,
                 count(ms.sent) as sent,
                 (count(ms.sent) - count(ms.bounced)) as delivered,
                 count(ms.opened) as opened,
                 count(ms.replied) as replied,
                 mm.state,
                 mm.email_from
             FROM
                 mail_mail_statistics as ms
                 left join mail_mass_mailing as mm ON (ms.mass_mailing_id=mm.id)
                 left join mail_mass_mailing_campaign as mc ON (ms.mass_mailing_campaign_id=mc.id)
                 left join utm_campaign as utm_campaign ON (mc.campaign_id = utm_campaign.id)
                 left join utm_source as utm_source ON (mm.source_id = utm_source.id)
             GROUP BY ms.scheduled, utm_source.name, utm_campaign.name, mm.state, mm.email_from
         )""")
예제 #2
0
 def init(self):
     """
         CRM Lead Report
         @param cr: the current row, from the database cursor
     """
     tools.drop_view_if_exists(self._cr, 'crm_partner_report_assign')
     self._cr.execute("""
         CREATE OR REPLACE VIEW crm_partner_report_assign AS (
             SELECT
                 coalesce(i.id, p.id - 1000000000) as id,
                 p.id as partner_id,
                 (SELECT country_id FROM res_partner a WHERE a.parent_id=p.id AND country_id is not null limit 1) as country_id,
                 p.grade_id,
                 p.activation,
                 p.date_review,
                 p.date_partnership,
                 p.user_id,
                 p.team_id,
                 (SELECT count(id) FROM crm_lead WHERE partner_assigned_id=p.id) AS nbr_opportunities,
                 i.price_total as turnover,
                 i.date
             FROM
                 res_partner p
                 left join account_invoice_report i
                     on (i.partner_id=p.id and i.type in ('out_invoice','out_refund') and i.state in ('open','paid'))
         )""")
예제 #3
0
 def init(self):
     # Note : start_date_hour must be remove when the read_group will allow grouping on the hour of a datetime. Don't forget to change the view !
     tools.drop_view_if_exists(self.env.cr, 'im_livechat_report_channel')
     self.env.cr.execute("""
         CREATE OR REPLACE VIEW im_livechat_report_channel AS (
             SELECT
                 C.id as id,
                 C.uuid as uuid,
                 C.id as channel_id,
                 C.name as channel_name,
                 CONCAT(L.name, ' / ', C.id) as technical_name,
                 C.livechat_channel_id as livechat_channel_id,
                 C.create_date as start_date,
                 to_char(date_trunc('hour', C.create_date), 'YYYY-MM-DD HH24:MI:SS') as start_date_hour,
                 EXTRACT('epoch' FROM (max((SELECT (max(M.create_date)) FROM mail_message M JOIN mail_message_mail_channel_rel R ON (R.mail_message_id = M.id) WHERE R.mail_channel_id = C.id))-C.create_date)) as duration,
                 count(distinct P.id) as nbr_speaker,
                 count(distinct M.id) as nbr_message,
                 MAX(S.partner_id) as partner_id
             FROM mail_channel C
                 JOIN mail_message_mail_channel_rel R ON (C.id = R.mail_channel_id)
                 JOIN mail_message M ON (M.id = R.mail_message_id)
                 JOIN mail_channel_partner S ON (S.channel_id = C.id)
                 JOIN im_livechat_channel L ON (L.id = C.livechat_channel_id)
                 LEFT JOIN res_partner P ON (M.author_id = P.id)
             GROUP BY C.id, C.name, C.livechat_channel_id, L.name, C.create_date, C.uuid
         )
     """)
예제 #4
0
 def init(self):
     tools.drop_view_if_exists(self._cr, self._table)
     self._cr.execute("""
         CREATE view %s as
           %s
           FROM project_task t
             WHERE t.active = 'true'
             %s
     """ % (self._table, self._select(), self._group_by()))
예제 #5
0
 def init(self):
     tools.drop_view_if_exists(self.env.cr, self._table)
     self.env.cr.execute("""CREATE VIEW %s AS (
         %s
         %s
         %s
         %s
         %s
     )""" % (self._table, self._select(), self._from(), self._join(),
             self._where(), self._group_by()))
예제 #6
0
 def init(self):
     # self._table = sale_report
     tools.drop_view_if_exists(self.env.cr, self._table)
     self.env.cr.execute(
         """CREATE or REPLACE VIEW %s as (
         %s
         FROM ( %s )
         %s
         )""" %
         (self._table, self._select(), self._from(), self._group_by()))
예제 #7
0
 def init(self):
     tools.drop_view_if_exists(self._cr, self._table)
     self._cr.execute("""
         CREATE OR REPLACE VIEW %s AS (
             %s
             %s
             %s
             %s
         )
     """ % (self._table, self._select(), self._from(), self._group_by(),self._having())
     )
예제 #8
0
 def init(self):
     # self._table = account_invoice_report
     tools.drop_view_if_exists(self.env.cr, self._table)
     self.env.cr.execute(
         """CREATE or REPLACE VIEW %s as (
         WITH currency_rate AS (%s)
         %s
         FROM (
             %s %s %s
         ) AS sub
         LEFT JOIN currency_rate cr ON
             (cr.currency_id = sub.currency_id AND
              cr.company_id = sub.company_id AND
              cr.date_start <= COALESCE(sub.date, NOW()) AND
              (cr.date_end IS NULL OR cr.date_end > COALESCE(sub.date, NOW())))
     )""" %
         (self._table, self.env['res.currency']._select_companies_rates(),
          self._select(), self._sub_select(), self._from(),
          self._group_by()))
예제 #9
0
 def init(self):
     # Note : start_date_hour must be remove when the read_group will allow grouping on the hour of a datetime. Don't forget to change the view !
     tools.drop_view_if_exists(self.env.cr, 'im_livechat_report_operator')
     self.env.cr.execute("""
         CREATE OR REPLACE VIEW im_livechat_report_operator AS (
             SELECT
                 row_number() OVER () AS id,
                 P.id as partner_id,
                 L.id as livechat_channel_id,
                 count(C.id) as nbr_channel,
                 C.id as channel_id,
                 C.create_date as start_date,
                 EXTRACT('epoch' FROM (max((SELECT (max(M.create_date)) FROM mail_message M JOIN mail_message_mail_channel_rel R ON (R.mail_message_id = M.id) WHERE R.mail_channel_id = C.id))-C.create_date)) as duration,
                 EXTRACT('epoch' from ((SELECT min(M.create_date) FROM mail_message M, mail_message_mail_channel_rel R WHERE M.author_id=P.id AND R.mail_channel_id = C.id AND R.mail_message_id = M.id)-(SELECT min(M.create_date) FROM mail_message M, mail_message_mail_channel_rel R WHERE M.author_id IS NULL AND R.mail_channel_id = C.id AND R.mail_message_id = M.id))) as time_to_answer
             FROM im_livechat_channel_im_user O
                 JOIN res_users U ON (O.user_id = U.id)
                 JOIN res_partner P ON (U.partner_id = P.id)
                 LEFT JOIN im_livechat_channel L ON (L.id = O.channel_id)
                 LEFT JOIN mail_channel C ON (C.livechat_channel_id = L.id)
             GROUP BY P.id, L.id, C.id, C.create_date
         )
     """)
예제 #10
0
 def init(self):
     tools.drop_view_if_exists(self._cr, 'asset_asset_report')
     self._cr.execute("""
         create or replace view asset_asset_report as (
             select
                 min(dl.id) as id,
                 dl.name as name,
                 dl.depreciation_date as depreciation_date,
                 a.date as date,
                 (CASE WHEN dlmin.id = min(dl.id)
                   THEN a.value
                   ELSE 0
                   END) as gross_value,
                 dl.amount as depreciation_value,
                 dl.amount as installment_value,
                 (CASE WHEN dl.move_check
                   THEN dl.amount
                   ELSE 0
                   END) as posted_value,
                 (CASE WHEN NOT dl.move_check
                   THEN dl.amount
                   ELSE 0
                   END) as unposted_value,
                 dl.asset_id as asset_id,
                 dl.move_check as move_check,
                 a.category_id as asset_category_id,
                 a.partner_id as partner_id,
                 a.state as state,
                 count(dl.*) as installment_nbr,
                 count(dl.*) as depreciation_nbr,
                 a.company_id as company_id
             from account_asset_depreciation_line dl
                 left join account_asset_asset a on (dl.asset_id=a.id)
                 left join (select min(d.id) as id,ac.id as ac_id from account_asset_depreciation_line as d inner join account_asset_asset as ac ON (ac.id=d.asset_id) group by ac_id) as dlmin on dlmin.ac_id=a.id
             group by
                 dl.amount,dl.asset_id,dl.depreciation_date,dl.name,
                 a.date, dl.move_check, a.state, a.category_id, a.partner_id, a.company_id,
                 a.value, a.id, a.salvage_value, dlmin.id
     )""")
예제 #11
0
 def init(self):
     tools.drop_view_if_exists(self._cr,
                               'hr_holidays_remaining_leaves_user')
     self._cr.execute("""
         CREATE or REPLACE view hr_holidays_remaining_leaves_user as (
              SELECT
                 min(hrs.id) as id,
                 rr.name as name,
                 sum(hrs.number_of_days) as no_of_leaves,
                 rr.user_id as user_id,
                 hhs.name as leave_type
             FROM
                 hr_holidays as hrs, hr_employee as hre,
                 resource_resource as rr,hr_holidays_status as hhs
             WHERE
                 hrs.employee_id = hre.id and
                 hre.resource_id =  rr.id and
                 hhs.id = hrs.holiday_status_id
             GROUP BY
                 rr.name,rr.user_id,hhs.name
         )
     """)
예제 #12
0
 def init(self):
     """ Event Question main report """
     tools.drop_view_if_exists(self._cr, 'event_question_report')
     self._cr.execute(""" CREATE VIEW event_question_report AS (
         SELECT
             att_answer.id as id,
             att_answer.event_registration_id as attendee_id,
             answer.question_id as question_id,
             answer.id as answer_id,
             question.event_id as event_id
         FROM
             event_registration_answer as att_answer
         LEFT JOIN
             event_answer as answer ON answer.id = att_answer.event_answer_id
         LEFT JOIN
             event_question as question ON question.id = answer.question_id
         GROUP BY
             attendee_id,
             event_id,
             question_id,
             answer_id,
             att_answer.id
     )""")
예제 #13
0
 def init(self):
     """
         CRM Lead Report
         @param cr: the current row, from the database cursor
     """
     tools.drop_view_if_exists(self._cr, 'crm_lead_report_assign')
     self._cr.execute("""
         CREATE OR REPLACE VIEW crm_lead_report_assign AS (
             SELECT
                 c.id,
                 c.date_open as opening_date,
                 c.date_closed as date_closed,
                 c.date_assign,
                 c.user_id,
                 c.probability,
                 c.probability as probability_max,
                 c.type,
                 c.company_id,
                 c.priority,
                 c.team_id,
                 c.partner_id,
                 c.country_id,
                 c.planned_revenue,
                 c.partner_assigned_id,
                 p.grade_id,
                 p.date as partner_date,
                 c.planned_revenue*(c.probability/100) as probable_revenue,
                 1 as nbr_cases,
                 c.create_date as create_date,
                 extract('epoch' from (c.write_date-c.create_date))/(3600*24) as  delay_close,
                 extract('epoch' from (c.date_deadline - c.date_closed))/(3600*24) as  delay_expected,
                 extract('epoch' from (c.date_open-c.create_date))/(3600*24) as  delay_open
             FROM
                 crm_lead c
                 left join res_partner p on (c.partner_assigned_id=p.id)
         )""")
예제 #14
0
 def init(self):
     tools.drop_view_if_exists(self.env.cr, self._table)
     self.env.cr.execute(self.get_main_request())
예제 #15
0
 def init(self):
     '''Create the view'''
     tools.drop_view_if_exists(self._cr, self._table)
     self._cr.execute("""
     CREATE OR REPLACE VIEW %s AS (
     SELECT
     MIN(id) AS id,
     partner_id,
     count(membership_id) as quantity,
     user_id,
     membership_state,
     associate_member_id,
     membership_amount,
     date_to,
     start_date,
     COUNT(num_waiting) AS num_waiting,
     COUNT(num_invoiced) AS num_invoiced,
     COUNT(num_paid) AS num_paid,
     SUM(tot_pending) AS tot_pending,
     SUM(tot_earned) AS tot_earned,
     membership_id,
     company_id
     FROM
     (SELECT
         MIN(p.id) AS id,
         p.id AS partner_id,
         p.user_id AS user_id,
         p.membership_state AS membership_state,
         p.associate_member AS associate_member_id,
         p.membership_amount AS membership_amount,
         p.membership_stop AS date_to,
         p.membership_start AS start_date,
         CASE WHEN ml.state = 'waiting'  THEN ml.id END AS num_waiting,
         CASE WHEN ml.state = 'invoiced' THEN ml.id END AS num_invoiced,
         CASE WHEN ml.state = 'paid'     THEN ml.id END AS num_paid,
         CASE WHEN ml.state IN ('waiting', 'invoiced') THEN SUM(il.price_subtotal) ELSE 0 END AS tot_pending,
         CASE WHEN ml.state = 'paid' OR p.membership_state = 'old' THEN SUM(il.price_subtotal) ELSE 0 END AS tot_earned,
         ml.membership_id AS membership_id,
         p.company_id AS company_id
         FROM res_partner p
         LEFT JOIN membership_membership_line ml ON (ml.partner = p.id)
         LEFT JOIN account_invoice_line il ON (ml.account_invoice_line = il.id)
         LEFT JOIN account_invoice ai ON (il.invoice_id = ai.id)
         WHERE p.membership_state != 'none' and p.active = 'true'
         GROUP BY
           p.id,
           p.user_id,
           p.membership_state,
           p.associate_member,
           p.membership_amount,
           p.membership_start,
           ml.membership_id,
           p.company_id,
           ml.state,
           ml.id
     ) AS foo
     GROUP BY
         start_date,
         date_to,
         partner_id,
         user_id,
         membership_id,
         company_id,
         membership_state,
         associate_member_id,
         membership_amount
     )""" % (self._table,))
예제 #16
0
 def init(self):
     tools.drop_view_if_exists(self._cr, 'purchase_report')
     self._cr.execute("""
         create view purchase_report as (
             WITH currency_rate as (%s)
             select
                 min(l.id) as id,
                 s.date_order as date_order,
                 s.state,
                 s.date_approve,
                 s.dest_address_id,
                 spt.warehouse_id as picking_type_id,
                 s.partner_id as partner_id,
                 s.create_uid as user_id,
                 s.company_id as company_id,
                 s.fiscal_position_id as fiscal_position_id,
                 l.product_id,
                 p.product_tmpl_id,
                 t.categ_id as category_id,
                 s.currency_id,
                 t.uom_id as product_uom,
                 sum(l.product_qty/u.factor*u2.factor) as unit_quantity,
                 extract(epoch from age(s.date_approve,s.date_order))/(24*60*60)::decimal(16,2) as delay,
                 extract(epoch from age(l.date_planned,s.date_order))/(24*60*60)::decimal(16,2) as delay_pass,
                 count(*) as nbr_lines,
                 sum(l.price_unit / COALESCE(cr.rate, 1.0) * l.product_qty)::decimal(16,2) as price_total,
                 avg(100.0 * (l.price_unit / COALESCE(cr.rate,1.0) * l.product_qty) / NULLIF(ip.value_float*l.product_qty/u.factor*u2.factor, 0.0))::decimal(16,2) as negociation,
                 sum(ip.value_float*l.product_qty/u.factor*u2.factor)::decimal(16,2) as price_standard,
                 (sum(l.product_qty * l.price_unit / COALESCE(cr.rate, 1.0))/NULLIF(sum(l.product_qty/u.factor*u2.factor),0.0))::decimal(16,2) as price_average,
                 partner.country_id as country_id,
                 partner.commercial_partner_id as commercial_partner_id,
                 analytic_account.id as account_analytic_id,
                 sum(p.weight * l.product_qty/u.factor*u2.factor) as weight,
                 sum(p.volume * l.product_qty/u.factor*u2.factor) as volume
             from purchase_order_line l
                 join purchase_order s on (l.order_id=s.id)
                 join res_partner partner on s.partner_id = partner.id
                     left join product_product p on (l.product_id=p.id)
                         left join product_template t on (p.product_tmpl_id=t.id)
                         LEFT JOIN ir_property ip ON (ip.name='standard_price' AND ip.res_id=CONCAT('product.product,',p.id) AND ip.company_id=s.company_id)
                 left join product_uom u on (u.id=l.product_uom)
                 left join product_uom u2 on (u2.id=t.uom_id)
                 left join stock_picking_type spt on (spt.id=s.picking_type_id)
                 left join account_analytic_account analytic_account on (l.account_analytic_id = analytic_account.id)
                 left join currency_rate cr on (cr.currency_id = s.currency_id and
                     cr.company_id = s.company_id and
                     cr.date_start <= coalesce(s.date_order, now()) and
                     (cr.date_end is null or cr.date_end > coalesce(s.date_order, now())))
             group by
                 s.company_id,
                 s.create_uid,
                 s.partner_id,
                 u.factor,
                 s.currency_id,
                 l.price_unit,
                 s.date_approve,
                 l.date_planned,
                 l.product_uom,
                 s.dest_address_id,
                 s.fiscal_position_id,
                 l.product_id,
                 p.product_tmpl_id,
                 t.categ_id,
                 s.date_order,
                 s.state,
                 spt.warehouse_id,
                 u.uom_type,
                 u.category_id,
                 t.uom_id,
                 u.id,
                 u2.factor,
                 partner.country_id,
                 partner.commercial_partner_id,
                 analytic_account.id
         )
     """ % self.env['res.currency']._select_companies_rates())