diff options
| author | Fabien Pinckaers <fp@tinyerp.com> | 2011-11-12 01:44:05 +0100 |
|---|---|---|
| committer | Fabien Pinckaers <fp@tinyerp.com> | 2011-11-12 01:44:05 +0100 |
| commit | dc04a292a43d04d9be9f23f07f17f8f0e1f46726 (patch) | |
| tree | 65cbcbadf73e1cad7e6ae9f68426cc4eea46d3e7 /addons | |
| parent | 31c9a1691e92e57f2a8fd90a461926e63b824a0c (diff) | |
[IMP] read_group full on crm.opportunities for kanban views, need to move this code to be used by others modules in tools
bzr revid: fp@tinyerp.com-20111112004405-m511icvvf3worvod
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/crm/crm_lead.py | 57 | ||||
| -rw-r--r-- | addons/crm/crm_lead_view.xml | 2 |
2 files changed, 58 insertions, 1 deletions
diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index 0e479d33737..dda57b81760 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -35,6 +35,36 @@ CRM_LEAD_PENDING_STATES = ( crm.AVAILABLE_STATES[4][0], # Pending ) +class read_group_full(object): + def __init__(self, field, obj, domain): + self.field = field + self.obj = obj + self.domain = domain + def __call__(self, method): + def lookup(self2, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False): + result = method(self2, cr, uid, domain, fields, groupby, offset, limit, context, orderby) + if groupby and groupby[0]==self.field: + stage_obj = self2.pool.get(self.obj) + stage_ids = map(lambda x: x[self.field][0], result) + stage_ids = stage_obj.search(cr, uid, ['|',('id','in',stage_ids)] + self.domain, context=context) + stages = stage_obj.name_get(cr, uid, stage_ids, context=context) + # as both lists are sorted in the same way, we can merge in one pass + pos = 0 + while (pos<len(result)) or (pos<len(stages)): + if (pos<len(result)) and (result[pos][self.field][0] == stages[pos][0]): + pos+=1 + continue + val = dict(map(lambda x: (x, False), fields)) + val.update({ + self.field: stages[pos], + '__domain': [(self.field, '=', stages[pos][0])]+domain, + self.field+'_count': 1L, # Should be 0L but the web client crashes + '__context': {'group_by': groupby[1:]} + }) + result.insert(pos, val) + return result + return lookup + class crm_lead(crm_case, osv.osv): """ CRM Lead Case """ _name = "crm.lead" @@ -42,6 +72,33 @@ class crm_lead(crm_case, osv.osv): _order = "priority,date_action,id desc" _inherit = ['mail.thread','res.partner.address'] + @read_group_full('stage_id', 'crm.case.stage', [('case_default','=',1)]) + def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False): + return super(crm_lead, self).read_group(cr, uid, domain, fields, groupby, offset=offset, limit=limit, context=context, orderby=orderby) + + def read_group_complete(cr, uid, domain, fields, groupby, context, result): + if groupby and groupby[0]=='stage_id': + stage_obj = self.pool.get('crm.case.stage') + stage_ids = map(lambda x: x['stage_id'][0], result) + stage_ids = stage_obj.search(cr, uid, ['|',('id','in',stage_ids),('case_default','=',True)], context=context) + stages = stage_obj.name_get(cr, uid, stage_ids, context=context) + + # as both lists are sorted in the same way, we can merge in one pass + pos = 0 + while (pos<len(result)) or (pos<len(stages)): + if (pos<len(result)) and (result[pos]['stage_id'][0] == stages[pos][0]): + pos+=1 + continue + val = dict(map(lambda x: (x, False), fields)) + val.update({ + 'stage_id': stages[pos], + '__domain': [('stage_id', '=', stages[pos][0])]+domain, + 'stage_id_count': 1L, # Should be 0L but the web client crashes + '__context': {'group_by': groupby[1:]} + }) + result.insert(pos, val) + return result + # overridden because res.partner.address has an inconvenient name_get, # especially if base_contact is installed. def name_get(self, cr, user, ids, context=None): diff --git a/addons/crm/crm_lead_view.xml b/addons/crm/crm_lead_view.xml index b37f1db6d55..16a90e4e44d 100644 --- a/addons/crm/crm_lead_view.xml +++ b/addons/crm/crm_lead_view.xml @@ -306,7 +306,7 @@ <field name="user_email"/> <templates> <t t-name="kanban-box"> - <t t-set="color" t-value="kanban_color(record.color.raw_value || record.state.raw_value)"/> + <t t-set="color" t-value="kanban_color(record.color.raw_value)"/> <div t-att-class="color + (record.priority.raw_value == 1 ? ' oe_kanban_color_alert' : '')"> <div class="oe_kanban_box oe_kanban_color_border"> <table class="oe_kanban_table oe_kanban_box_header oe_kanban_color_bgdark oe_kanban_color_border oe_kanban_draghandle"> |
