modification of the base segmentation tool, in order to fetch the current criteria and the merge with the crm_profiling module.
- new design of the crm_segmentation view - correction of the function process_continue - add a new field, to choose if the basic options are enabled bzr revid: qdp-96e1d36a0b494da0803bb8e537a787107e1b9593
This commit is contained in:
parent
cf067054a4
commit
154b0de66b
|
@ -49,6 +49,7 @@ class crm_segmentation(osv.osv):
|
|||
'som_interval_max': fields.integer('Max Interval', help="The computation is made on all events that occured during this interval, the past X periods."),
|
||||
'som_interval_decrease': fields.float('Decrease (0>1)', help="If the partner has not purchased (or buied) during a period, decrease the state of mind by this factor. It\'s a multiplication"),
|
||||
'som_interval_default': fields.float('Default (0=None)', help="Default state of mind for period preceeding the 'Max Interval' computation. This is the starting state of mind by default if the partner has no event."),
|
||||
'sales_purchase_active': fields.boolean('Optionnal tab active', help='Check if you want to use this tab as part of the segmentation rule. If not checked, the criteria beneath will be ignored')
|
||||
}
|
||||
_defaults = {
|
||||
'partner_id': lambda *a: 0,
|
||||
|
@ -59,32 +60,63 @@ class crm_segmentation(osv.osv):
|
|||
}
|
||||
|
||||
def process_continue(self, cr, uid, ids, start=False):
|
||||
categs = self.read(cr,uid,ids,['categ_id','exclusif','partner_id'])
|
||||
categs = self.read(cr,uid,ids,['categ_id','exclusif','partner_id', 'sales_purchase_active', 'profiling_active'])
|
||||
for categ in categs:
|
||||
if start:
|
||||
if categ['exclusif']:
|
||||
cr.execute('delete from res_partner_category_rel where category_id=%d', (categ['categ_id'][0],))
|
||||
id = categ['id']
|
||||
cr.execute('select id from crm_segmentation_line where segmentation_id=%d', (id,))
|
||||
line_ids = [x[0] for x in cr.fetchall()]
|
||||
cr.execute('select id from res_partner order by id limit 100 offset %d', (categ['partner_id'],))
|
||||
partners = cr.fetchall()
|
||||
ok = []
|
||||
for (pid,) in partners:
|
||||
if self.pool.get('crm.segmentation.line').test(cr, uid, line_ids, pid):
|
||||
ok.append(pid)
|
||||
|
||||
for partner_id in ok:
|
||||
id = categ['id']
|
||||
|
||||
cr.execute('select id from res_partner order by id ')
|
||||
partners = [x[0] for x in cr.fetchall()]
|
||||
|
||||
if categ['sales_purchase_active']:
|
||||
to_remove_list=[]
|
||||
cr.execute('select id from crm_segmentation_line where segmentation_id=%d', (id,))
|
||||
line_ids = [x[0] for x in cr.fetchall()]
|
||||
|
||||
for pid in partners:
|
||||
if (not self.pool.get('crm.segmentation.line').test(cr, uid, line_ids, pid)):
|
||||
to_remove_list.append(pid)
|
||||
for pid in to_remove_list:
|
||||
partners.remove(pid)
|
||||
|
||||
for partner_id in partners:
|
||||
cr.execute('insert into res_partner_category_rel (category_id,partner_id) values (%d,%d)', (categ['categ_id'][0],partner_id))
|
||||
cr.commit()
|
||||
|
||||
if len(partners)==100:
|
||||
self.write(cr, uid, [id], {'partner_id':categ['partner_id']+100})
|
||||
self.process_continue(cr, uid, [id])
|
||||
self.write(cr, uid, [id], {'state':'not running', 'partner_id':0})
|
||||
cr.commit()
|
||||
return True
|
||||
|
||||
# def process_continue(self, cr, uid, ids, start=False):
|
||||
# categs = self.read(cr,uid,ids,['categ_id','exclusif','partner_id'])
|
||||
# for categ in categs:
|
||||
# if start:
|
||||
# if categ['exclusif']:
|
||||
# cr.execute('delete from res_partner_category_rel where category_id=%d', (categ['categ_id'][0],))
|
||||
# id = categ['id']
|
||||
# cr.execute('select id from crm_segmentation_line where segmentation_id=%d', (id,))
|
||||
# line_ids = [x[0] for x in cr.fetchall()]
|
||||
# cr.execute('select id from res_partner order by id limit 100 offset %d', (categ['partner_id'],))
|
||||
# partners = cr.fetchall()
|
||||
# ok = []
|
||||
# for (pid,) in partners:
|
||||
# if self.pool.get('crm.segmentation.line').test(cr, uid, line_ids, pid):
|
||||
# ok.append(pid)
|
||||
#
|
||||
# for partner_id in ok:
|
||||
# cr.execute('insert into res_partner_category_rel (category_id,partner_id) values (%d,%d)', (categ['categ_id'][0],partner_id))
|
||||
# cr.commit()
|
||||
#
|
||||
# if len(partners)==100:
|
||||
# self.write(cr, uid, [id], {'partner_id':categ['partner_id']+100})
|
||||
# self.process_continue(cr, uid, [id])
|
||||
# self.write(cr, uid, [id], {'state':'not running', 'partner_id':0})
|
||||
# cr.commit()
|
||||
# return True
|
||||
|
||||
def process_stop(self, cr, uid, ids, *args):
|
||||
return self.write(cr, uid, ids, {'state':'not running', 'partner_id':0})
|
||||
|
||||
|
|
|
@ -483,26 +483,30 @@
|
|||
<field name="arch" type="xml">
|
||||
<form string="Partner Segmentation">
|
||||
<notebook>
|
||||
<page string="Segmentation Parameters">
|
||||
<separator string="Segmentation Description" colspan="4"/>
|
||||
<field name="name" select="1"/>
|
||||
<field name="exclusif"/>
|
||||
<field name="description" select="2" colspan="4"/>
|
||||
<field name="categ_id" select="2" colspan="4"/>
|
||||
<separator string="Segmentation Test" colspan="4"/>
|
||||
<field name="segmentation_line" widget="one2many_list" colspan="4"/>
|
||||
<page string="Segmentation">
|
||||
<field name="state"/>
|
||||
<group col="3" colspan="2">
|
||||
<button name="process_start" states="not running" string="Compute Segmentation" type="object"/>
|
||||
<button name="process_stop" states="running" string="Stop Process" type="object"/>
|
||||
<button name="process_continue" states="running" string="Continue Process" type="object"/>
|
||||
</group>
|
||||
</page><page string="Computation Parameters">
|
||||
<separator string="Segmentation Description" colspan="4"/>
|
||||
<field name="name" select="1"/>
|
||||
<field name="exclusif"/>
|
||||
<newline/>
|
||||
<field name="categ_id" select="2" colspan="2"/>
|
||||
<newline/>
|
||||
<field name="description" select="2" colspan="4"/>
|
||||
</page>
|
||||
<page string="Sales Purchase">
|
||||
<field name="sales_purchase_active"/>
|
||||
<separator string="State of Mind Computation" colspan="4"/>
|
||||
<field name="som_interval"/>
|
||||
<field name="som_interval_max"/>
|
||||
<field name="som_interval_decrease"/>
|
||||
<field name="som_interval_default"/>
|
||||
<separator string="Segmentation Test" colspan="4"/>
|
||||
<field name="segmentation_line" widget="one2many_list" colspan="4"/>
|
||||
</page>
|
||||
</notebook>
|
||||
</form>
|
||||
|
|
Loading…
Reference in New Issue