[IMP,REM]: crm*: Improvements for sections and stages:

* Removed many2one field section_id from stage
* Added many2many field stage_ids in sales team(section)
* Improvement in stage_previous, state_next

bzr revid: rpa@tinyerp.com-20101001123719-h7rmqkgt15abjbfb
This commit is contained in:
rpa (Open ERP) 2010-10-01 18:07:19 +05:30
parent 28a1069e86
commit 4787a78cdd
17 changed files with 113 additions and 155 deletions

View File

@ -145,53 +145,29 @@ class crm_case(object):
@param context: A standard dictionary for contextual values"""
if not context:
context = {}
s = self.get_stage_dict(cr, uid, ids, context=context)
section = self._name
stage = False
stage_pool = self.pool.get('crm.case.stage')
model = self._name
for case in self.browse(cr, uid, ids, context):
if section in s:
st = not context.get('force_domain', False) and case.stage_id.id or False
if st in s[section]:
data = {'stage_id': s[section][st]}
stage = s[section][st]
self.write(cr, uid, [case.id], data)
return stage
def get_stage_dict(self, cr, uid, ids, context=None):
"""This function gives dictionary for stage according to stage levels
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of case IDs
@param context: A standard dictionary for contextual values"""
if not context:
context = {}
stage_obj = self.pool.get('crm.case.stage')
res = self.read(cr, uid, ids, ['section_id', 'stage_id'], context)[0]
section_id = res['section_id'] and res['section_id'][0] or False
stage_id = res['stage_id'] and res['stage_id'][0] or False
# We select either the stages in the same section as the current stage
# if it a stage that does not have a section, or the stages of the
# current section of the case
if stage_id:
stage_record = stage_obj.browse(cr, uid, stage_id)
if not stage_record.section_id:
section_id = False # only select stages without section
domain = [('object_id.model', '=', self._name), '|', ('section_id', '=', section_id),('section_id','=',False)]
if 'force_domain' in context and context['force_domain']:
domain += context['force_domain']
sid = stage_obj.search(cr, uid, domain, context=context)
s = {}
previous = {}
section = self._name
for stage in stage_obj.browse(cr, uid, sid, context=context):
s.setdefault(section, {})
s[section][previous.get(section, False)] = stage.id
previous[section] = stage.id
return s
next_stage = False
data = {}
domain = [('object_id.model', '=', model)]
if case.section_id and case.section_id.stage_ids:
domain.append(('id', 'in', map(lambda x: x.id, case.section_id.stage_ids)))
stages = stage_pool.search(cr, uid, domain, order='sequence')
index = -1
if case.stage_id and case.stage_id.id in stages:
index = stages.index(case.stage_id.id)
if index + 1 == len(stages):
return False
else:
next_stage = stages[index + 1]
if next_stage:
data = {'stage_id': next_stage}
stage = stage_pool.browse(cr, uid, next_stage, context=context)
if stage.on_change:
data.update({'probability': stage.probability})
self.write(cr, uid, [case.id], data, context=context)
return next_stage
def stage_previous(self, cr, uid, ids, context=None):
"""This function computes previous stage for case from its current stage
@ -203,21 +179,28 @@ class crm_case(object):
@param context: A standard dictionary for contextual values"""
if not context:
context = {}
s = self.get_stage_dict(cr, uid, ids, context=context)
section = self._name
stage_pool = self.pool.get('crm.case.stage')
model = self._name
for case in self.browse(cr, uid, ids, context):
if section in s:
st = not context.get('force_domain', False) and case.stage_id.id or False
s[section] = dict([(v, k) for (k, v) in s[section].iteritems()])
if st in s[section]:
data = {'stage_id': s[section][st]}
if s[section][st]:
stage = stage_pool.browse(cr, uid, s[section][st], context=context)
if stage.on_change:
data.update({'probability': stage.probability})
self.write(cr, uid, [case.id], data)
prev_stage = False
data = {}
domain = [('object_id.model', '=', model)]
if case.section_id and case.section_id.stage_ids:
domain.append(('id', 'in', map(lambda x: x.id, case.section_id.stage_ids)))
stages = stage_pool.search(cr, uid, domain, order='sequence')
index = 0
if case.stage_id and case.stage_id.id in stages:
index = stages.index(case.stage_id.id)
if index == 0:
return False
else:
prev_stage = stages[index - 1]
if prev_stage:
data = {'stage_id': prev_stage}
stage = stage_pool.browse(cr, uid, prev_stage, context=context)
if stage.on_change:
data.update({'probability': stage.probability})
self.write(cr, uid, [case.id], data, context=context)
return True
def onchange_partner_id(self, cr, uid, ids, part, email=False):
@ -492,6 +475,43 @@ class crm_case(object):
return res
class crm_case_stage(osv.osv):
""" Stage of case """
_name = "crm.case.stage"
_description = "Stage of case"
_rec_name = 'name'
_order = "sequence"
_columns = {
'name': fields.char('Stage Name', size=64, required=True, translate=True),
'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of case stages."),
'object_id': fields.many2one('ir.model', 'Object Name'),
'probability': fields.float('Probability (%)', required=True, help="This percentage depicts the default/average probability of the Case for this stage to be a success"),
'on_change': fields.boolean('Change Probability Automatically', \
help="Change Probability on next and previous stages."),
'requirements': fields.text('Requirements')
}
def _find_object_id(self, cr, uid, context=None):
"""Finds id for case object
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param context: A standard dictionary for contextual values
"""
object_id = context and context.get('object_id', False) or False
ids = self.pool.get('ir.model').search(cr, uid, [('model', '=', object_id)])
return ids and ids[0]
_defaults = {
'sequence': lambda *args: 1,
'probability': lambda *args: 0.0,
'object_id' : _find_object_id
}
crm_case_stage()
class crm_case_section(osv.osv):
"""Sales Team"""
@ -517,7 +537,8 @@ class crm_case_section(osv.osv):
'child_ids': fields.one2many('crm.case.section', 'parent_id', 'Child Teams'),
'resource_calendar_id': fields.many2one('resource.calendar', "Resource's Calendar"),
'note': fields.text('Description'),
'working_hours': fields.float('Working Hours', digits=(16,2 )),
'working_hours': fields.float('Working Hours', digits=(16,2 )),
'stage_ids':fields.many2many('crm.case.stage', 'section_stage_rel', 'section_id', 'stage_id', 'Stages'),
}
_defaults = {
@ -619,43 +640,6 @@ class crm_case_resource_type(osv.osv):
crm_case_resource_type()
class crm_case_stage(osv.osv):
""" Stage of case """
_name = "crm.case.stage"
_description = "Stage of case"
_rec_name = 'name'
_order = "sequence"
_columns = {
'name': fields.char('Stage Name', size=64, required=True, translate=True),
'section_id': fields.many2one('crm.case.section', 'Sales Team'),
'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of case stages."),
'object_id': fields.many2one('ir.model', 'Object Name'),
'probability': fields.float('Probability (%)', required=True, help="This percentage depicts the default/average probability of the Case for this stage to be a success"),
'on_change': fields.boolean('Change Probability Automatically', \
help="Change Probability on next and previous stages."),
'requirements': fields.text('Requirements')
}
def _find_object_id(self, cr, uid, context=None):
"""Finds id for case object
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param context: A standard dictionary for contextual values
"""
object_id = context and context.get('object_id', False) or False
ids = self.pool.get('ir.model').search(cr, uid, [('model', '=', object_id)])
return ids and ids[0]
_defaults = {
'sequence': lambda *args: 1,
'probability': lambda *args: 0.0,
'object_id' : _find_object_id
}
crm_case_stage()
def _links_get(self, cr, uid, context=None):
"""Gets links value for reference field
@param self: The object pointer

