1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
21 from osv import fields,osv
25 class crm_partner_report_assign(osv.osv):
26 """ CRM Lead Report """
27 _name = "crm.partner.report.assign"
29 _description = "CRM Partner Report"
31 'partner_id': fields.many2one('res.partner', 'Partner', required=False, readonly=True),
32 'grade_id':fields.many2one('res.partner.grade', 'Grade', readonly=True),
33 'activation' : fields.many2one('res.partner.activation', 'Activation', select=1),
34 'user_id':fields.many2one('res.users', 'User', readonly=True),
35 'date_review' : fields.date('Latest Partner Review'),
36 'date_partnership' : fields.date('Partnership Date'),
37 'country_id':fields.many2one('res.country', 'Country', readonly=True),
38 'section_id':fields.many2one('crm.case.section', 'Sales Team', readonly=True),
39 'opp': fields.integer('# of Opportunity', readonly=True),
40 'turnover': fields.float('Turnover', readonly=True),
41 'period_id': fields.many2one('account.period', 'Invoice Period', readonly=True),
46 @param cr: the current row, from the database cursor
48 tools.drop_view_if_exists(cr, 'crm_partner_report_assign')
50 CREATE OR REPLACE VIEW crm_partner_report_assign AS (
52 coalesce(i.id, p.id - 1000000000) as id,
54 (SELECT country_id FROM res_partner_address a WHERE a.partner_id=p.id AND country_id is not null limit 1) as country_id,
61 (SELECT count(id) FROM crm_lead WHERE partner_assigned_id=p.id) AS opp,
62 i.price_total as turnover,
66 left join account_invoice_report i
67 on (i.partner_id=p.id and i.type in ('out_invoice','out_refund') and i.state in ('open','paid'))
70 crm_partner_report_assign()
72 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: