2011-03-10 09:53:21 +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
|
2011-03-10 09:53:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
class crm_partner_report_assign(osv.osv):
|
|
|
|
""" CRM Lead Report """
|
|
|
|
_name = "crm.partner.report.assign"
|
|
|
|
_auto = False
|
|
|
|
_description = "CRM Partner Report"
|
|
|
|
_columns = {
|
2012-02-09 16:15:44 +00:00
|
|
|
'partner_id': fields.many2one('res.partner', 'Partner', required=False, readonly=True),
|
2011-03-10 09:53:21 +00:00
|
|
|
'grade_id':fields.many2one('res.partner.grade', 'Grade', readonly=True),
|
2012-02-09 16:15:44 +00:00
|
|
|
'activation' : fields.many2one('res.partner.activation', 'Activation', select=1),
|
2011-03-10 09:53:21 +00:00
|
|
|
'user_id':fields.many2one('res.users', 'User', readonly=True),
|
2012-02-09 16:15:44 +00:00
|
|
|
'date_review' : fields.date('Latest Partner Review'),
|
|
|
|
'date_partnership' : fields.date('Partnership Date'),
|
2011-03-10 09:53:21 +00:00
|
|
|
'country_id':fields.many2one('res.country', 'Country', readonly=True),
|
|
|
|
'section_id':fields.many2one('crm.case.section', 'Sales Team', readonly=True),
|
2014-08-21 10:53:47 +00:00
|
|
|
'nbr_opportunities': fields.integer('# of Opportunity', readonly=True, oldname='opp'),
|
2012-02-09 16:15:44 +00:00
|
|
|
'turnover': fields.float('Turnover', readonly=True),
|
2012-02-15 10:52:12 +00:00
|
|
|
'period_id': fields.many2one('account.period', 'Invoice Period', readonly=True),
|
2011-03-10 09:53:21 +00:00
|
|
|
}
|
|
|
|
def init(self, cr):
|
|
|
|
"""
|
|
|
|
CRM Lead Report
|
|
|
|
@param cr: the current row, from the database cursor
|
|
|
|
"""
|
|
|
|
tools.drop_view_if_exists(cr, 'crm_partner_report_assign')
|
|
|
|
cr.execute("""
|
|
|
|
CREATE OR REPLACE VIEW crm_partner_report_assign AS (
|
|
|
|
SELECT
|
2012-02-16 10:07:44 +00:00
|
|
|
coalesce(i.id, p.id - 1000000000) as id,
|
2012-02-09 16:15:44 +00:00
|
|
|
p.id as partner_id,
|
2012-03-14 05:34:40 +00:00
|
|
|
(SELECT country_id FROM res_partner a WHERE a.parent_id=p.id AND country_id is not null limit 1) as country_id,
|
2011-03-10 09:53:21 +00:00
|
|
|
p.grade_id,
|
2012-02-09 16:15:44 +00:00
|
|
|
p.activation,
|
|
|
|
p.date_review,
|
|
|
|
p.date_partnership,
|
2011-03-10 09:53:21 +00:00
|
|
|
p.user_id,
|
|
|
|
p.section_id,
|
2014-08-21 10:53:47 +00:00
|
|
|
(SELECT count(id) FROM crm_lead WHERE partner_assigned_id=p.id) AS nbr_opportunities,
|
2012-02-15 10:52:12 +00:00
|
|
|
i.price_total as turnover,
|
|
|
|
i.period_id
|
2011-03-10 09:53:21 +00:00
|
|
|
FROM
|
|
|
|
res_partner p
|
2012-02-15 10:52:12 +00:00
|
|
|
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'))
|
2011-03-10 09:53:21 +00:00
|
|
|
)""")
|
|
|
|
|
2011-11-22 08:51:38 +00:00
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|