View File

@ -8,7 +8,6 @@
<field name="name">New</field>
<field eval="'10'" name="probability"/>
<field eval="'1'" name="sequence"/>
<field name="section_id" ref="section_sales_department"/>
<field name="object_id" search="[('model','=','crm.lead')]" model="ir.model"/>
</record>
@ -16,7 +15,6 @@
<field name="name">Qualification</field>
<field eval="'20'" name="probability"/>
<field eval="'2'" name="sequence"/>
<field name="section_id" ref="section_sales_department"/>
<field name="object_id" search="[('model','=','crm.lead')]" model="ir.model"/>
</record>
@ -24,7 +22,6 @@
<field name="name">Proposition</field>
<field eval="'40'" name="probability"/>
<field eval="'3'" name="sequence"/>
<field name="section_id" ref="section_sales_department"/>
<field name="object_id" search="[('model','=','crm.lead')]" model="ir.model"/>
</record>
@ -32,7 +29,6 @@
<field name="name">Negotiation</field>
<field eval="'60'" name="probability"/>
<field eval="'4'" name="sequence"/>
<field name="section_id" ref="section_sales_department"/>
<field name="object_id" search="[('model','=','crm.lead')]" model="ir.model"/>
</record>
@ -40,7 +36,6 @@
<field name="name">Win</field>
<field eval="'100'" name="probability"/>
<field eval="'5'" name="sequence"/>
<field name="section_id" ref="section_sales_department"/>
<field name="object_id" search="[('model','=','crm.lead')]" model="ir.model"/>
</record>
@ -48,10 +43,15 @@
<field name="name">Lost</field>
<field eval="'0'" name="probability"/>
<field eval="'6'" name="sequence"/>
<field name="section_id" ref="section_sales_department"/>
<field name="object_id" search="[('model','=','crm.lead')]" model="ir.model"/>
</record>
<record model="crm.case.section" id="section_sales_department">
<field name="name">Sales Department</field>
<field name="code">Sales</field>
<field name="stage_ids" eval="[(4, ref('stage_lead1')), (4, ref('stage_lead2')), (4, ref('stage_lead3')), (4, ref('stage_lead4')), (4, ref('stage_lead5')), (4, ref('stage_lead6'))]"/>
</record>
<!-- CASE CATEGORY2(category2_id) -->
<record model="crm.case.resource.type" id="type_lead1">
<field name="name">Telesales</field>

