[IMP] improved code.
authorTurkesh Patel (Open ERP) <tpa@tinyerp.com>
Fri, 25 Oct 2013 09:45:12 +0000 (15:15 +0530)
committerTurkesh Patel (Open ERP) <tpa@tinyerp.com>
Fri, 25 Oct 2013 09:45:12 +0000 (15:15 +0530)
bzr revid: tpa@tinyerp.com-20131025094512-m0mx0a0s94h1ldjg

addons/crm/crm.py
addons/sale_crm/sale_crm.py

index f0b4ffe..9e1a9ab 100644 (file)
@@ -105,12 +105,6 @@ class crm_case_section(osv.osv):
         base_currency_id = user.company_id.currency_id.id
         if relation_field == 'company_id':
             base_currency_id = self.pool.get('res.company').browse(cr, uid, relation_id, context=context).currency_id.id
-        elif relation_field == 'pricelist_id':
-            base_currency_id = self.pool.get('product.pricelist').browse(cr, uid, relation_id, context=context).currency_id.id
-        elif relation_field == 'currency_id':
-            currency_rates = self.pool.get('res.currency.rate').search_read(cr, uid, [('rate', '=', 1)], ['currency_id'], limit=1, context=context)
-            if currency_rates:
-                base_currency_id = currency_rates[0]['currency_id'][0]
         return self.pool.get('res.currency').compute(cr, uid, base_currency_id, user.company_id.currency_id.id, amount, context=context)
 
     def __get_bar_values(self, cr, uid, obj, domain, read_fields, value_field, groupby_field, context=None):
@@ -146,7 +140,7 @@ class crm_case_section(osv.osv):
             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:
-                    section_result[month]['value'] += self._currency_conversation(cr, uid, groupby.get(value_field, 0), groupby['__domain'][0][2],inner_groupby[0], context=context)
+                    section_result[month]['value'] += self._currency_conversation(cr, uid, groupby.get(value_field, 0), groupby['__domain'][0][2], inner_groupby[0], context=context)
         return section_result
 
     def _get_opportunities_data(self, cr, uid, ids, field_name, arg, context=None):
index 2e7d61a..26b2aa0 100644 (file)
@@ -45,6 +45,19 @@ class sale_order(osv.osv):
 class crm_case_section(osv.osv):
     _inherit = 'crm.case.section'
 
+    def _currency_conversation(self, cr, uid, amount, relation_id, relation_field, context=None):
+        user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
+        base_currency_id = user.company_id.currency_id.id
+        if relation_field not in ['pricelist_id', 'currency_id']:
+            return super(crm_case_section, self)._currency_conversation(cr, uid, amount, relation_id, relation_field, context=context)
+        if relation_field == 'pricelist_id':
+            base_currency_id = self.pool.get('product.pricelist').browse(cr, uid, relation_id, context=context).currency_id.id
+        elif relation_field == 'currency_id':
+            currency_rates = self.pool.get('res.currency.rate').search_read(cr, uid, [('rate', '=', 1)], ['currency_id'], limit=1, context=context)
+            if currency_rates:
+                base_currency_id = currency_rates[0]['currency_id'][0]
+        return self.pool.get('res.currency').compute(cr, uid, base_currency_id, user.company_id.currency_id.id, amount, context=context)
+
     def _get_sale_orders_data(self, cr, uid, ids, field_name, arg, context=None):
         obj = self.pool.get('sale.order')
         res = dict.fromkeys(ids, False)