[IMP] crm: clean code

bzr revid: chm@openerp.com-20130322123803-43mz918j3ez9muvg
This commit is contained in:
Christophe Matthieu 2013-03-22 13:38:03 +01:00
parent 7f3ad2e6ea
commit a45ad6ec82
7 changed files with 28 additions and 28 deletions

View File

@ -81,7 +81,7 @@ Dashboard for CRM will include:
'crm_lead_view.xml',
'crm_lead_menu.xml',
'crm_salesteams.xml',
'crm_case_section_view.xml',
'crm_meeting_menu.xml',

View File

@ -109,19 +109,6 @@ 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_number_items(self, cr, uid, ids, model, domain, context=None):
res = dict.fromkeys(ids, 0)
obj = self.pool.get(model)
for section_id in ids:
res[section_id] = obj.search(cr, uid, [("section_id", "=", section_id)] + domain, count=True, context=context)
return res
def _get_number_leads(self, cr, uid, ids, field_name, arg, context=None):
return self.get_number_items(cr, uid, ids, 'crm.lead', ['|', '|', ("type", "=", "lead"), ("type", "=", "both"), ("type", "=", False), ('state', 'not in', ['done', 'cancel'])], context=context)
def _get_number_opportunities(self, cr, uid, ids, field_name, arg, context=None):
return self.get_number_items(cr, uid, ids, 'crm.lead', ['|', ("type", "=", "opportunity"), ("type", "=", "both"), ('state', 'not in', ['done', 'cancel'])], context=context)
_columns = {
'name': fields.char('Sales Team', size=64, required=True, translate=True),
'complete_name': fields.function(get_full_name, type='char', size=256, readonly=True, store=True),
@ -141,8 +128,10 @@ class crm_case_section(osv.osv):
'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="cascade", required=True,
help="The email address associated with this team. New emails received will automatically "
"create new leads assigned to the team."),
'number_lead': fields.function(_get_number_leads, type='integer', readonly=True),
'number_opportunity': fields.function(_get_number_opportunities, type='integer', readonly=True),
'open_lead_ids': fields.one2many('crm.lead', 'section_id', 'Leads', readonly=True,
domain=[('type', '!=', 'opportunity'), ('state', 'not in', ['done', 'cancel'])]),
'open_opportunity_ids': fields.one2many('crm.lead', 'section_id', 'Opportunities', readonly=True,
domain=['&', ('type', '=', 'opportunity'), ('type', '=', 'both'), ('state', 'not in', ['done', 'cancel'])]),
'color': fields.integer('Color Index'),
}

View File

@ -80,8 +80,8 @@
<field name="note"/>
<field name="alias_id"/>
<field name="color"/>
<field name="number_lead"/>
<field name="number_opportunity"/>
<field name="open_lead_ids"/>
<field name="open_opportunity_ids"/>
<templates>
<t t-name="kanban-box">
<div t-attf-class="oe_kanban_color_#{kanban_getcolor(record.color.raw_value)} oe_kanban_card oe_kanban_project oe_kanban_global_click oe_kanban_crm_salesteams" style="width:220px;">
@ -100,11 +100,11 @@
</div>
<div class="oe_kanban_crm_salesteams_list">
<a name="%(crm_case_form_view_salesteams_lead)d" type="action" style="margin-right: 10px">
<t t-raw="record.number_lead.raw_value"/>
<t t-if="record.number_lead.raw_value &gt;= 1">Leads</t><t t-if="record.number_lead.raw_value &lt; 1">Lead</t></a>
<t t-raw="record.open_lead_ids.raw_value.length"/>
<t t-if="record.open_lead_ids.raw_value.length &gt;= 1">Leads</t><t t-if="record.open_lead_ids.raw_value.length &lt; 1">Lead</t></a>
<a name="%(crm_case_form_view_salesteams_opportunity)d" type="action" style="margin-right: 10px">
<t t-raw="record.number_opportunity.raw_value"/>
<t t-if="record.number_opportunity.raw_value &gt;= 1">Opportunities</t><t t-if="record.number_opportunity.raw_value &lt; 1">Opportunity</t></a>
<t t-raw="record.open_opportunity_ids.raw_value.length"/>
<t t-if="record.open_opportunity_ids.raw_value.length &gt;= 1">Opportunities</t><t t-if="record.open_opportunity_ids.raw_value.length &lt; 1">Opportunity</t></a>
</div>
<div class="oe_kanban_crm_salesteams_avatars">
<img t-if="record.user_id.raw_value" t-att-src="kanban_image('res.users', 'image_small', record.user_id.raw_value)" t-att-data-member_id="record.user_id.raw_value"/>

View File

@ -94,7 +94,7 @@ class crm_lead(base_stage, format_address, osv.osv):
def onchange_user_id(self, cr, uid, ids, section_id, user_id, context=None):
if user_id:
section_ids = self.pool.get('crm.case.section').search(cr, uid, ['|', ('user_id', '=', user_id), ('member_ids', '=', user_id)], context=context)
if section_ids and (not section_id or section_id not in section_ids):
if section_id not in section_ids:
section_id = section_ids[0]
return {'value': {'section_id': section_id}}

View File

@ -22,7 +22,6 @@
import logging
import re
import unicodedata
import ast
from openerp.osv import fields, osv
from openerp.tools import ustr

View File

@ -33,13 +33,25 @@ class crm_case_section(osv.osv):
_inherit = 'crm.case.section'
def _get_number_saleorder(self, cr, uid, ids, field_name, arg, context=None):
return self.get_number_items(cr, uid, ids, 'sale.order', [('state','not in',('draft','sent','cancel'))], context=context)
res = dict.fromkeys(ids, 0)
obj = self.pool.get('sale.order')
for section_id in ids:
res[section_id] = obj.search(cr, uid, [("section_id", "=", section_id),('state','not in',['draft','sent','cancel'])], count=True, context=context)
return res
def _get_number_quotation(self, cr, uid, ids, field_name, arg, context=None):
return self.get_number_items(cr, uid, ids, 'sale.order', [('state','in',('draft','sent','cancel'))], context=context)
res = dict.fromkeys(ids, 0)
obj = self.pool.get('sale.order')
for section_id in ids:
res[section_id] = obj.search(cr, uid, [("section_id", "=", section_id),('state','in',['draft','sent','cancel'])], count=True, context=context)
return res
def _get_number_invoice(self, cr, uid, ids, field_name, arg, context=None):
return self.get_number_items(cr, uid, ids, 'account.invoice', [('state','not in',('draft','cancel'))], context=context)
res = dict.fromkeys(ids, 0)
obj = self.pool.get('account.invoice')
for section_id in ids:
res[section_id] = obj.search(cr, uid, [("section_id", "=", section_id),('state','not in',['draft','cancel'])], count=True, context=context)
return res
_columns = {
'number_saleorder': fields.function(_get_number_saleorder, type='integer', readonly=True),

View File

@ -181,7 +181,7 @@
<field name="inherit_id" ref="crm.crm_case_section_salesteams_view_kanban"/>
<field name="arch" type="xml">
<data>
<xpath expr="//field[@name='number_opportunity']" position="after">
<xpath expr="//field[@name='open_opportunity_ids']" position="after">
<field name="number_quotation"/>
<field name="number_saleorder"/>
<field name="number_invoice"/>