2010-03-18 08:46:13 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2012-12-06 14:56:32 +00:00
|
|
|
from openerp.osv import fields,osv
|
|
|
|
from openerp import tools
|
2010-01-20 07:30:06 +00:00
|
|
|
|
2010-05-06 06:44:00 +00:00
|
|
|
AVAILABLE_STATES = [
|
|
|
|
('draft','Draft'),
|
|
|
|
('open','Open'),
|
|
|
|
('cancel', 'Cancelled'),
|
|
|
|
('done', 'Closed'),
|
|
|
|
('pending','Pending')
|
|
|
|
]
|
2010-03-18 08:46:13 +00:00
|
|
|
|
2010-05-06 08:45:15 +00:00
|
|
|
AVAILABLE_PRIORITIES = [
|
|
|
|
('5', 'Lowest'),
|
|
|
|
('4', 'Low'),
|
|
|
|
('3', 'Normal'),
|
|
|
|
('2', 'High'),
|
|
|
|
('1', 'Highest')
|
|
|
|
]
|
2010-01-20 07:30:06 +00:00
|
|
|
|
2010-03-18 08:46:13 +00:00
|
|
|
|
2010-03-05 13:17:53 +00:00
|
|
|
class crm_claim_report(osv.osv):
|
2010-03-18 08:46:13 +00:00
|
|
|
""" CRM Claim Report"""
|
|
|
|
|
2010-03-05 13:17:53 +00:00
|
|
|
_name = "crm.claim.report"
|
2010-01-20 07:30:06 +00:00
|
|
|
_auto = False
|
2010-03-18 08:46:13 +00:00
|
|
|
_description = "CRM Claim Report"
|
|
|
|
|
2010-01-20 07:30:06 +00:00
|
|
|
_columns = {
|
2010-05-06 06:44:00 +00:00
|
|
|
'name': fields.char('Year', size=64, required=False, readonly=True),
|
|
|
|
'user_id':fields.many2one('res.users', 'User', readonly=True),
|
|
|
|
'section_id':fields.many2one('crm.case.section', 'Section', readonly=True),
|
|
|
|
'nbr': fields.integer('# of Cases', readonly=True),
|
2012-05-04 11:57:48 +00:00
|
|
|
'state': fields.selection(AVAILABLE_STATES, 'Status', size=16, readonly=True),
|
2010-05-06 06:44:00 +00:00
|
|
|
'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')], 'Month', readonly=True),
|
|
|
|
'company_id': fields.many2one('res.company', 'Company', readonly=True),
|
2011-01-17 13:26:54 +00:00
|
|
|
'create_date': fields.datetime('Create Date', readonly=True, select=True),
|
2011-02-07 05:33:04 +00:00
|
|
|
'day': fields.char('Day', size=128, readonly=True),
|
2010-04-21 10:12:25 +00:00
|
|
|
'delay_close': fields.float('Delay to close', digits=(16,2),readonly=True, group_operator="avg",help="Number of Days to close the case"),
|
2011-08-17 08:33:50 +00:00
|
|
|
'stage_id': fields.many2one ('crm.case.stage', 'Stage', readonly=True,domain="[('section_ids','=',section_id)]"),
|
2010-03-18 08:46:13 +00:00
|
|
|
'categ_id': fields.many2one('crm.case.categ', 'Category',\
|
|
|
|
domain="[('section_id','=',section_id),\
|
|
|
|
('object_id.model', '=', 'crm.claim')]", readonly=True),
|
|
|
|
'partner_id': fields.many2one('res.partner', 'Partner', readonly=True),
|
|
|
|
'company_id': fields.many2one('res.company', 'Company', readonly=True),
|
2010-05-06 08:45:15 +00:00
|
|
|
'priority': fields.selection(AVAILABLE_PRIORITIES, 'Priority'),
|
2010-09-28 21:53:48 +00:00
|
|
|
'type_action': fields.selection([('correction','Corrective Action'),('prevention','Preventive Action')], 'Action Type'),
|
2011-02-07 05:33:04 +00:00
|
|
|
'date_closed': fields.date('Close Date', readonly=True, select=True),
|
|
|
|
'date_deadline': fields.date('Deadline', readonly=True, select=True),
|
2010-09-21 07:17:53 +00:00
|
|
|
'delay_expected': fields.float('Overpassed Deadline',digits=(16,2),readonly=True, group_operator="avg"),
|
2011-09-05 10:31:49 +00:00
|
|
|
'email': fields.integer('# Emails', size=128, readonly=True)
|
2010-01-20 07:30:06 +00:00
|
|
|
}
|
2010-03-18 08:46:13 +00:00
|
|
|
|
2010-01-20 07:30:06 +00:00
|
|
|
def init(self, cr):
|
2010-03-18 08:46:13 +00:00
|
|
|
|
2010-03-18 11:23:49 +00:00
|
|
|
""" Display Number of cases And Section Name
|
2010-03-18 08:46:13 +00:00
|
|
|
@param cr: the current row, from the database cursor,
|
2010-03-18 11:23:49 +00:00
|
|
|
"""
|
2010-03-18 08:46:13 +00:00
|
|
|
|
2010-03-05 13:17:53 +00:00
|
|
|
tools.drop_view_if_exists(cr, 'crm_claim_report')
|
2010-01-20 07:30:06 +00:00
|
|
|
cr.execute("""
|
2010-03-05 13:17:53 +00:00
|
|
|
create or replace view crm_claim_report as (
|
2010-01-20 07:30:06 +00:00
|
|
|
select
|
|
|
|
min(c.id) as id,
|
2010-09-21 07:17:53 +00:00
|
|
|
to_char(c.date, 'YYYY') as name,
|
|
|
|
to_char(c.date, 'MM') as month,
|
|
|
|
to_char(c.date, 'YYYY-MM-DD') as day,
|
|
|
|
to_char(c.date_closed, 'YYYY-MM-DD') as date_closed,
|
2010-10-04 06:03:16 +00:00
|
|
|
to_char(c.date_deadline, 'YYYY-MM-DD') as date_deadline,
|
2010-01-20 07:30:06 +00:00
|
|
|
c.state,
|
|
|
|
c.user_id,
|
2010-03-02 14:06:35 +00:00
|
|
|
c.stage_id,
|
2010-03-03 11:35:55 +00:00
|
|
|
c.section_id,
|
2010-03-05 08:19:49 +00:00
|
|
|
c.partner_id,
|
2010-03-05 09:20:14 +00:00
|
|
|
c.company_id,
|
2010-01-20 07:30:06 +00:00
|
|
|
c.categ_id,
|
|
|
|
count(*) as nbr,
|
2010-04-23 13:30:26 +00:00
|
|
|
c.priority as priority,
|
2010-09-28 22:10:23 +00:00
|
|
|
c.type_action as type_action,
|
2010-04-21 10:12:25 +00:00
|
|
|
date_trunc('day',c.create_date) as create_date,
|
2010-09-21 07:17:53 +00:00
|
|
|
avg(extract('epoch' from (c.date_closed-c.create_date)))/(3600*24) as delay_close,
|
2011-09-15 14:46:11 +00:00
|
|
|
(SELECT count(id) FROM mail_message WHERE model='crm.claim' AND res_id=c.id) AS email,
|
2010-09-21 07:17:53 +00:00
|
|
|
extract('epoch' from (c.date_deadline - c.date_closed))/(3600*24) as delay_expected
|
2010-01-20 07:30:06 +00:00
|
|
|
from
|
|
|
|
crm_claim c
|
2010-09-21 07:17:53 +00:00
|
|
|
group by to_char(c.date, 'YYYY'), to_char(c.date, 'MM'),to_char(c.date, 'YYYY-MM-DD'),\
|
2010-03-18 08:46:13 +00:00
|
|
|
c.state, c.user_id,c.section_id, c.stage_id,\
|
2010-09-21 07:17:53 +00:00
|
|
|
c.categ_id,c.partner_id,c.company_id,c.create_date,
|
2010-12-23 10:55:16 +00:00
|
|
|
c.priority,c.type_action,c.date_deadline,c.date_closed,c.id
|
2010-01-20 07:30:06 +00:00
|
|
|
)""")
|
2010-03-18 08:46:13 +00:00
|
|
|
|
2010-01-29 07:35:52 +00:00
|
|
|
|
2010-03-03 07:15:21 +00:00
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|