[IMP] remove type parameter from __get_bar_values and make base_currency_id alwas...
authorTurkesh Patel (Open ERP) <tpa@tinyerp.com>
Fri, 11 Oct 2013 12:44:04 +0000 (18:14 +0530)
committerTurkesh Patel (Open ERP) <tpa@tinyerp.com>
Fri, 11 Oct 2013 12:44:04 +0000 (18:14 +0530)
bzr revid: tpa@tinyerp.com-20131011124404-xoytwxfso8rg5lmb

addons/crm/crm.py

index bb4d13c..8f0e6a8 100644 (file)
@@ -100,7 +100,7 @@ class crm_case_section(osv.osv):
     def get_full_name(self, cr, uid, ids, field_name, arg, context=None):
         return dict(self.name_get(cr, uid, ids, context=context))
 
-    def __get_bar_values(self, cr, uid, obj, domain, read_fields, value_field, groupby_field, type=None, context=None):
+    def __get_bar_values(self, cr, uid, obj, domain, read_fields, value_field, groupby_field, context=None):
         """ Generic method to generate data for bar chart values using SparklineBarWidget.
             This method performs obj.read_group(cr, uid, domain, read_fields, groupby_field).
 
@@ -127,21 +127,22 @@ class crm_case_section(osv.osv):
             month = self._period_number - (relativedelta.relativedelta(month_begin, group_begin_date).months + 1)
             section_result[month] = {'value': 0, 'tooltip': group_begin_date.strftime('%B')}
             inner_groupby = (group.get('__context', {})).get('group_by',[])
-            if type == "Lead" or not inner_groupby:
+            if value_field == 'create_date_count' or not inner_groupby:
                 section_result[month]['value'] = group.get(value_field, 0)
                 continue
-            elif inner_groupby:
+            if inner_groupby:
                 inner_group_obj = obj.read_group(cr, uid, group.get('__domain'), read_fields, inner_groupby, context=context)
                 for groupby in inner_group_obj:
+                    user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
+                    base_currency_id = user.company_id.currency_id.id
                     if inner_groupby[0] == 'company_id':
                         base_currency_id = self.pool.get('res.company').browse(cr, uid, groupby['__domain'][0][2], context=context).currency_id.id
                     elif inner_groupby[0] == 'pricelist_id':
                         base_currency_id = self.pool.get('product.pricelist').browse(cr, uid, groupby['__domain'][0][2], context=context).currency_id.id
                     elif inner_groupby[0] == 'currency_id':
                         base_currency_id = self.pool.get('res.currency.rate').search_read(cr, uid, [('rate', '=', 1)], ['currency_id'], limit=1, context=context)[0]['currency_id'][0]
-                    user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
                     value = self.pool.get('res.currency').compute(cr, uid, base_currency_id, user.company_id.currency_id.id, groupby.get(value_field, 0))
-                    section_result[month]['value'] = section_result[month]['value'] + value
+                    section_result[month]['value'] += value
         return section_result
 
     def _get_opportunities_data(self, cr, uid, ids, field_name, arg, context=None):
@@ -158,7 +159,7 @@ class crm_case_section(osv.osv):
         for id in ids:
             res[id] = dict()
             lead_domain = date_domain + [('type', '=', 'lead'), ('section_id', '=', id)]
-            res[id]['monthly_open_leads'] = self.__get_bar_values(cr, uid, obj, lead_domain, ['create_date','company_id'], 'create_date_count', ['create_date', 'company_id'], type="Lead", context=context)
+            res[id]['monthly_open_leads'] = self.__get_bar_values(cr, uid, obj, lead_domain, ['create_date','company_id'], 'create_date_count', ['create_date', 'company_id'], context=context)
             opp_domain = date_domain + [('type', '=', 'opportunity'), ('section_id', '=', id)]
             res[id]['monthly_planned_revenue'] = self.__get_bar_values(cr, uid, obj, opp_domain, ['planned_revenue', 'create_date', 'company_id'], 'planned_revenue', ['create_date', 'company_id'], context=context)
         return res