| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 3 |
|
| 4 |
from odoo import fields, models |
| 5 |
from odoo.tools import SQL |
| 6 |
|
| 7 |
|
| 8 |
class CrmPartnerReportAssign(models.Model): |
| 9 |
""" CRM Lead Report """ |
| 10 |
_name = 'crm.partner.report.assign' |
| 11 |
_auto = False |
| 12 |
_description = "CRM Partnership Analysis" |
| 13 |
|
| 14 |
partner_id = fields.Many2one('res.partner', 'Partner', required=False, readonly=True) |
| 15 |
grade_id = fields.Many2one('res.partner.grade', 'Grade', readonly=True) |
| 16 |
activation = fields.Many2one('res.partner.activation', 'Activation', index=True) |
| 17 |
user_id = fields.Many2one('res.users', 'User', readonly=True) |
| 18 |
date_review = fields.Date('Latest Partner Review') |
| 19 |
date_partnership = fields.Date('Partnership Date') |
| 20 |
country_id = fields.Many2one('res.country', 'Country', readonly=True) |
| 21 |
nbr_opportunities = fields.Integer('# of Opportunity', readonly=True) |
| 22 |
turnover = fields.Float('Turnover', readonly=True) |
| 23 |
date = fields.Date('Invoice Account Date', readonly=True) |
| 24 |
|
| 25 |
_depends = { |
| 26 |
'account.invoice.report': ['invoice_date', 'partner_id', 'price_subtotal', 'state', 'move_type'], |
| 27 |
'crm.lead': ['partner_assigned_id'], |
| 28 |
'res.partner': ['activation', 'country_id', 'date_partnership', 'date_review', |
| 29 |
'grade_id', 'parent_id', 'user_id'], |
| 30 |
} |
| 31 |
|
| 32 |
@property |
| 33 |
def _table_query(self): |
| 34 |
""" |
| 35 |
CRM Lead Report |
| 36 |
@param cr: the current row, from the database cursor |
| 37 |
""" |
| 38 |
return SQL( |
| 39 |
""" |
| 40 |
SELECT |
| 41 |
COALESCE(2 * i.id, 2 * p.id + 1) AS id, |
| 42 |
p.id as partner_id, |
| 43 |
(SELECT country_id FROM res_partner a WHERE a.parent_id=p.id AND country_id is not null limit 1) as country_id, |
| 44 |
p.grade_id, |
| 45 |
p.activation, |
| 46 |
p.date_review, |
| 47 |
p.date_partnership, |
| 48 |
p.user_id, |
| 49 |
(SELECT count(id) FROM crm_lead WHERE partner_assigned_id=p.id) AS nbr_opportunities, |
| 50 |
i.price_subtotal as turnover, |
| 51 |
i.invoice_date as date |
| 52 |
FROM |
| 53 |
res_partner p |
| 54 |
left join (%(account_invoice_report)s) i |
| 55 |
on (i.partner_id=p.id and i.move_type in ('out_invoice','out_refund') and i.state='posted') |
| 56 |
""", |
| 57 |
account_invoice_report=self.env['account.invoice.report']._table_query, |
| 58 |
) |