View File

@ -55,8 +55,7 @@
<newline />
<field name="section_id" widget="selection" />
<field name="user_id" />
<field name="stage_id"
domain="[('section_id','=',section_id), ('section_id','=',False), ('object_id.model', '=', 'crm.lead')]" />
<field name="stage_id" readonly="1"/>
<group col="2" colspan="1">
<button name="stage_previous" string="Previous"
states="open,pending,draft" type="object"
@ -235,7 +234,7 @@
<field name="referred" invisible="1"/>
<field name="channel_id" invisible="1"/>
<field name="stage_id" />
<field name="stage_id" readonly="1"/>
<button name="stage_previous" string="Previous Stage"
states="open,pending" type="object" icon="gtk-go-back" />
<button name="stage_next" string="Next Stage"

View File

@ -14,8 +14,9 @@
<label string="Stage:" align="1.0"/>
<group colspan="1" col="4">
<field name="stage_id" nolabel="1"
on_change="onchange_stage_id(stage_id)"
domain="['|',('section_id','=',section_id),('section_id','=',False),('object_id.model', '=', 'crm.lead')]" />
on_change="onchange_stage_id(stage_id)"
domain="[('object_id.model', '=', 'crm.lead')]"
readonly="1" />
<button name="stage_previous"
states="open,pending" type="object"
icon="gtk-go-back" string="" />

View File

@ -16,23 +16,5 @@
<field name="object_id" search="[('model','=','crm.phonecall')]" model="ir.model"/>
</record>
<!--
Case Stage
-->
<record model="crm.case.stage" id="stage_phone1">
<field name="name">Planned</field>
<field name="section_id" ref="section_sales_department"/>
<field name="object_id" search="[('model','=','crm.phonecall')]" model="ir.model"/>
</record>
<record model="crm.case.stage" id="stage_phone2">
<field name="name">Held</field>
<field name="section_id" ref="section_sales_department"/>
<field name="object_id" search="[('model','=','crm.phonecall')]" model="ir.model"/>
</record>
<record model="crm.case.stage" id="stage_phone3">
<field name="name">Not Held</field>
<field name="section_id" ref="section_sales_department"/>
<field name="object_id" search="[('model','=','crm.phonecall')]" model="ir.model"/>
</record>
</data>
</openerp>

View File

