[IMP] improved code to show all amounts in sales teams currency instead on current users currency
bzr revid: tpa@tinyerp.com-20131029125128-9n4myfklstueqq0v
This commit is contained in:
parent
c05369d2b2
commit
ecdb4abbd1
|
@ -100,14 +100,14 @@ 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 _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
|
||||
def _currency_conversation(self, cr, uid, id, amount, relation_id, relation_field, context=None):
|
||||
team = self.browse(cr, uid, id, context=context)
|
||||
base_currency_id = team.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
|
||||
return self.pool.get('res.currency').compute(cr, uid, base_currency_id, user.company_id.currency_id.id, amount, context=context)
|
||||
return self.pool.get('res.currency').compute(cr, uid, base_currency_id, team.currency_id.id, amount, context=context)
|
||||
|
||||
def __get_bar_values(self, cr, uid, obj, domain, read_fields, value_field, groupby_field, context=None):
|
||||
def __get_bar_values(self, cr, uid, id, 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).
|
||||
|
||||
|
@ -140,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, id, 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):
|
||||
|
@ -157,16 +157,9 @@ 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'], context=context)
|
||||
res[id]['monthly_open_leads'] = self.__get_bar_values(cr, uid, id, 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
|
||||
|
||||
def _get_currency_symbol(self, cr, uid, ids, name, arg, context=None):
|
||||
"""Set currency symbole of company currency"""
|
||||
res = {}
|
||||
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
|
||||
res = dict.fromkeys(ids, user.company_id.currency_id.symbol)
|
||||
res[id]['monthly_planned_revenue'] = self.__get_bar_values(cr, uid, id, obj, opp_domain, ['planned_revenue', 'create_date', 'company_id'], 'planned_revenue', ['create_date', 'company_id'], context=context)
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
|
@ -200,7 +193,7 @@ class crm_case_section(osv.osv):
|
|||
string='Planned Revenue per Month'),
|
||||
'create_uid': fields.many2one('res.users', 'Create User'),
|
||||
'currency_id': fields.many2one('res.currency', 'Currency', required=True),
|
||||
'currency_symbol': fields.function(_get_currency_symbol, string="Current User's Currency Symbol", method=True, type='char'),
|
||||
'currency_symbol': fields.related('currency_id', 'symbol', type='char', string='Currency Symbol'),
|
||||
}
|
||||
|
||||
def _get_stage_common(self, cr, uid, context):
|
||||
|
|
|
@ -45,18 +45,18 @@ 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
|
||||
def _currency_conversation(self, cr, uid, id, amount, relation_id, relation_field, context=None):
|
||||
team = self.browse(cr, uid, id, context=context)
|
||||
base_currency_id = team.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)
|
||||
return super(crm_case_section, self)._currency_conversation(cr, uid, id, 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)
|
||||
return self.pool.get('res.currency').compute(cr, uid, base_currency_id, team.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')
|
||||
|
@ -67,9 +67,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', '>=', date_begin), ('date_order', '<=', date_end)]
|
||||
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, id, 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', '>=', date_begin), ('date_order', '<=', date_end)]
|
||||
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, id, 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):
|
||||
|
@ -80,7 +80,7 @@ class crm_case_section(osv.osv):
|
|||
date_end = month_begin.replace(day=calendar.monthrange(month_begin.year, month_begin.month)[1]).strftime(tools.DEFAULT_SERVER_DATE_FORMAT)
|
||||
for id in ids:
|
||||
created_domain = [('section_id', '=', id), ('state', 'not in', ['draft', 'cancel']), ('date', '>=', date_begin), ('date', '<=', date_end)]
|
||||
res[id] = self.__get_bar_values(cr, uid, obj, created_domain, ['price_total', 'date', 'currency_id'], 'price_total', ['date', 'currency_id'], context=context)
|
||||
res[id] = self.__get_bar_values(cr, uid, id, obj, created_domain, ['price_total', 'date', 'currency_id'], 'price_total', ['date', 'currency_id'], context=context)
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
|
|
Loading…
Reference in New Issue