[IMP] marketing_campaign: change the way that the differents activity types are processed.
[FIX] marketing_campaign: deactivate the subcampaign activity type because it is not implemented at all. bzr revid: chs@openerp.com-20100702131849-961q3075l5wvrorn
This commit is contained in:
parent
ee23522ca8
commit
23d6634faa
|
@ -115,6 +115,7 @@ you required for the campaign"),
|
|||
}
|
||||
|
||||
def state_running_set(self, cr, uid, ids, *args):
|
||||
# TODO check that all subcampaigns are running
|
||||
campaign = self.browse(cr, uid, ids[0])
|
||||
if not campaign.activity_ids :
|
||||
raise osv.except_osv("Error", "There is no activitity in the campaign")
|
||||
|
@ -135,6 +136,7 @@ you required for the campaign"),
|
|||
return True
|
||||
|
||||
def state_done_set(self, cr, uid, ids, *args):
|
||||
# TODO check that this campaign is not a subcampaign in running mode.
|
||||
segment_ids = self.pool.get('marketing.campaign.segment').search(cr, uid,
|
||||
[('campaign_id', 'in', ids),
|
||||
('state', '=', 'running')])
|
||||
|
@ -144,6 +146,7 @@ you required for the campaign"),
|
|||
return True
|
||||
|
||||
def state_cancel_set(self, cr, uid, ids, *args):
|
||||
# TODO check that this campaign is not a subcampaign in running mode.
|
||||
self.write(cr, uid, ids, {'state': 'cancelled'})
|
||||
return True
|
||||
|
||||
|
@ -288,8 +291,18 @@ class marketing_campaign_activity(osv.osv):
|
|||
_name = "marketing.campaign.activity"
|
||||
_description = "Campaign Activity"
|
||||
|
||||
_actions_type = [('email', 'E-mail'), ('paper', 'Paper'), ('action', 'Action'),
|
||||
('subcampaign', 'Sub-Campaign')]
|
||||
_action_types = [
|
||||
('email', 'E-mail'),
|
||||
('paper', 'Paper'),
|
||||
('action', 'Action'),
|
||||
# TODO implement the subcampaigns. The segment_id on woritems must be
|
||||
# optional (thus campaign_id must be a real many2one, and a constraint
|
||||
# must be set).
|
||||
# TODO implement the subcampaign out. disallow out transitions from
|
||||
# subcampaign activities ?
|
||||
#('subcampaign', 'Sub-Campaign'),
|
||||
]
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Name', size=128, required=True),
|
||||
'campaign_id': fields.many2one('marketing.campaign', 'Campaign',
|
||||
|
@ -300,8 +313,7 @@ class marketing_campaign_activity(osv.osv):
|
|||
'start': fields.boolean('Start',help= "This activity is launched when the campaign starts."),
|
||||
'condition': fields.char('Condition', size=256, required=True,
|
||||
help="Python condition to know if the activity can be launched"),
|
||||
'type': fields.selection(_actions_type,
|
||||
'Type', required=True,
|
||||
'type': fields.selection(_action_types, 'Type', required=True,
|
||||
help="Describe type of action to be performed on the Activity.Eg : Send email,Send paper.."),
|
||||
'email_template_id': fields.many2one('email.template','Email Template'),
|
||||
'report_id': fields.many2one('ir.actions.report.xml', 'Reports', ),
|
||||
|
@ -316,9 +328,8 @@ class marketing_campaign_activity(osv.osv):
|
|||
'from_ids': fields.one2many('marketing.campaign.transition',
|
||||
'activity_to_id',
|
||||
'Previous Activities'),
|
||||
'subcampaign_id': fields.many2one('marketing.campaign', 'Sub-Campaign'),
|
||||
'subcampaign_segment_id': fields.many2one('marketing.campaign.segment',
|
||||
'Sub Campaign Segment'),
|
||||
#'subcampaign_id': fields.many2one('marketing.campaign', 'Sub-Campaign',
|
||||
# domain="[('object_id', '=', object_id)]"),
|
||||
'variable_cost': fields.float('Variable Cost'),
|
||||
'revenue': fields.float('Revenue'),
|
||||
'signal': fields.char('Signal', size=128,
|
||||
|
@ -345,14 +356,6 @@ class marketing_campaign_activity(osv.osv):
|
|||
),
|
||||
]
|
||||
|
||||
def __init__(self, *args):
|
||||
# FIXME use self._process_wi_<type>
|
||||
self._actions = {'paper' : self.process_wi_report,
|
||||
'email' : self.process_wi_email,
|
||||
'action' : self.process_wi_action,
|
||||
}
|
||||
return super(marketing_campaign_activity, self).__init__(*args)
|
||||
|
||||
def search(self, cr, uid, args, offset=0, limit=None, order=None,
|
||||
context=None, count=False):
|
||||
if context == None:
|
||||
|
@ -367,7 +370,7 @@ class marketing_campaign_activity(osv.osv):
|
|||
return super(marketing_campaign_activity, self).search(cr, uid, args,
|
||||
offset, limit, order, context, count)
|
||||
|
||||
def process_wi_report(self, cr, uid, activity, workitem, context={}):
|
||||
def _process_wi_paper(self, cr, uid, activity, workitem, context=None):
|
||||
service = netsvc.LocalService('report.%s'%activity.report_id.report_name)
|
||||
(report_data, format) = service.create(cr, uid, [], {}, {})
|
||||
attach_vals = {
|
||||
|
@ -382,24 +385,36 @@ class marketing_campaign_activity(osv.osv):
|
|||
self.pool.get('ir.attachment').create(cr, uid, attach_vals)
|
||||
return True
|
||||
|
||||
def process_wi_email(self, cr, uid, activity, workitem, context=None):
|
||||
def _process_wi_email(self, cr, uid, activity, workitem, context=None):
|
||||
return self.pool.get('email.template').generate_mail(cr, uid,
|
||||
activity.email_template_id.id,
|
||||
[workitem.res_id], context=context)
|
||||
|
||||
def process_wi_action(self, cr, uid, activity, workitem, context={}):
|
||||
context = {}
|
||||
def _process_wi_action(self, cr, uid, activity, workitem, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
server_obj = self.pool.get('ir.actions.server')
|
||||
context['active_id'] = workitem.res_id
|
||||
res = server_obj.run(cr, uid, [activity.server_action_id.id], context)
|
||||
#server action return False if the action is perfomed except client_action,other and python code
|
||||
return res==False and True or res
|
||||
|
||||
def process(self, cr, uid, act_id, wi_id, context={}):
|
||||
activity = self.browse(cr, uid, act_id)
|
||||
action_context = dict(context,
|
||||
active_id=workitem.res_id,
|
||||
active_ids=[workitem.res_id],
|
||||
active_model=workitem.object_id.model)
|
||||
res = server_obj.run(cr, uid, [activity.server_action_id.id],
|
||||
context=action_context)
|
||||
# server action return False if the action is perfomed
|
||||
# except client_action, other and python code
|
||||
return res == False and True or res
|
||||
|
||||
def process(self, cr, uid, act_id, wi_id, context=None):
|
||||
activity = self.browse(cr, uid, act_id, context=context)
|
||||
method = '_process_wi_%s' % (activity.type,)
|
||||
action = getattr(self, method, None)
|
||||
if not action:
|
||||
raise NotImplementedError('method %r in not implemented on %r object' % (method, self))
|
||||
|
||||
workitem_obj = self.pool.get('marketing.campaign.workitem')
|
||||
workitem = workitem_obj.browse(cr, uid, wi_id, context=context)
|
||||
return self._actions[activity.type](cr, uid, activity, workitem, context)
|
||||
return action(cr, uid, activity, workitem, context)
|
||||
|
||||
marketing_campaign_activity()
|
||||
|
||||
|
|
|
@ -241,10 +241,11 @@
|
|||
<group attrs="{'invisible':[('type','!=','action')]}" >
|
||||
<field name="server_action_id" attrs="{'required':[('type','=','action')]}" domain="[('model_id','=',object_id)]" />
|
||||
</group>
|
||||
<!--
|
||||
<group attrs="{'invisible':[('type','!=','subcampaign')]}" >
|
||||
<field name="subcampaign_id" attrs="{'required':[('type','=','subcampaign')]}" />
|
||||
<field name="subcampaign_segment_id" attrs="{'required':[('type','=','subcampaign')]}" />
|
||||
</group>
|
||||
-->
|
||||
</group>
|
||||
</group>
|
||||
<newline/>
|
||||
|
|
|
@ -22,11 +22,9 @@ import urllib
|
|||
import urllib2
|
||||
import simplejson as json
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
from osv import fields, osv
|
||||
from marketing_campaign.marketing_campaign import _intervalTypes
|
||||
|
||||
mailchimp_url = 'http://%s.api.mailchimp.com/1.2'
|
||||
|
||||
class mailchimp_account(osv.osv):
|
||||
|
@ -150,7 +148,7 @@ class marketing_campaign_activity(osv.osv):
|
|||
return {}
|
||||
return {'value':{}}
|
||||
|
||||
def process_wi_mailchimp(self, cr, uid, activity, workitem, context={}):
|
||||
def _process_wi_mailchimp(self, cr, uid, activity, workitem, context=None):
|
||||
mailchimp_account_id = activity.mailchimp_account_id.id
|
||||
list_name = activity.mailchimp_list
|
||||
mc_acc_obj = self.pool.get('mailchimp.account')
|
||||
|
@ -193,18 +191,15 @@ class marketing_campaign_activity(osv.osv):
|
|||
'merge_vars[address][city]' : model_obj.city and model_obj.city or '',
|
||||
'merge_vars[phone]' : model_obj.phone and model_obj.phone or '',
|
||||
})
|
||||
res = mc_acc_obj.get_response(cr, uid, mailchimp_account_id, 'listSubscribe', params)
|
||||
# handle mailchimp error
|
||||
mc_acc_obj.get_response(cr, uid, mailchimp_account_id, 'listSubscribe', params)
|
||||
# TODO handle mailchimp error
|
||||
return True
|
||||
else :
|
||||
else :
|
||||
return {'error_msg' : "Invalid Email Address"}
|
||||
|
||||
|
||||
def __init__(self, *args):
|
||||
res = super(marketing_campaign_activity, self).__init__(*args)
|
||||
self._actions.update({'mailchimp' : self.process_wi_mailchimp})
|
||||
self._actions_type.append(('mailchimp', 'Mailchimp'))
|
||||
return res
|
||||
|
||||
super(marketing_campaign_activity, self).__init__(*args)
|
||||
self._action_types.append(('mailchimp', 'Mailchimp'))
|
||||
|
||||
marketing_campaign_activity()
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
Loading…
Reference in New Issue