@ -16,7 +16,6 @@
<field eval="&quot;(726) 782-0636&quot;" name="partner_mobile"/>
<field eval="1" name="active"/>
<field name="categ_id" ref="crm.categ_phone1"/>
<field name="stage_id" ref="crm.stage_phone1"/>
<field eval="&quot;(769) 703-274&quot;" name="partner_phone"/>
<field eval="2.3" name="duration"/>
</record>
@ -32,7 +31,6 @@
<field eval="&quot;(392) 895-7917&quot;" name="partner_mobile"/>
<field eval="1" name="active"/>
<field name="categ_id" ref="crm.categ_phone1"/>
<field name="stage_id" ref="crm.stage_phone2"/>
<field eval="&quot;(956) 293-2595&quot;" name="partner_phone"/>
<field eval="1.5" name="duration"/>
</record>
@ -48,7 +46,6 @@
<field eval="&quot;(820) 167-3208&quot;" name="partner_mobile"/>
<field eval="1" name="active"/>
<field name="categ_id" ref="crm.categ_phone1"/>
<field name="stage_id" ref="crm.stage_phone3"/>
<field eval="&quot;(079) 681-2139&quot;" name="partner_phone"/>
<field eval="&quot;contact@tecsas.fr&quot;" name="email_from"/>
<field eval="5.0" name="duration"/>
@ -64,7 +61,6 @@
<field eval="&quot;(077) 582-4035&quot;" name="partner_mobile"/>
<field eval="1" name="active"/>
<field name="categ_id" ref="crm.categ_phone2"/>
<field name="stage_id" ref="crm.stage_phone1"/>
<field eval="&quot;(514) 698-4118&quot;" name="partner_phone"/>
<field eval="3.45" name="duration"/>
</record>
@ -80,7 +76,6 @@
<field eval="&quot;(333) 715-1450&quot;" name="partner_mobile"/>
<field eval="1" name="active"/>
<field name="categ_id" ref="crm.categ_phone2"/>
<field name="stage_id" ref="crm.stage_phone2"/>
<field eval="&quot;(855) 924-4364&quot;" name="partner_phone"/>
<field eval="2.08" name="duration"/>
</record>
@ -96,7 +91,6 @@
<field eval="&quot;(468) 017-2684&quot;" name="partner_mobile"/>
<field eval="time.strftime('%Y-%m-28 14:15:30')" name="date"/>
<field name="categ_id" ref="crm.categ_phone2"/>
<field name="stage_id" ref="crm.stage_phone3"/>
<field eval="&quot;(373) 907-1009&quot;" name="partner_phone"/>
<field eval="&quot;info@opensides.be&quot;" name="email_from"/>
<field eval="8.56" name="duration"/>

View File

@ -48,6 +48,10 @@
<separator string="Team Members" colspan="4"/>
<field name="member_ids" nolabel="1" colspan="4"/>
</page>
<page string="Stages">
<separator string="Select stages for this Sales Team" colspan="4"/>
<field name="stage_ids" colspan="4" nolabel="1"/>
</page>
<page string="Notes">
<field name="note" select="1" colspan="4" nolabel="1"/>
</page>
@ -97,8 +101,6 @@
<field name="sequence"/>
<field name="name"/>
<field name="probability"/>
<field name="section_id"/>
</tree>
</field>
</record>
@ -113,7 +115,6 @@
<form string="Stage">
<separator string="Stage Definition" colspan="4"/>
<field name="name" select="1"/>
<field name="section_id" select="1"/>
<field name="object_id" invisible="1" />
<field name="sequence"/>
<field name="probability"/>

View File

@ -101,9 +101,7 @@ class crm_lead_report(osv.osv):
'probable_revenue': fields.float('Probable Revenue', digits=(16,2),readonly=True),
'categ_id': fields.many2one('crm.case.categ', 'Category',\
domain="['|',('section_id','=',False),('section_id','=',section_id)]" , readonly=True),
'stage_id': fields.many2one ('crm.case.stage', 'Stage', \
domain="['|',('section_id','=',False),('section_id','=',section_id),\
('object_id.model', '=', 'crm.lead')]", readonly=True),
'stage_id': fields.many2one ('crm.case.stage', 'Stage', readonly=True, domain="('object_id.model', '=', 'crm.lead')]"),
'partner_id': fields.many2one('res.partner', 'Partner' , readonly=True),
'opening_date': fields.date('Opening Date', readonly=True),
'creation_date': fields.date('Creation Date', readonly=True),

View File

