[IMP] removing res.partner.event and som segmentation
bzr revid: fp@tinyerp.com-20120604171042-thc4lksih1c2ac8m
This commit is contained in:
@@ -1,66 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import time
|
||||
|
||||
def som(cr, uid, partner_id, args):
|
||||
"""
|
||||
@param cr: the current row, from the database cursor,
|
||||
@param uid: the current user’s ID for security checks
|
||||
"""
|
||||
|
||||
result = args['som_interval_default']
|
||||
max = args['som_interval_max'] or 4
|
||||
factor = args['som_interval_decrease']
|
||||
date_start=time.time() - args['som_interval']*3600*24*max
|
||||
for i in range(max):
|
||||
next_date = date_start + args['som_interval']*3600*24
|
||||
cr.execute(
|
||||
'''
|
||||
select s.factor from res_partner_event e
|
||||
left join res_partner_som s
|
||||
on (e.som=s.id) where partner_id=%s and date>=%s and date<%s''',
|
||||
(partner_id,
|
||||
time.strftime('%Y-%m-%d', time.gmtime(date_start)),
|
||||
time.strftime('%Y-%m-%d', time.gmtime(next_date))))
|
||||
|
||||
soms = cr.fetchall()
|
||||
if len(soms):
|
||||
c = 0
|
||||
nbr = 0.0
|
||||
for som in soms:
|
||||
if som[0]:
|
||||
c+=1
|
||||
nbr+=som[0]
|
||||
if c:
|
||||
avg = nbr/c
|
||||
else:
|
||||
avg = result
|
||||
result = result*(1-factor) + (avg*factor)
|
||||
else:
|
||||
avg = args['som_interval_default']
|
||||
date_start = next_date
|
||||
return result
|
||||
|
||||
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -21,9 +21,6 @@
|
||||
|
||||
from osv import fields,osv,orm
|
||||
|
||||
import crm_operators
|
||||
|
||||
|
||||
class crm_segmentation(osv.osv):
|
||||
'''
|
||||
A segmentation is a tool to automatically assign categories on partners.
|
||||
@@ -45,25 +42,11 @@ added to partners that match the segmentation criterions after computation.'),
|
||||
'partner_id': fields.integer('Max Partner ID processed'),
|
||||
'segmentation_line': fields.one2many('crm.segmentation.line', \
|
||||
'segmentation_id', 'Criteria', required=True),
|
||||
'som_interval': fields.integer('Days per Period', help="A period is the average number of days between two cycle of sale or purchase for this segmentation.\
|
||||
\nIt's mainly used to detect if a partner has not purchased or buy for a too long time, \
|
||||
\nso we suppose that his state of mind has decreased because he probably bought goods to another supplier. \
|
||||
\nUse this functionality for recurring businesses."),
|
||||
'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 bought) 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('Use The Sales Purchase Rules', 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,
|
||||
'state': lambda *a: 'not running',
|
||||
'som_interval_max': lambda *a: 3,
|
||||
'som_interval_decrease': lambda *a: 0.8,
|
||||
'som_interval_default': lambda *a: 0.5
|
||||
}
|
||||
|
||||
def process_continue(self, cr, uid, ids, start=False):
|
||||
@@ -132,7 +115,7 @@ class crm_segmentation_line(osv.osv):
|
||||
_columns = {
|
||||
'name': fields.char('Rule Name', size=64, required=True),
|
||||
'segmentation_id': fields.many2one('crm.segmentation', 'Segmentation'),
|
||||
'expr_name': fields.selection([('sale','Sale Amount'),('som','State of Mind'),\
|
||||
'expr_name': fields.selection([('sale','Sale Amount'),
|
||||
('purchase','Purchase Amount')], 'Control Variable', size=64, required=True),
|
||||
'expr_operator': fields.selection([('<','<'),('=','='),('>','>')], 'Operator', required=True),
|
||||
'expr_value': fields.float('Value', required=True),
|
||||
@@ -157,12 +140,7 @@ class crm_segmentation_line(osv.osv):
|
||||
for l in lst:
|
||||
cr.execute('select * from ir_module_module where name=%s and state=%s', ('account','installed'))
|
||||
if cr.fetchone():
|
||||
if l['expr_name']=='som':
|
||||
datas = self.pool.get('crm.segmentation').read(cr, uid, [l['segmentation_id'][0]],
|
||||
['som','som_interval','som_interval_max',\
|
||||
'som_interval_default', 'som_interval_decrease'])
|
||||
value = crm_operators.som(cr, uid, partner_id, datas[0])
|
||||
elif l['expr_name']=='sale':
|
||||
if l['expr_name']=='sale':
|
||||
cr.execute('SELECT SUM(l.price_unit * l.quantity) ' \
|
||||
'FROM account_invoice_line l, account_invoice i ' \
|
||||
'WHERE (l.invoice_id = i.id) ' \
|
||||
|
||||
@@ -990,29 +990,6 @@ class sale_order(osv.osv):
|
||||
self.delivery_end_send_note(cr, uid, [order.id], context=context)
|
||||
return True
|
||||
|
||||
def _log_event(self, cr, uid, ids, factor=0.7, name='Open Order'):
|
||||
invs = self.read(cr, uid, ids, ['date_order', 'partner_id', 'amount_untaxed'])
|
||||
for inv in invs:
|
||||
part = inv['partner_id'] and inv['partner_id'][0]
|
||||
pr = inv['amount_untaxed'] or 0.0
|
||||
partnertype = 'customer'
|
||||
eventtype = 'sale'
|
||||
event = {
|
||||
'name': 'Order: '+name,
|
||||
'som': False,
|
||||
'description': 'Order '+str(inv['id']),
|
||||
'document': '',
|
||||
'partner_id': part,
|
||||
'date': time.strftime(DEFAULT_SERVER_DATE_FORMAT),
|
||||
'user_id': uid,
|
||||
'partner_type': partnertype,
|
||||
'probability': 1.0,
|
||||
'planned_revenue': pr,
|
||||
'planned_cost': 0.0,
|
||||
'type': eventtype
|
||||
}
|
||||
self.pool.get('res.partner.event').create(cr, uid, event)
|
||||
|
||||
def has_stockable_products(self, cr, uid, ids, *args):
|
||||
for order in self.browse(cr, uid, ids):
|
||||
for order_line in order.order_line:
|
||||
|
||||
Reference in New Issue
Block a user