From e7764209b74cd68bc561e1ee3ab83ce06862e63f Mon Sep 17 00:00:00 2001 From: "Turkesh Patel (Open ERP)" Date: Thu, 5 Sep 2013 12:44:04 +0530 Subject: [PATCH] [FIX] improved code for invoice sparkline bar bzr revid: tpa@tinyerp.com-20130905071404-dlgdeovxarfa9pg6 --- addons/crm/crm.py | 8 +++++--- addons/sale_crm/sale_crm.py | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/addons/crm/crm.py b/addons/crm/crm.py index a9479000b3e..b3c560f084d 100644 --- a/addons/crm/crm.py +++ b/addons/crm/crm.py @@ -129,13 +129,15 @@ class crm_case_section(osv.osv): if type == "Lead" or not inner_groupby: section_result[month]['value'] = group.get(value_field, 0) continue - if inner_groupby: - groupby_company = obj.read_group(cr, uid, group.get('__domain'), read_fields, inner_groupby, context=context) - for groupby in groupby_company: + elif 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: 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 diff --git a/addons/sale_crm/sale_crm.py b/addons/sale_crm/sale_crm.py index af5973b8e3e..63017171322 100644 --- a/addons/sale_crm/sale_crm.py +++ b/addons/sale_crm/sale_crm.py @@ -52,9 +52,9 @@ class crm_case_section(osv.osv): for id in ids: res[id] = dict() created_domain = [('section_id', '=', id), ('state', 'in', ['draft', 'sent']), ('date_order', '>=', groupby_begin)] - res[id]['monthly_quoted'] = self.__get_bar_values(cr, uid, obj, created_domain, ['amount_total', 'date_order','pricelist_id'], 'amount_total', ['date_order','pricelist_id'], context=context) + res[id]['monthly_quoted'] = self.__get_bar_values(cr, uid, obj, created_domain, ['amount_total', 'date_order', 'pricelist_id'], 'amount_total', ['date_order', 'pricelist_id'], context=context) validated_domain = [('section_id', '=', id), ('state', 'not in', ['draft', 'sent']), ('date_confirm', '>=', groupby_begin)] - res[id]['monthly_confirmed'] = self.__get_bar_values(cr, uid, obj, validated_domain, ['amount_total', 'date_confirm','pricelist_id'], 'amount_total', ['date_confirm','pricelist_id'], context=context) + res[id]['monthly_confirmed'] = self.__get_bar_values(cr, uid, obj, validated_domain, ['amount_total', 'date_confirm', 'pricelist_id'], 'amount_total', ['date_confirm', 'pricelist_id'], context=context) return res def _get_invoices_data(self, cr, uid, ids, field_name, arg, context=None): @@ -64,7 +64,7 @@ class crm_case_section(osv.osv): groupby_begin = (month_begin + relativedelta.relativedelta(months=-4)).strftime(tools.DEFAULT_SERVER_DATE_FORMAT) for id in ids: created_domain = [('section_id', '=', id), ('state', 'not in', ['draft', 'cancel']), ('date', '>=', groupby_begin)] - res[id] = self.__get_bar_values(cr, uid, obj, created_domain, ['date'], 'user_currency_price_total', 'date', context=context) + res[id] = self.__get_bar_values(cr, uid, obj, created_domain, ['price_total', 'date', 'currency_id'], 'price_total', ['date', 'currency_id'], context=context) return res def _compute_amounts_in_user_currency(self, cr, uid, ids, field_names, args, context=None):