@ -70,7 +70,7 @@ class crm_claim(crm.crm_case, osv.osv):
'partner_name': fields.char("Employee's Name", size=64),
'partner_mobile': fields.char('Mobile', size=32),
'partner_phone': fields.char('Phone', size=32),
'stage_id': fields.many2one ('crm.case.stage', 'Stage'),
'stage_id': fields.many2one ('crm.case.stage', 'Stage', domain="('object_id.model', '=', 'crm.claim')]"),
'probability': fields.float('Probability (%)'),
'state': fields.selection(crm.AVAILABLE_STATES, 'State', size=16, readonly=True,
help='The state is set to \'Draft\', when a case is created.\

View File

@ -71,6 +71,11 @@
<field name="section_id" ref="crm.section_sales_department"/>
<field name="object_id" search="[('model','=','crm.claim')]" model="ir.model"/>
</record>
<record model="crm.case.section" id="crm.section_sales_department">
<field name="name">Sales Department</field>
<field name="code">Sales</field>
<field name="stage_ids" eval="[(4, ref('stage_claim1')), (4, ref('stage_claim2')), (4, ref('stage_claim3')), (4, ref('stage_claim4')), (4, ref('stage_claim5'))]"/>
</record>
</data>
</openerp>

View File

@ -109,9 +109,9 @@
<field name="section_id" widget="selection"/>
<label string="Stage: " align="1.0"/>
<group colspan="1" col="3">
<field name="stage_id" nolabel="1"
<field name="stage_id" nolabel="1" readonly="1"
on_change="onchange_stage_id(stage_id)"
domain="[('section_id','=',section_id), ('object_id.model', '=', 'crm.claim')]" />
domain="[('object_id.model', '=', 'crm.claim')]" />
<button name="stage_previous" string="" type="object" icon="gtk-go-back" />
<button icon="gtk-go-forward" string="" name="stage_next" type="object"/>
</group>

View File

@ -62,9 +62,7 @@ class crm_claim_report(osv.osv):
'create_date': fields.datetime('Create Date', readonly=True),
'day': fields.char('Day', size=128, readonly=True),
'delay_close': fields.float('Delay to close', digits=(16,2),readonly=True, group_operator="avg",help="Number of Days to close the case"),
'stage_id': fields.many2one ('crm.case.stage', 'Stage', \
domain="[('section_id','=',section_id),\
('object_id.model', '=', 'crm.claim')]", readonly=True),
'stage_id': fields.many2one ('crm.case.stage', 'Stage', readonly=True),
'categ_id': fields.many2one('crm.case.categ', 'Category',\
domain="[('section_id','=',section_id),\
('object_id.model', '=', 'crm.claim')]", readonly=True),

View File

@ -61,9 +61,7 @@ class crm_fundraising(crm.crm_case, osv.osv):
'partner_name2': fields.char('Employee Email', size=64),
'partner_phone': fields.char('Phone', size=32),
'partner_mobile': fields.char('Mobile', size=32),
'stage_id': fields.many2one ('crm.case.stage', 'Stage', \
domain="[('section_id','=',section_id),\
('object_id.model', '=', 'crm.fundraising')]"),
'stage_id': fields.many2one ('crm.case.stage', 'Stage', domain="('object_id.model', '=', 'crm.fundraising')]"),
'type_id': fields.many2one('crm.case.resource.type', 'Campaign', \
domain="[('section_id','=',section_id)]"),
'duration': fields.float('Duration'),

View File

@ -89,7 +89,7 @@
<field name="user_id" string="Responsible"/>
<field name="date"/>
<field name="categ_id" select="1" widget="selection" domain="[('object_id.model', '=', 'crm.fundraising')]"/>
<field name="type_id" string="Payment Mode" select="1" widget="selection" domain="[('object_id.model', '=', 'crm.fundraising')]"/>
<field name="type_id" string="Payment Mode" select="1" widget="selection"/>
</group>
<notebook colspan="4">
<page string="Funds">

View File

@ -63,9 +63,7 @@ class crm_lead_report_assign(osv.osv):
'probable_revenue': fields.float('Probable Revenue', digits=(16,2),readonly=True),
'categ_id': fields.many2one('crm.case.categ', 'Category',\
domain="[('section_id','=',section_id)]" , readonly=True),
'stage_id': fields.many2one ('crm.case.stage', 'Stage', \
domain="[('section_id','=',section_id),\
('object_id.model', '=', 'crm.lead')]", readonly=True),
'stage_id': fields.many2one ('crm.case.stage', 'Stage', domain="('object_id.model', '=', 'crm.lead')]"),
'partner_id': fields.many2one('res.partner', 'Customer' , readonly=True),
'opening_date': fields.date('Opening Date', readonly=True),
'creation_date': fields.date('Creation Date', readonly=True),

View File

@ -9,11 +9,11 @@
<field eval="time.strftime('%Y-%m-%d', time.localtime(time.mktime(time.localtime()[0:2] + (0,)*7)-1))" name="date_to"/>
</record>
<record id="sheet1" model="hr_timesheet_sheet.sheet">
<!-- record id="sheet1" model="hr_timesheet_sheet.sheet">
<field name="name">Sheet 1</field>
<field name="user_id" ref="base.user_root"/>
<field eval="time.strftime('%Y-%m-%d')" name="date_current"/>
</record>
</record-->
</data>
</openerp>

View File

@ -68,7 +68,7 @@
<field name="user_id"/>
<field name="assigned_to" />
<group colspan="2" col="4">
<field name="stage_id" on_change="onchange_stage_id(stage_id)" domain="[('object_id.model', '=', 'project.issue')]" widget="selection"/>
<field name="stage_id" on_change="onchange_stage_id(stage_id)" domain="[('object_id.model', '=', 'project.issue')]" widget="selection" readonly="1"/>
<button icon="gtk-go-back" string="" name="stage_previous" type="object"/>
<button icon="gtk-go-forward" string="" name="stage_next" type="object"/>
</group>