diff --git a/addons/crm/report/crm_lead_report.py b/addons/crm/report/crm_lead_report.py index d12facd66a0..23347988573 100644 --- a/addons/crm/report/crm_lead_report.py +++ b/addons/crm/report/crm_lead_report.py @@ -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 diff --git a/addons/crm/report/crm_lead_report_view.xml b/addons/crm/report/crm_lead_report_view.xml index 23594a7f9e1..a9b7bc73aab 100644 --- a/addons/crm/report/crm_lead_report_view.xml +++ b/addons/crm/report/crm_lead_report_view.xml @@ -28,7 +28,7 @@ - + @@ -53,7 +53,7 @@ - + @@ -146,12 +146,12 @@ - + - + diff --git a/addons/sale_crm/sale_crm.py b/addons/sale_crm/sale_crm.py index 97c5f4579e0..634df104d34 100644 --- a/addons/sale_crm/sale_crm.py +++ b/addons/sale_crm/sale_crm.py @@ -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' diff --git a/addons/sale_crm/sale_crm_demo.xml b/addons/sale_crm/sale_crm_demo.xml index 0c2822719dd..3eff4061aa1 100644 --- a/addons/sale_crm/sale_crm_demo.xml +++ b/addons/sale_crm/sale_crm_demo.xml @@ -3,15 +3,15 @@ - 52700 - 60000 + 52700 + 60000 Indirect Sales IM - 36000 - 40000 + 36000 + 40000 diff --git a/addons/sale_crm/sale_crm_view.xml b/addons/sale_crm/sale_crm_view.xml index 73057e63bfc..22dff55531d 100644 --- a/addons/sale_crm/sale_crm_view.xml +++ b/addons/sale_crm/sale_crm_view.xml @@ -248,8 +248,8 @@ - - + +