Launchpad automatic translations update.
[odoo/odoo.git] / addons / crm_partner_assign / report / crm_partner_report.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
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.
11 #
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.
16 #
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/>.
19 #
20 ##############################################################################
21 from osv import fields,osv
22 import tools
23
24
25 class crm_partner_report_assign(osv.osv):
26     """ CRM Lead Report """
27     _name = "crm.partner.report.assign"
28     _auto = False
29     _description = "CRM Partner Report"
30     _columns = {
31         'name': fields.char('Partner name', size=64, required=False, readonly=True),
32         'grade_id':fields.many2one('res.partner.grade', 'Grade', readonly=True),
33         'user_id':fields.many2one('res.users', 'User', readonly=True),
34         'country_id':fields.many2one('res.country', 'Country', readonly=True),
35         'section_id':fields.many2one('crm.case.section', 'Sales Team', readonly=True),
36         'nbr': fields.integer('# of Partner', readonly=True),
37         'opp': fields.integer('# of Opportunity', readonly=True),
38     }
39
40     def init(self, cr):
41
42         """
43             CRM Lead Report
44             @param cr: the current row, from the database cursor
45         """
46         tools.drop_view_if_exists(cr, 'crm_partner_report_assign')
47         cr.execute("""
48             CREATE OR REPLACE VIEW crm_partner_report_assign AS (
49                 SELECT
50                     p.id,
51                     p.name,
52                     (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,
53                     p.grade_id,
54                     p.user_id,
55                     p.section_id,
56                     1 as nbr,
57                     (SELECT count(id) FROM crm_lead WHERE partner_assigned_id=p.id) AS opp
58                 FROM
59                     res_partner p
60
61             )""")
62
63 crm_partner_report_assign()