[IMP] Improved report of lead/apportunity analysis to show in user currency and improved code to show target and forcast amount in current user currency.

bzr revid: tpa@tinyerp.com-20130805113549-9vmwd2v0zsjwlcms
This commit is contained in:
Turkesh Patel (Open ERP) 2013-08-05 17:05:49 +05:30
parent d2777a494f
commit 7f6daa12f9
5 changed files with 67 additions and 17 deletions

View File

@ -53,6 +53,19 @@ class crm_lead_report(osv.osv):
_description = "CRM Lead Analysis"
_rec_name = 'deadline_day'
def _compute_amounts_in_user_currency(self, cr, uid, ids, field_names=[], args={}, context=None):
"""Compute the amounts in the currency of the user
"""
res = {}
currency_obj = self.pool.get('res.currency')
user_currency_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id.id
for item in self.browse(cr, uid, ids, context=context):
res[item.id] = {
'user_currency_planned_revenue': currency_obj.compute(cr, uid, item.company_id.currency_id.id, user_currency_id, item.planned_revenue, context=context),
'user_currency_probable_revenue': currency_obj.compute(cr, uid, item.company_id.currency_id.id, user_currency_id, item.probable_revenue, context=context),
}
return res
_columns = {
# grouping fields based on Deadline Date
'deadline_year': fields.char('Ex. Closing Year', size=10, readonly=True, help="Expected closing year"),
@ -83,7 +96,9 @@ class crm_lead_report(osv.osv):
'company_id': fields.many2one('res.company', 'Company', readonly=True),
'probability': fields.float('Probability',digits=(16,2),readonly=True, group_operator="avg"),
'planned_revenue': fields.float('Planned Revenue',digits=(16,2),readonly=True),
'user_currency_planned_revenue': fields.function(_compute_amounts_in_user_currency, string="Planned Revenue", type='float',digits=(16,2), multi="_compute_amounts", readonly=True),
'probable_revenue': fields.float('Probable Revenue', digits=(16,2),readonly=True),
'user_currency_probable_revenue': fields.function(_compute_amounts_in_user_currency, string="Probable Revenue", type='float',digits=(16,2), multi="_compute_amounts",readonly=True),
'stage_id': fields.many2one ('crm.case.stage', 'Stage', readonly=True, domain="[('section_ids', '=', section_id)]"),
'partner_id': fields.many2one('res.partner', 'Partner' , readonly=True),
'nbr': fields.integer('# of Cases', readonly=True),
@ -94,12 +109,21 @@ class crm_lead_report(osv.osv):
('opportunity','Opportunity'),
],'Type', help="Type is used to separate Leads and Opportunities"),
}
#FIX:To show sum of values of function fields in groupby
def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False):
res = super(crm_lead_report, self).read_group(cr, uid, domain, fields, groupby, offset, limit, context, orderby)
for group in res:
group['user_currency_probable_revenue'] = 0
group['user_currency_planned_revenue'] = 0
group_ids = self.search(cr, uid, group.get('__domain'),context=context)
record = self._compute_amounts_in_user_currency(cr, uid, group_ids, context=context)
for id, rec in record.iteritems():
group['user_currency_planned_revenue'] += rec['user_currency_planned_revenue']
group['user_currency_probable_revenue'] += rec['user_currency_probable_revenue']
return res
def init(self, cr):
"""
CRM Lead Report
@param cr: the current row, from the database cursor

View File

@ -28,7 +28,7 @@
<field name="nbr" sum="# Leads"/>
<field name="delay_open"/>
<field name="delay_close"/>
<field name="planned_revenue"/>
<field name="user_currency_planned_revenue"/>
</tree>
</field>
</record>
@ -53,7 +53,7 @@
<field name="arch" type="xml">
<graph orientation="vertical" string="Leads Analysis" type="bar">
<field name="stage_id"/>
<field name="planned_revenue" operator="+"/>
<field name="user_currency_planned_revenue" operator="+"/>
<field group="True" name="user_id"/>
</graph>
</field>
@ -146,12 +146,12 @@
<field name="type" invisible="1"/>
<field name="company_id" invisible="1" groups="base.group_multi_company"/>
<field name="nbr" string="#Opportunities" sum="#Opportunities"/>
<field name="planned_revenue" sum="Planned Revenues"/>
<field name="user_currency_planned_revenue" sum="Planned Revenues"/>
<field name="delay_open" sum='Delay to open'/>
<field name="delay_close" sum='Delay to close'/>
<field name="delay_expected"/>
<field name="probability" widget="progressbar"/>
<field name="probable_revenue"/>
<field name="user_currency_probable_revenue"/>
</tree>
</field>
</record>

View File

@ -67,12 +67,25 @@ class crm_case_section(osv.osv):
res[id] = self.__get_bar_values(cr, uid, obj, created_domain, ['price_total', 'date'], 'price_total', 'date', context=context)
return res
def _compute_amounts_in_user_currency(self, cr, uid, ids, field_names, args, context=None):
"""Compute the amounts in the currency of the user """
res = {}
currency_obj = self.pool.get('res.currency')
user_currency_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id.id
for item in self.browse(cr, uid, ids, context=context):
base_currency_id = item.user_id.company_id.currency_id.id if item.user_id else item.create_uid.company_id.currency_id.id
res[item.id] = {
'invoiced_forecast': currency_obj.compute(cr, uid, base_currency_id, user_currency_id, item.base_invoiced_forecast, context=context),
'invoiced_target': currency_obj.compute(cr, uid, base_currency_id, user_currency_id, item.base_invoiced_target, context=context),
}
return res
_columns = {
'invoiced_forecast': fields.integer(string='Invoice Forecast',
'invoiced_forecast': fields.function(_compute_amounts_in_user_currency, string='Invoice Forecast',type='integer', multi="_compute_amounts",
help="Forecast of the invoice revenue for the current month. This is the amount the sales \n"
"team should invoice this month. It is used to compute the progression ratio \n"
" of the current and forecast revenue on the kanban view."),
'invoiced_target': fields.integer(string='Invoice Target',
'invoiced_target': fields.function(_compute_amounts_in_user_currency,string='Invoice Target',type='integer', multi="_compute_amounts",
help="Target of invoice revenue for the current month. This is the amount the sales \n"
"team estimates to be able to invoice this month."),
'monthly_quoted': fields.function(_get_sale_orders_data,
@ -84,11 +97,24 @@ class crm_case_section(osv.osv):
'monthly_invoiced': fields.function(_get_invoices_data,
type='string', readonly=True,
string='Rate of sent invoices per duration'),
'base_invoiced_forecast': fields.integer(string="Invoice Forecast"),
'base_invoiced_target': fields.integer(string="Invoice Target"),
'create_uid': fields.many2one('res.users', 'Create User'),
}
def action_forecast(self, cr, uid, id, value, context=None):
return self.write(cr, uid, [id], {'invoiced_forecast': value}, context=context)
return self.write(cr, uid, [id], {'invoiced_forecast': int(value)}, context=context)
def write(self, cr, uid, ids, vals, context=None):
currency_obj = self.pool.get('res.currency')
user_currency_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id.id
for item in self.browse(cr, uid, ids, context=context):
base_currency_id = item.user_id.company_id.currency_id.id if item.user_id else item.create_uid.company_id.currency_id.id
if vals.get('invoiced_forecast'):
vals['base_invoiced_forecast'] = currency_obj.compute(cr, uid, user_currency_id, base_currency_id, vals['invoiced_forecast'], context=context)
if vals.get('invoiced_target'):
vals['base_invoiced_target'] = currency_obj.compute(cr, uid, user_currency_id, base_currency_id, vals['invoiced_target'], context=context)
return super(crm_case_section, self).write(cr, uid, ids, vals, context=context)
class res_users(osv.Model):
_inherit = 'res.users'

View File

@ -3,15 +3,15 @@
<data>
<record model="crm.case.section" id="crm.section_sales_department">
<field name="invoiced_forecast">52700</field>
<field name="invoiced_target">60000</field>
<field name="base_invoiced_forecast">52700</field>
<field name="base_invoiced_target">60000</field>
</record>
<record model="crm.case.section" id="crm.crm_case_section_1">
<field name="name">Indirect Sales</field>
<field name="code">IM</field>
<field name="invoiced_forecast">36000</field>
<field name="invoiced_target">40000</field>
<field name="base_invoiced_forecast">36000</field>
<field name="base_invoiced_target">40000</field>
</record>
<!-- Invoice for Direct Marketing -->

View File

@ -248,8 +248,8 @@
<field name="arch" type="xml">
<data>
<xpath expr="//field[@name='code']" position="after">
<field name="invoiced_target"/>
<field name="invoiced_forecast"/>
<field name="invoiced_target" readonly="0"/>
<field name="invoiced_forecast" readonly="0"/>
</xpath>
</data>
</field>