[IMP] marketing_campaign : change process of segment wi(tooltip and relate by pso)

bzr revid: dhara@dhara-laptop-20100610125538-d6k6wxsp0m035az4
This commit is contained in:
Dhara
2010-06-10 18:25:38 +05:30
parent b6c32132b2
commit fd58ff8578
2 changed files with 107 additions and 70 deletions
+88 -60
View File
@@ -42,7 +42,7 @@ class marketing_campaign(osv.osv): #{{{
'name': fields.char('Name', size=64, required=True),
'object_id': fields.many2one('ir.model', 'Object', required=True,
help="Choose the Object on which you want \
this campaign to be run"),
this campaign to be run"),
'mode':fields.selection([('test', 'Test'),
('test_realtime', 'Realtime'),
('manual', 'Manual'),
@@ -56,7 +56,7 @@ class marketing_campaign(osv.osv): #{{{
'activity_ids': fields.one2many('marketing.campaign.activity',
'campaign_id', 'Activities'),
'fixed_cost': fields.float('Fixed Cost', help="The fixed cost is cost\
you required for the campaign"),
you required for the campaign"),
}
_defaults = {
'state': lambda *a: 'draft',
@@ -128,11 +128,11 @@ class marketing_campaign_segment(osv.osv): #{{{
vals = {'state': 'running'}
if not segment.date_run:
vals['date_run'] = time.strftime('%Y-%m-%d %H:%M:%S')
if not segment.sync_last_date:
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')
# if not segment.sync_last_date:
# 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)
return True
@@ -152,12 +152,21 @@ class marketing_campaign_segment(osv.osv): #{{{
def state_cancel_set(self, cr, uid, ids, *args):
self.write(cr, uid, ids, {'state': 'cancelled'})
return True
def synchroniz(self, cr, uid, ids, *args):
self.process_segment(cr, uid, {'segment_ids' : ids})
return True
def process_segment(self, cr, uid, context={}):
segment_ids = self.search(cr, uid, [('state', '=', 'running')])
last_action_date = ''
if 'segment_ids' in context:
segment_ids = context['segment_ids']
last_action_date = (datetime.now() + _intervalTypes['days'](-1) \
).strftime('%Y-%m-%d %H:%M:%S')
else :
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),
@@ -166,9 +175,10 @@ class marketing_campaign_segment(osv.osv): #{{{
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)])
criteria = [(segment.sync_mode, '<=', action_date)]
if last_action_date :
criteria.append((segment.sync_mode, '>=', last_action_date))
object_ids = model_obj.search(cr, uid, criteria)
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
@@ -190,7 +200,9 @@ marketing_campaign_segment()#}}}
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')]
_columns = {
'name': fields.char('Name', size=128, required=True),
'campaign_id': fields.many2one('marketing.campaign', 'Campaign',
@@ -199,15 +211,17 @@ class marketing_campaign_activity(osv.osv): #{{{
type='many2one', relation='ir.model',
string='Object'),
'start': fields.boolean('Start',help= "Its necessary to start activity \
before running campaign"),
before running campaign"),
'condition': fields.char('Condition', size=256, required=True,
help="Condition that is to be tested before \
action is executed"),
help="It is simple python condition that is to \
be tested before action is executed. Eg : revenue > 10"),
'type': fields.selection([('email', 'E-mail'),
('paper', 'Paper'),
('action', 'Action'),
('subcampaign', 'Sub-Campaign')],
'Type', required=True),
'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', ),
'report_directory_id': fields.many2one('document.directory','Directory',
@@ -233,6 +247,13 @@ class marketing_campaign_activity(osv.osv): #{{{
'condition': lambda *a: 'True',
'object_id' : lambda obj, cr, uid, context : context.get('object_id',False),
}
def __init__(self, *args):
self._actions = {'paper' : self.process_wi_report,
'email' : self.process_wi_email,
'server_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):
@@ -248,55 +269,62 @@ class marketing_campaign_activity(osv.osv): #{{{
return super(marketing_campaign_activity, self).search(cr, uid, args,
offset, limit, order, context, count)
def process(self, cr, uid, act_id, wi_id, context={}):
activity = self.browse(cr, uid, act_id)
workitem_obj = self.pool.get('marketing.campaign.workitem')
workitem = workitem_obj.browse(cr, uid, wi_id)
def process_wi_report(self, cr, uid, activity, workitem):
service = netsvc.LocalService('report.%s'%activity.report_id.report_name)
(report_data, format) = service.create(cr, uid, [], {}, {})
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)
return True
if activity.type == 'paper' :
service = netsvc.LocalService('report.%s'%activity.report_id.report_name)
(report_data, format) = service.create(cr, uid, [], {}, {})
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)
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 = {
'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,
'state':'na',
'mail_type':'multipart/alternative' #Options:'multipart/mixed','multipart/alternative','text/plain','text/html'
}
def process_wi_email(self, cr, uid, activity, workitem):
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 = {
'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,
'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
mail_id = self.pool.get('email_template.mailbox').create(cr, uid, vals, context)
elif activity.type == 'action' :
server_obj = self.pool.get('ir.actions.server')
server_obj.run(cr, uid, [activity.server_action_id.id], context)
#???
#Create partly the mail and later update attachments
mail_id = self.pool.get('email_template.mailbox').create(cr, uid, vals, context)
return True
def process_wi_action(self, cr, uid, activity, workitem):
context = {}
server_obj = self.pool.get('ir.actions.server')
server_obj.run(cr, uid, [activity.server_action_id.id], context)
return True
def process(self, cr, uid, act_id, wi_id, context={}):
activity = self.browse(cr, uid, act_id)
workitem_obj = self.pool.get('marketing.campaign.workitem')
workitem = workitem_obj.browse(cr, uid, wi_id)
self._actions[activity.type](cr, uid, activity, workitem)
return True
marketing_campaign_activity()#}}}
class marketing_campaign_transition(osv.osv): #{{{
@@ -181,9 +181,10 @@
<field name="object_id" invisible="1" readonly="True"/>
</group>
<group colspan="2" col="2">
<separator string="Synchronization" colspan="2"/>
<separator string="Synchronization" colspan="2"/>
<field name="sync_last_date"/>
<field name="sync_mode" required="True"/>
<button string="Synchroniz" states="draft,running" name="synchroniz" icon="gtk-apply" type="object"/>
</group>
<group colspan="2" col="2">
<separator string="Dates" colspan="2"/>
@@ -209,9 +210,8 @@
<tree string="Segments">
<field name="name"/>
<field name="campaign_id"/>
<field name="object_id"/>
<field name="date_run"/>
<field name="date_done"/>
<field name="sync_last_date"/>
<field name="state" />
</tree>
</field>
@@ -223,10 +223,10 @@
<field name="type">search</field>
<field name="arch" type="xml">
<search string="Segments">
<filter icon="terp-document-new" string="Draft" name="draft" domain="[('state','=','draft')]"/>
<filter icon="terp-check" string="Running" domain="[('state','=','running')]"/>
<filter icon="terp-document-new" string="Draft" domain="[('state','=','draft')]"/>
<filter icon="terp-check" string="Running" name="running" domain="[('state','=','running')]"/>
<separator orientation="vertical"/>
<filter icon="terp-go-month" string="Create Date" name="create_date" domain="[('sync_mode','=','create_date')]"/>
<filter icon="terp-go-month" string="Create Date" domain="[('sync_mode','=','create_date')]"/>
<filter icon="terp-go-month" string="Write Date" domain="[('sync_mode','=','write_date')]"/>
<separator orientation="vertical"/>
<field name="name" select="1"/>
@@ -242,7 +242,7 @@
</search>
</field>
</record>
+
<record model="ir.actions.act_window" id="action_marketing_campaign_segment_form">
<field name="name">Segments</field>
<field name="type">ir.actions.act_window</field>
@@ -250,8 +250,8 @@
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_marketing_campaign_segment_tree"/>
<field name="search_view_id" ref="view_marketing_campaign_segment_search"/>
<field name="context">{'group_by': [], 'search_default_draft': 1, 'search_default_create_date': 1}</field>
<field name="search_view_id" ref="view_marketing_campaign_segment_search"/>
<field name="context">{'group_by': [], 'search_default_running': 1}</field>
</record>
<menuitem id="menu_marketing_campaign_segment_form" parent="menu_marketing_campaign" action="action_marketing_campaign_segment_form" sequence="20" />
@@ -393,7 +393,7 @@
<separator string="Date" colspan="2"/>
<field name="date"/>
<label string="" colspan="1"/>
<button string="Preview" states="todo" name="preview" icon="gtk-apply"/>
<button string="Preview" states="todo" name="preview" icon="gtk-apply" type="object"/>
</group>
</group>
<separator string="Status" colspan="4"/>
@@ -445,5 +445,14 @@
<menuitem id="menu_action_marketing_campaign_workitem" parent="menu_marketing_campaign" action="action_marketing_campaign_workitem" sequence="30" groups="base.group_extended"/>
<act_window name="All Segments"
res_model="marketing.campaign.segment"
src_model="marketing.campaign"
view_type="form"
view_mode="tree,form"
id="act_marketing_campaing_segment_opened"
domain="[('campaign_id','=',active_id)]"
/>
</data>
</openerp>