2010-05-14 14:36:02 +00:00
|
|
|
# -*- 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
|
2010-05-21 15:50:09 +00:00
|
|
|
import base64
|
2010-05-14 14:36:02 +00:00
|
|
|
from datetime import datetime
|
|
|
|
from dateutil.relativedelta import relativedelta
|
|
|
|
|
|
|
|
from osv import fields, osv
|
2010-05-21 15:50:09 +00:00
|
|
|
import netsvc
|
2010-05-25 14:26:20 +00:00
|
|
|
import tools
|
2010-05-14 14:36:02 +00:00
|
|
|
|
|
|
|
_intervalTypes = {
|
|
|
|
'hours': lambda interval: relativedelta(hours=interval),
|
|
|
|
'days': lambda interval: relativedelta(days=interval),
|
|
|
|
'months': lambda interval: relativedelta(months=interval),
|
|
|
|
'years': lambda interval: relativedelta(years=interval),
|
|
|
|
}
|
|
|
|
|
|
|
|
class marketing_campaign(osv.osv): #{{{
|
|
|
|
_name = "marketing.campaign"
|
2010-05-19 18:32:32 +00:00
|
|
|
_description = "Marketing Campaign"
|
2010-05-14 14:36:02 +00:00
|
|
|
|
|
|
|
_columns = {
|
2010-05-18 10:42:08 +00:00
|
|
|
'name': fields.char('Name', size=64, required=True),
|
2010-05-26 08:23:28 +00:00
|
|
|
'object_id': fields.many2one('ir.model', 'Objects', required=True,
|
|
|
|
help="Choose the Object on which you want \
|
|
|
|
this campaign to be run"),
|
2010-05-14 14:36:02 +00:00
|
|
|
'mode':fields.selection([('test', 'Test'),
|
2010-05-26 08:23:28 +00:00
|
|
|
('test_realtime', 'Realtime'),
|
2010-05-14 14:36:02 +00:00
|
|
|
('manual', 'Manual'),
|
|
|
|
('active', 'Active')],
|
2010-05-25 14:26:20 +00:00
|
|
|
'Mode', required=True),
|
2010-05-14 14:36:02 +00:00
|
|
|
'state': fields.selection([('draft', 'Draft'),
|
|
|
|
('running', 'Running'),
|
|
|
|
('done', 'Done'),
|
|
|
|
('cancelled', 'Cancelled'),],
|
2010-05-19 06:44:15 +00:00
|
|
|
'State',),
|
2010-05-17 09:41:49 +00:00
|
|
|
'activity_ids': fields.one2many('marketing.campaign.activity',
|
|
|
|
'campaign_id', 'Activities'),
|
2010-05-26 08:23:28 +00:00
|
|
|
'fixed_cost': fields.float('Fixed Cost', help="The fixed cost is cost\
|
|
|
|
you required for the campaign"),
|
2010-05-14 14:36:02 +00:00
|
|
|
|
|
|
|
}
|
2010-05-21 09:53:53 +00:00
|
|
|
|
|
|
|
_defaults = {
|
|
|
|
'state': lambda *a: 'draft',
|
2010-05-25 14:26:20 +00:00
|
|
|
'mode': lambda *a: 'test',
|
2010-05-21 09:53:53 +00:00
|
|
|
}
|
2010-05-25 14:26:20 +00:00
|
|
|
|
2010-05-21 09:53:53 +00:00
|
|
|
def state_running_set(self, cr, uid, ids, *args):
|
|
|
|
campaign = self.browse(cr, uid, ids[0])
|
|
|
|
if not campaign.activity_ids :
|
|
|
|
raise osv.except_osv("Error", "There is no associate activitity for the campaign")
|
|
|
|
act_ids = [ act_id.id for act_id in campaign.activity_ids]
|
|
|
|
act_ids = self.pool.get('marketing.campaign.activity').search(cr, uid,
|
|
|
|
[('id', 'in', act_ids), ('start', '=', True)])
|
|
|
|
if not act_ids :
|
|
|
|
raise osv.except_osv("Error", "There is no associate activitity for the campaign")
|
|
|
|
segment_ids = self.pool.get('marketing.campaign.segment').search(cr, uid,
|
|
|
|
[('campaign_id', '=', campaign.id),
|
|
|
|
('state', '=', 'draft')])
|
|
|
|
self.write(cr, uid, ids, {'state': 'running'})
|
|
|
|
return True
|
|
|
|
|
|
|
|
def state_done_set(self, cr, uid, ids, *args):
|
|
|
|
segment_ids = self.pool.get('marketing.campaign.segment').search(cr, uid,
|
|
|
|
[('campaign_id', 'in', ids),
|
|
|
|
('state', '=', 'running')])
|
|
|
|
if segment_ids :
|
|
|
|
raise osv.except_osv("Error", "Camapign cannot be done before all segments are done")
|
|
|
|
self.write(cr, uid, ids, {'state': 'done'})
|
|
|
|
return True
|
|
|
|
|
|
|
|
def state_cancel_set(self, cr, uid, ids, *args):
|
|
|
|
self.write(cr, uid, ids, {'state': 'cancelled'})
|
|
|
|
return True
|
2010-05-14 14:36:02 +00:00
|
|
|
marketing_campaign()#}}}
|
|
|
|
|
|
|
|
class marketing_campaign_segment(osv.osv): #{{{
|
|
|
|
_name = "marketing.campaign.segment"
|
2010-05-19 18:32:32 +00:00
|
|
|
_description = "Campaign Segment"
|
2010-05-14 14:36:02 +00:00
|
|
|
|
|
|
|
_columns = {
|
2010-05-18 10:42:08 +00:00
|
|
|
'name': fields.char('Name', size=64,required=True),
|
|
|
|
'campaign_id': fields.many2one('marketing.campaign', 'Campaign',
|
|
|
|
required=True),
|
2010-05-14 14:36:02 +00:00
|
|
|
'object_id': fields.related('campaign_id','object_id',
|
|
|
|
type='many2one', relation='ir.model',
|
|
|
|
string='Object'),
|
2010-05-26 08:23:28 +00:00
|
|
|
'ir_filter_id': fields.many2one('ir.filters', 'Filter', help=""),
|
2010-05-14 14:36:02 +00:00
|
|
|
'sync_last_date': fields.datetime('Date'),
|
2010-05-21 09:53:53 +00:00
|
|
|
'sync_mode': fields.selection([('create_date', 'Create'),
|
|
|
|
('write_date', 'Write')],
|
2010-05-14 14:36:02 +00:00
|
|
|
'Mode'),
|
|
|
|
'state': fields.selection([('draft', 'Draft'),
|
|
|
|
('running', 'Running'),
|
|
|
|
('done', 'Done'),
|
|
|
|
('cancelled', 'Cancelled')],
|
2010-05-19 06:44:15 +00:00
|
|
|
'State',),
|
2010-05-14 14:36:02 +00:00
|
|
|
'date_run': fields.datetime('Running'),
|
|
|
|
'date_done': fields.datetime('Done'),
|
|
|
|
}
|
2010-05-21 09:53:53 +00:00
|
|
|
|
|
|
|
_defaults = {
|
|
|
|
'state': lambda *a: 'draft',
|
|
|
|
'sync_mode': lambda *a: 'create_date',
|
|
|
|
}
|
|
|
|
|
|
|
|
def state_running_set(self, cr, uid, ids, *args):
|
|
|
|
segment = self.browse(cr, uid, ids[0])
|
2010-05-21 13:46:28 +00:00
|
|
|
curr_date = time.strftime('%Y-%m-%d %H:%M:%S')
|
2010-05-25 14:26:20 +00:00
|
|
|
vals = {'state': 'running'}
|
2010-05-21 09:53:53 +00:00
|
|
|
if not segment.date_run:
|
2010-06-02 14:39:28 +00:00
|
|
|
vals['date_run'] = time.strftime('%Y-%m-%d %H:%M:%S')
|
2010-05-21 13:46:28 +00:00
|
|
|
if not segment.sync_last_date:
|
2010-05-25 14:26:20 +00:00
|
|
|
vals['sync_last_date']=curr_date
|
|
|
|
if not segment.date_done:
|
|
|
|
vals['date_done']= (datetime.now() + _intervalTypes['years'](1) \
|
|
|
|
).strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
self.write(cr, uid, ids, vals)
|
2010-05-21 09:53:53 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
def state_done_set(self, cr, uid, ids, *args):
|
|
|
|
date_done = self.browse(cr, uid, ids[0]).date_done
|
2010-06-02 14:39:28 +00:00
|
|
|
if (date_done > time.strftime('%Y-%m-%d %H:%M:%S')):
|
2010-05-21 09:53:53 +00:00
|
|
|
raise osv.except_osv("Error", "Segment cannot be closed before end date")
|
|
|
|
|
|
|
|
wi_ids = self.pool.get("marketing.campaign.workitem").search(cr, uid,
|
|
|
|
[('state', 'in', ['inprogress', 'todo']),
|
|
|
|
('segment_id', '=', ids[0])])
|
|
|
|
if wi_ids :
|
|
|
|
raise osv.except_osv("Error", "Segment cannot be done before all workitems are processed")
|
|
|
|
self.write(cr, uid, ids, {'state': 'done'})
|
|
|
|
return True
|
|
|
|
|
|
|
|
def state_cancel_set(self, cr, uid, ids, *args):
|
|
|
|
self.write(cr, uid, ids, {'state': 'cancelled'})
|
|
|
|
return True
|
|
|
|
|
|
|
|
def process_segment(self, cr, uid, context={}):
|
|
|
|
segment_ids = self.search(cr, uid, [('state', '=', 'running')])
|
|
|
|
action_date = time.strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
last_action_date = (datetime.now() + _intervalTypes['days'](-1) \
|
|
|
|
).strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
for segment in self.browse(cr, uid, segment_ids):
|
|
|
|
act_ids = self.pool.get('marketing.campaign.activity').search(cr,
|
|
|
|
uid, [('start', '=', True),
|
|
|
|
('campaign_id', '=', segment.campaign_id.id)])
|
|
|
|
if (segment.sync_last_date and \
|
|
|
|
segment.sync_last_date <= action_date )\
|
|
|
|
or not segment.sync_last_date :
|
|
|
|
model_obj = self.pool.get(segment.object_id.model)
|
|
|
|
object_ids = model_obj.search(cr, uid, [
|
|
|
|
(segment.sync_mode, '<=', action_date),
|
|
|
|
(segment.sync_mode, '>=', last_action_date)])
|
|
|
|
for o_ids in model_obj.read(cr, uid, object_ids) :
|
|
|
|
partner_id = 'partner_id' in o_ids and o_ids['partner_id'] \
|
|
|
|
or False
|
2010-05-21 15:50:09 +00:00
|
|
|
if partner_id:
|
|
|
|
for act_id in act_ids:
|
|
|
|
wi_vals = {'segment_id': segment.id,
|
|
|
|
'activity_id': act_id,
|
|
|
|
'date': action_date,
|
|
|
|
'partner_id': partner_id[0],
|
|
|
|
'state': 'todo',
|
|
|
|
}
|
|
|
|
self.pool.get('marketing.campaign.workitem').create(
|
|
|
|
cr, uid, wi_vals)
|
2010-06-02 14:39:28 +00:00
|
|
|
self.write(cr, uid, segment.id, {'sync_last_date':action_date})
|
2010-05-21 09:53:53 +00:00
|
|
|
return True
|
2010-05-14 14:36:02 +00:00
|
|
|
|
|
|
|
marketing_campaign_segment()#}}}
|
|
|
|
|
|
|
|
class marketing_campaign_activity(osv.osv): #{{{
|
|
|
|
_name = "marketing.campaign.activity"
|
2010-05-19 18:32:32 +00:00
|
|
|
_description = "Campaign Activity"
|
2010-05-14 14:36:02 +00:00
|
|
|
|
|
|
|
_columns = {
|
2010-06-02 14:39:28 +00:00
|
|
|
'name': fields.char('Name', size=128, required=True),
|
2010-05-25 14:26:20 +00:00
|
|
|
'campaign_id': fields.many2one('marketing.campaign', 'Campaign',
|
|
|
|
required = True, ondelete='cascade'),
|
2010-05-14 14:36:02 +00:00
|
|
|
'object_id': fields.related('campaign_id','object_id',
|
|
|
|
type='many2one', relation='ir.model',
|
|
|
|
string='Object'),
|
2010-05-26 08:23:28 +00:00
|
|
|
'start': fields.boolean('Start',help= "Its necessary to start activity \
|
|
|
|
before running campaign"),
|
|
|
|
'condition': fields.char('Condition', size=256, required=True,
|
|
|
|
help="Condition that is to be tested before \
|
|
|
|
action is executed"),
|
2010-05-19 07:33:24 +00:00
|
|
|
'type': fields.selection([('email', 'E-mail'),
|
2010-05-14 14:36:02 +00:00
|
|
|
('paper', 'Paper'),
|
|
|
|
('action', 'Action'),
|
|
|
|
('subcampaign', 'Sub-Campaign')],
|
2010-05-21 13:46:28 +00:00
|
|
|
'Type', required=True),
|
2010-06-02 14:39:28 +00:00
|
|
|
'email_template_id': fields.many2one('email.template','Email Template'),
|
2010-05-25 14:26:20 +00:00
|
|
|
'report_id': fields.many2one('ir.actions.report.xml', 'Reports', ),
|
2010-05-26 08:23:28 +00:00
|
|
|
'report_directory_id': fields.many2one('document.directory','Directory',
|
|
|
|
help="Folder is used to store the generated reports"),
|
|
|
|
'server_action_id': fields.many2one('ir.actions.server', string='Action',
|
|
|
|
help= "Describes the action name.\n"
|
|
|
|
"eg:On which object which action to be taken on basis of which condition"),
|
2010-05-14 14:36:02 +00:00
|
|
|
'to_ids': fields.one2many('marketing.campaign.transition',
|
2010-05-25 14:26:20 +00:00
|
|
|
'activity_from_id',
|
2010-05-17 09:41:49 +00:00
|
|
|
'Next Activities'),
|
|
|
|
'from_ids': fields.one2many('marketing.campaign.transition',
|
2010-05-25 14:26:20 +00:00
|
|
|
'activity_to_id',
|
2010-05-17 09:41:49 +00:00
|
|
|
'Previous Activities'),
|
2010-05-19 07:33:24 +00:00
|
|
|
'subcampaign_id': fields.many2one('marketing.campaign', 'Sub-Campaign'),
|
|
|
|
'subcampaign_segment_id': fields.many2one('marketing.campaign.segment',
|
2010-05-14 14:36:02 +00:00
|
|
|
'Sub Campaign Segment'),
|
2010-05-19 06:44:15 +00:00
|
|
|
'variable_cost': fields.float('Variable Cost'),
|
|
|
|
'revenue': fields.float('Revenue')
|
2010-05-14 14:36:02 +00:00
|
|
|
}
|
2010-05-21 09:53:53 +00:00
|
|
|
|
2010-05-25 14:26:20 +00:00
|
|
|
_defaults = {
|
|
|
|
'type': lambda *a: 'email',
|
|
|
|
'condition': lambda *a: 'True',
|
|
|
|
'object_id' : lambda obj, cr, uid, context : context.get('object_id',False),
|
|
|
|
}
|
|
|
|
|
2010-05-18 10:42:08 +00:00
|
|
|
def search(self, cr, uid, args, offset=0, limit=None, order=None,
|
|
|
|
context=None, count=False):
|
|
|
|
if context == None:
|
|
|
|
context = {}
|
|
|
|
if 'segment_id' in context and context['segment_id']:
|
|
|
|
segment_obj = self.pool.get('marketing.campaign.segment').browse(cr,
|
|
|
|
uid, context['segment_id'])
|
|
|
|
act_ids = []
|
|
|
|
for activity in segment_obj.campaign_id.activity_ids:
|
|
|
|
act_ids.append(activity.id)
|
|
|
|
return act_ids
|
|
|
|
return super(marketing_campaign_activity, self).search(cr, uid, args,
|
|
|
|
offset, limit, order, context, count)
|
2010-05-21 15:50:09 +00:00
|
|
|
|
|
|
|
def process(self, cr, uid, act_id, wi_id, context={}):
|
|
|
|
activity = self.browse(cr, uid, act_id)
|
2010-06-02 14:39:28 +00:00
|
|
|
workitem_obj = self.pool.get('marketing.campaign.workitem')
|
2010-05-25 14:26:20 +00:00
|
|
|
workitem = workitem_obj.browse(cr, uid, wi_id)
|
2010-06-02 14:39:28 +00:00
|
|
|
|
2010-05-21 15:50:09 +00:00
|
|
|
if activity.type == 'paper' :
|
|
|
|
service = netsvc.LocalService('report.%s'%activity.report_id.report_name)
|
2010-05-26 08:20:02 +00:00
|
|
|
(report_data, format) = service.create(cr, uid, [], {}, {})
|
2010-05-21 15:50:09 +00:00
|
|
|
attach_vals = {
|
|
|
|
'name': '%s_%s_%s'%(activity.report_id.report_name,
|
|
|
|
activity.name,workitem.partner_id.name),
|
|
|
|
'datas_fname': '%s.%s'%(activity.report_id.report_name,
|
|
|
|
activity.report_id.report_type),
|
|
|
|
'parent_id': activity.report_directory_id.id,
|
|
|
|
'datas': base64.encodestring(report_data),
|
|
|
|
'file_type': format
|
|
|
|
}
|
|
|
|
self.pool.get('ir.attachment').create(cr, uid, attach_vals)
|
2010-05-25 14:26:20 +00:00
|
|
|
elif activity.type == 'email' :
|
|
|
|
context = {}
|
|
|
|
template = activity.email_template_id
|
|
|
|
accounts = template.enforce_from_account
|
|
|
|
if not template.enforce_from_account:
|
|
|
|
return {'error_msg' : "There is no account defined for the email"}
|
|
|
|
if not workitem.partner_id.email:
|
|
|
|
return {'error_msg' : "There is no email defined for the partner"}
|
|
|
|
vals = {
|
2010-06-02 14:39:28 +00:00
|
|
|
'email_from': tools.ustr(accounts.name) + "<" + tools.ustr(accounts.email_id) + ">",
|
|
|
|
'email_to': workitem.partner_id.email,
|
|
|
|
'subject': template.def_subject,
|
|
|
|
'body_text': template.def_body_text,
|
|
|
|
'body_html': template.def_body_html,
|
|
|
|
'account_id':accounts.id,
|
2010-05-25 14:26:20 +00:00
|
|
|
'state':'na',
|
|
|
|
'mail_type':'multipart/alternative' #Options:'multipart/mixed','multipart/alternative','text/plain','text/html'
|
|
|
|
}
|
|
|
|
# if accounts.use_sign:
|
|
|
|
# signature = self.pool.get('res.users').read(cr, uid, uid, ['signature'], context)['signature']
|
|
|
|
# if signature:
|
|
|
|
# vals['pem_body_text'] = tools.ustr(vals['pem_body_text'] or '') + signature
|
|
|
|
# vals['pem_body_html'] = tools.ustr(vals['pem_body_html'] or '') + signature
|
|
|
|
|
|
|
|
#Create partly the mail and later update attachments
|
2010-06-02 14:39:28 +00:00
|
|
|
mail_id = self.pool.get('email_template.mailbox').create(cr, uid, vals, context)
|
2010-05-25 14:26:20 +00:00
|
|
|
elif activity.type == 'action' :
|
|
|
|
server_obj = self.pool.get('ir.actions.server')
|
|
|
|
server_obj.run(cr, uid, [activity.server_action_id.id], context)
|
|
|
|
#???
|
2010-05-21 15:50:09 +00:00
|
|
|
return True
|
2010-05-14 14:36:02 +00:00
|
|
|
marketing_campaign_activity()#}}}
|
|
|
|
|
|
|
|
class marketing_campaign_transition(osv.osv): #{{{
|
|
|
|
_name = "marketing.campaign.transition"
|
2010-05-19 18:32:32 +00:00
|
|
|
_description = "Campaign Transition"
|
2010-05-25 14:26:20 +00:00
|
|
|
_rec_name = "interval_type"
|
2010-05-14 14:36:02 +00:00
|
|
|
|
|
|
|
_columns = {
|
|
|
|
'activity_from_id': fields.many2one('marketing.campaign.activity',
|
|
|
|
'Source Activity'),
|
|
|
|
'activity_to_id': fields.many2one('marketing.campaign.activity',
|
|
|
|
'Destination Activity'),
|
|
|
|
'interval_nbr': fields.integer('Interval No.'),
|
|
|
|
'interval_type': fields.selection([('hours', 'Hours'), ('days', 'Days'),
|
2010-05-18 10:42:08 +00:00
|
|
|
('months', 'Months'),
|
|
|
|
('years','Years')],'Interval Type')
|
2010-05-14 14:36:02 +00:00
|
|
|
}
|
2010-05-19 06:44:15 +00:00
|
|
|
|
2010-05-19 07:15:52 +00:00
|
|
|
def default_get(self, cr, uid, fields, context={}):
|
|
|
|
value = super(marketing_campaign_transition, self).default_get(cr, uid,
|
|
|
|
fields, context)
|
|
|
|
if context.has_key('type_id'):
|
|
|
|
value[context['type_id']] = context['activity_id']
|
|
|
|
return value
|
|
|
|
|
2010-05-14 14:36:02 +00:00
|
|
|
marketing_campaign_transition() #}}}
|
|
|
|
|
|
|
|
class marketing_campaign_workitem(osv.osv): #{{{
|
|
|
|
_name = "marketing.campaign.workitem"
|
2010-05-19 18:32:32 +00:00
|
|
|
_description = "Campaign Workitem"
|
2010-05-14 14:36:02 +00:00
|
|
|
|
|
|
|
_columns = {
|
2010-05-18 10:42:08 +00:00
|
|
|
'segment_id': fields.many2one('marketing.campaign.segment', 'Segment',
|
|
|
|
required=True),
|
|
|
|
'activity_id': fields.many2one('marketing.campaign.activity','Activity',
|
|
|
|
required=True),
|
2010-05-14 14:36:02 +00:00
|
|
|
'object_id': fields.related('segment_id', 'campaign_id', 'object_id',
|
|
|
|
type='many2one', relation='ir.model',
|
|
|
|
string='Object'),
|
|
|
|
'res_id': fields.integer('Results'),
|
|
|
|
'date': fields.datetime('Execution Date'),
|
2010-05-18 10:42:08 +00:00
|
|
|
'partner_id': fields.many2one('res.partner', 'Partner',required=True),
|
2010-05-14 14:36:02 +00:00
|
|
|
'state': fields.selection([('todo', 'ToDo'), ('inprogress', 'In Progress'),
|
2010-05-19 07:33:24 +00:00
|
|
|
('exception', 'Exception'), ('done', 'Done'),
|
2010-05-25 14:26:20 +00:00
|
|
|
('cancelled', 'Cancelled')], 'State'),
|
|
|
|
|
|
|
|
'error_msg' : fields.text('Error Message')
|
2010-05-14 14:36:02 +00:00
|
|
|
}
|
2010-05-21 09:53:53 +00:00
|
|
|
_defaults = {
|
|
|
|
'state': lambda *a: 'draft',
|
|
|
|
}
|
2010-05-14 14:36:02 +00:00
|
|
|
|
|
|
|
def process_chain(self, cr, uid, workitem_id, context={}):
|
|
|
|
workitem = self.browse(cr, uid, workitem_id)
|
|
|
|
mct_obj = self.pool.get('marketing.campaign.transition')
|
2010-05-21 15:50:09 +00:00
|
|
|
process_to_id = mct_obj.search(cr,uid, [
|
|
|
|
('activity_from_id','=', workitem.activity_id.id)])
|
2010-05-14 14:36:02 +00:00
|
|
|
for mct_id in mct_obj.browse(cr, uid, process_to_id):
|
2010-05-21 15:50:09 +00:00
|
|
|
if mct_id.interval_type and mct_id.interval_nbr :
|
|
|
|
launch_date = (datetime.now() + _intervalTypes[ \
|
|
|
|
mct_id.interval_type](mct_id.interval_nbr) \
|
|
|
|
).strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
launch_date = time.strftime('%Y-%m-%d %H:%M:%S')
|
2010-05-14 14:36:02 +00:00
|
|
|
workitem_vals = {'segment_id': workitem.segment_id.id,
|
|
|
|
'activity_id': mct_id.activity_to_id.id,
|
|
|
|
'date': launch_date,
|
|
|
|
'partner_id': workitem.partner_id.id,
|
|
|
|
'state': 'todo',
|
|
|
|
}
|
|
|
|
self.create(cr, uid, workitem_vals)
|
|
|
|
|
|
|
|
def process(self, cr, uid, workitem_ids, context={}):
|
2010-05-21 15:50:09 +00:00
|
|
|
for wi in self.browse(cr, uid, workitem_ids):
|
2010-05-26 08:23:28 +00:00
|
|
|
if wi.state == 'todo':# we searched the wi which are in todo state
|
2010-05-18 10:42:08 +00:00
|
|
|
#then y v keep this filter again
|
2010-05-21 15:50:09 +00:00
|
|
|
eval_context = {
|
|
|
|
'pool': self.pool,
|
|
|
|
'cr': cr,
|
|
|
|
'uid': uid,
|
|
|
|
'wi': wi,
|
|
|
|
'object': wi.activity_id,
|
2010-05-26 08:23:28 +00:00
|
|
|
'transition': wi.activity_id.to_ids
|
2010-05-21 15:50:09 +00:00
|
|
|
}
|
2010-05-26 08:20:02 +00:00
|
|
|
expr = eval(str(wi.activity_id.condition), eval_context)
|
2010-05-25 14:26:20 +00:00
|
|
|
if expr:
|
2010-05-21 15:50:09 +00:00
|
|
|
try :
|
2010-05-25 14:26:20 +00:00
|
|
|
res = self.pool.get('marketing.campaign.activity').process(
|
|
|
|
cr, uid, wi.activity_id.id, wi.id, context)
|
|
|
|
if res :
|
2010-05-26 08:23:28 +00:00
|
|
|
self.write(cr, uid, wi.id, {'state': 'done'})
|
2010-05-25 14:26:20 +00:00
|
|
|
self.process_chain(cr, uid, wi.id, context)
|
|
|
|
else :
|
2010-05-26 08:23:28 +00:00
|
|
|
self.write(cr, uid, wi.id, {'state': 'exception',
|
|
|
|
'error_msg': res['error_msg']})
|
2010-05-21 15:50:09 +00:00
|
|
|
except Exception,e:
|
2010-05-26 08:23:28 +00:00
|
|
|
self.write(cr, uid, wi.id, {'state': 'exception'})
|
2010-05-21 15:50:09 +00:00
|
|
|
else :
|
2010-05-26 08:23:28 +00:00
|
|
|
self.write(cr, uid, wi.id, {'state': 'cancelled'})
|
2010-05-21 15:50:09 +00:00
|
|
|
|
2010-05-14 14:36:02 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
def process_all(self, cr, uid, context={}):
|
2010-05-21 09:53:53 +00:00
|
|
|
workitem_ids = self.search(cr, uid, [('state', '=', 'todo'),
|
2010-05-14 14:36:02 +00:00
|
|
|
('date','<=', time.strftime('%Y-%m-%d %H:%M:%S'))])
|
|
|
|
if workitem_ids:
|
2010-05-21 09:53:53 +00:00
|
|
|
self.process(cr, uid, workitem_ids, context)
|
2010-05-18 10:42:08 +00:00
|
|
|
|
2010-05-14 14:36:02 +00:00
|
|
|
marketing_campaign_workitem() #}}}
|
2010-05-25 14:26:20 +00:00
|
|
|
|
2010-06-02 14:39:28 +00:00
|
|
|
class email_template(osv.osv):
|
|
|
|
_inherit = "email.template"
|
2010-05-25 14:26:20 +00:00
|
|
|
|
|
|
|
_defaults = {
|
2010-05-26 08:23:28 +00:00
|
|
|
'object_name': lambda obj, cr, uid, context: context.get('object_id',False),
|
2010-05-25 14:26:20 +00:00
|
|
|
}
|
2010-06-02 14:39:28 +00:00
|
|
|
email_template()
|
2010-05-25 14:26:20 +00:00
|
|
|
|
|
|
|
class report_xml(osv.osv):
|
|
|
|
|
|
|
|
_inherit = 'ir.actions.report.xml'
|
|
|
|
|
|
|
|
def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
|
2010-05-26 08:23:28 +00:00
|
|
|
if not context:
|
2010-05-25 14:26:20 +00:00
|
|
|
context = {}
|
|
|
|
if context and 'object_id' in context and context['object_id']:
|
|
|
|
model = self.pool.get('ir.model').browse(cr, uid,
|
|
|
|
context['object_id']).model
|
2010-05-26 08:23:28 +00:00
|
|
|
args.append(('model', '=', model))
|
2010-05-25 14:26:20 +00:00
|
|
|
return super(report_xml, self).search(cr, uid, args, offset, limit, order, context, count)
|
|
|
|
|
|
|
|
report_xml()
|
2010-05-14 14:36:02 +00:00
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
|
|
|