[MERGE] trunk adons
bzr revid: mra@mra-laptop-20100611081604-ogxd954fe4p35hkx
This commit is contained in:
Executable → Regular
Executable → Regular
Executable → Regular
+19
-11
@@ -17,10 +17,10 @@ try:
|
||||
TEMPLATE_ENGINES.append(('mako', 'Mako Templates'))
|
||||
except:
|
||||
LOGGER.notifyChannel(
|
||||
_("Email Template"),
|
||||
netsvc.LOG_ERROR,
|
||||
_("Mako templates not installed")
|
||||
)
|
||||
_("Email Template"),
|
||||
netsvc.LOG_WARNING,
|
||||
_("Mako templates not installed")
|
||||
)
|
||||
try:
|
||||
from django.template import Context, Template as DjangoTemplate
|
||||
#Workaround for bug:
|
||||
@@ -31,10 +31,10 @@ try:
|
||||
TEMPLATE_ENGINES.append(('django', 'Django Template'))
|
||||
except:
|
||||
LOGGER.notifyChannel(
|
||||
_("Email Template"),
|
||||
netsvc.LOG_ERROR,
|
||||
_("Django templates not installed")
|
||||
)
|
||||
_("Email Template"),
|
||||
netsvc.LOG_WARNING,
|
||||
_("Django templates not installed")
|
||||
)
|
||||
|
||||
import email_template_engines
|
||||
import tools
|
||||
@@ -468,7 +468,7 @@ class email_template(osv.osv):
|
||||
context)
|
||||
return True
|
||||
|
||||
def generate_mailbox_item_from_template(self,
|
||||
def _generate_mailbox_item_from_template(self,
|
||||
cursor,
|
||||
user,
|
||||
template,
|
||||
@@ -559,6 +559,8 @@ class email_template(osv.osv):
|
||||
'folder':'drafts',
|
||||
'mail_type':'multipart/alternative'
|
||||
}
|
||||
if not mailbox_values['account_id']:
|
||||
raise Exception("Unable to send the mail. No account linked to the template.")
|
||||
#Use signatures if allowed
|
||||
if template.use_sign:
|
||||
sign = self.pool.get('res.users').read(cursor,
|
||||
@@ -570,13 +572,17 @@ class email_template(osv.osv):
|
||||
mailbox_values['body_text'] += sign
|
||||
if mailbox_values['body_html']:
|
||||
mailbox_values['body_html'] += sign
|
||||
print 'Creating', mailbox_values
|
||||
mailbox_id = self.pool.get('email_template.mailbox').create(
|
||||
cursor,
|
||||
user,
|
||||
mailbox_values,
|
||||
context)
|
||||
|
||||
print 'Sending', mailbox_id
|
||||
self.pool.get('email_template.mailbox').send_this_mail(cursor, user, [mailbox_id], context)
|
||||
return mailbox_id
|
||||
|
||||
|
||||
def generate_mail(self,
|
||||
cursor,
|
||||
user,
|
||||
@@ -588,6 +594,7 @@ class email_template(osv.osv):
|
||||
template = self.browse(cursor, user, template_id, context=context)
|
||||
if not template:
|
||||
raise Exception("The requested template could not be loaded")
|
||||
print 'loaded', record_ids
|
||||
for record_id in record_ids:
|
||||
mailbox_id = self._generate_mailbox_item_from_template(
|
||||
cursor,
|
||||
@@ -595,6 +602,7 @@ class email_template(osv.osv):
|
||||
template,
|
||||
record_id,
|
||||
context)
|
||||
print 'loaded'
|
||||
mail = self.pool.get('email_template.mailbox').browse(
|
||||
cursor,
|
||||
user,
|
||||
@@ -616,7 +624,7 @@ class email_template(osv.osv):
|
||||
mailbox_id,
|
||||
{'folder':'outbox'},
|
||||
context=context
|
||||
)
|
||||
)
|
||||
return True
|
||||
|
||||
email_template()
|
||||
|
||||
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
+1
-3
@@ -41,9 +41,7 @@ class email_template_mailbox(osv.osv):
|
||||
return True
|
||||
|
||||
def send_this_mail(self, cr, uid, ids=None, context=None):
|
||||
if ids is None:
|
||||
ids = []
|
||||
for id in ids:
|
||||
for id in (ids or []):
|
||||
try:
|
||||
account_obj = self.pool.get('email_template.account')
|
||||
values = self.read(cr, uid, id, [], context)
|
||||
|
||||
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
@@ -29,8 +29,9 @@
|
||||
<attribute name="string">Configure</attribute>
|
||||
</xpath>
|
||||
<group colspan="8">
|
||||
<field name="marketing_campaign" />
|
||||
<field name="email_template" />
|
||||
<field name="crm_profiling" />
|
||||
<field name="marketing_campaign" />
|
||||
<field name="marketing_campaign_mailchimp" />
|
||||
</group>
|
||||
</data>
|
||||
|
||||
@@ -25,7 +25,8 @@ class marketing_installer(osv.osv_memory):
|
||||
_name = 'marketing.installer'
|
||||
_inherit = 'res.config.installer'
|
||||
_columns = {
|
||||
# Generic modules
|
||||
'email_template':fields.boolean('Automated E-Mails',
|
||||
help="Helps you to design templates of emails and integrate them in your different processes."),
|
||||
'marketing_campaign':fields.boolean('Marketing Campaigns',
|
||||
help="Helps you to manage marketing campaigns and automate actions and communication steps."),
|
||||
'marketing_campaign_mailchimp':fields.boolean('Mailchimp Integration',
|
||||
|
||||
Executable → Regular
Executable → Regular
Executable → Regular
+69
-47
@@ -101,7 +101,7 @@ class marketing_campaign_segment(osv.osv):
|
||||
_columns = {
|
||||
'name': fields.char('Name', size=64,required=True),
|
||||
'campaign_id': fields.many2one('marketing.campaign', 'Campaign',
|
||||
required=True),
|
||||
required=True, select=1),
|
||||
'object_id': fields.related('campaign_id','object_id',
|
||||
type='many2one', relation='ir.model',
|
||||
string='Object'),
|
||||
@@ -200,7 +200,7 @@ class marketing_campaign_activity(osv.osv):
|
||||
_columns = {
|
||||
'name': fields.char('Name', size=128, required=True),
|
||||
'campaign_id': fields.many2one('marketing.campaign', 'Campaign',
|
||||
required = True, ondelete='cascade'),
|
||||
required = True, ondelete='cascade', select=1),
|
||||
'object_id': fields.related('campaign_id','object_id',
|
||||
type='many2one', relation='ir.model',
|
||||
string='Object'),
|
||||
@@ -242,7 +242,7 @@ class marketing_campaign_activity(osv.osv):
|
||||
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,
|
||||
@@ -259,7 +259,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):
|
||||
def process_wi_report(self, cr, uid, activity, workitem, context={}):
|
||||
service = netsvc.LocalService('report.%s'%activity.report_id.report_name)
|
||||
(report_data, format) = service.create(cr, uid, [], {}, {})
|
||||
attach_vals = {
|
||||
@@ -274,46 +274,58 @@ 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):
|
||||
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
|
||||
def process_wi_email(self, cr, uid, activity, workitem, context=None):
|
||||
print 'Sending Email Init', activity.name
|
||||
return self.pool.get('email.template').generate_mail(cr, uid, activity.email_template_id.id, [workitem.res_id], context=context)
|
||||
|
||||
#Create partly the mail and later update attachments
|
||||
mail_id = self.pool.get('email_template.mailbox').create(cr, uid, vals, context)
|
||||
#if not template.enforce_from_account:
|
||||
# self.pool.get('marketing.campaign.workitem').write(cr, uid, [workitem.id], {
|
||||
# 'error_msg': 'There is no account defined for the email',
|
||||
# 'state': 'exception'
|
||||
# })
|
||||
# return False
|
||||
#if not workitem.partner_id.email:
|
||||
# self.pool.get('marketing.campaign.workitem').write(cr, uid, [workitem.id], {
|
||||
# 'error_msg': "There is no email defined for the partner",
|
||||
# 'state': 'exception'
|
||||
# })
|
||||
# return False
|
||||
#vals = {
|
||||
# 'email_from': tools.ustr(accounts.name) + "<" + tools.ustr(accounts.email_id) + ">",
|
||||
# 'email_to': template.email_to,
|
||||
# 'email_cc': template.email_cc,
|
||||
# 'email_bcc': template.email_bcc,
|
||||
# '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
|
||||
#print 'Sending Email', vals
|
||||
#mail_id = self.pool.get('email_template.mailbox').create(cr, uid, vals, context)
|
||||
return True
|
||||
|
||||
def process_wi_action(self, cr, uid, activity, workitem):
|
||||
|
||||
def process_wi_action(self, cr, uid, activity, workitem, context={}):
|
||||
context = {}
|
||||
server_obj = self.pool.get('ir.actions.server')
|
||||
server_obj.run(cr, uid, [activity.server_action_id.id], context)
|
||||
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)
|
||||
print 'Process', activity.name
|
||||
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
|
||||
workitem = workitem_obj.browse(cr, uid, wi_id, context=context)
|
||||
print 'WI', workitem, activity.type
|
||||
return self._actions[activity.type](cr, uid, activity, workitem, context)
|
||||
|
||||
marketing_campaign_activity()
|
||||
|
||||
@@ -324,7 +336,7 @@ class marketing_campaign_transition(osv.osv):
|
||||
|
||||
_columns = {
|
||||
'activity_from_id': fields.many2one('marketing.campaign.activity',
|
||||
'Source Activity'),
|
||||
'Source Activity', select=1),
|
||||
'activity_to_id': fields.many2one('marketing.campaign.activity',
|
||||
'Destination Activity'),
|
||||
'interval_nbr': fields.integer('Interval No.'),
|
||||
@@ -366,12 +378,12 @@ class marketing_campaign_workitem(osv.osv):
|
||||
'campaign_id': fields.related('segment_id', 'campaign_id',
|
||||
type='many2one', relation='marketing.campaign', string='Campaign', readonly=True),
|
||||
'object_id': fields.related('segment_id', 'campaign_id', 'object_id',
|
||||
type='many2one', relation='ir.model', string='Object'),
|
||||
'res_id': fields.integer('Resource ID'),
|
||||
type='many2one', relation='ir.model', string='Object', select=1),
|
||||
'res_id': fields.integer('Resource ID', select=1),
|
||||
'res_name': fields.function(_res_name_get, method=True, string='Resource Name', type="char", size=64),
|
||||
'date': fields.datetime('Execution Date'),
|
||||
'partner_id': fields.many2one('res.partner', 'Partner'),
|
||||
'state': fields.selection([('todo', 'ToDo'), ('inprogress', 'In Progress'),
|
||||
'partner_id': fields.many2one('res.partner', 'Partner', select=1),
|
||||
'state': fields.selection([('todo', 'To Do'), ('inprogress', 'In Progress'),
|
||||
('exception', 'Exception'), ('done', 'Done'),
|
||||
('cancelled', 'Cancelled')], 'State'),
|
||||
|
||||
@@ -400,8 +412,14 @@ class marketing_campaign_workitem(osv.osv):
|
||||
self.create(cr, uid, workitem_vals)
|
||||
return True
|
||||
|
||||
def button_draft(self, cr, uid, workitem_ids, context={}):
|
||||
for wi in self.browse(cr, uid, workitem_ids, context=context):
|
||||
if wi.state=='exception':
|
||||
self.write(cr, uid, [wi.id], {'state':'todo'}, context=context)
|
||||
return True
|
||||
|
||||
def button_cancel(self, cr, uid, workitem_ids, context={}):
|
||||
for wi in self.browse(cr, uid, workitem_ids):
|
||||
for wi in self.browse(cr, uid, workitem_ids, context=context):
|
||||
if wi.state in ('todo','exception'):
|
||||
self.write(cr, uid, [wi.id], {'state':'cancelled'}, context=context)
|
||||
return True
|
||||
@@ -419,14 +437,18 @@ class marketing_campaign_workitem(osv.osv):
|
||||
}
|
||||
expr = eval(str(wi.activity_id.condition), eval_context)
|
||||
if expr:
|
||||
try :
|
||||
try:
|
||||
result = True
|
||||
if wi.campaign_id.mode in ('manual','active'):
|
||||
self.pool.get('marketing.campaign.activity').process(
|
||||
result = self.pool.get('marketing.campaign.activity').process(
|
||||
cr, uid, wi.activity_id.id, wi.id, context)
|
||||
self.write(cr, uid, wi.id, {'state': 'done'})
|
||||
self.process_chain(cr, uid, wi.id, context)
|
||||
if result:
|
||||
self.write(cr, uid, wi.id, {'state': 'done'})
|
||||
self.process_chain(cr, uid, wi.id, context)
|
||||
else:
|
||||
self.write(cr, uid, wi.id, {'state': 'exception'})
|
||||
except Exception,e:
|
||||
self.write(cr, uid, wi.id, {'state': 'exception'})
|
||||
self.write(cr, uid, wi.id, {'state': 'exception', 'error_msg': str(e)})
|
||||
else :
|
||||
self.write(cr, uid, wi.id, {'state': 'cancelled'})
|
||||
|
||||
@@ -444,7 +466,7 @@ class marketing_campaign_workitem(osv.osv):
|
||||
workitem_ids = self.search(cr, uid, [('state', '=', 'todo')])
|
||||
else:
|
||||
# manual states are not processed automatically
|
||||
pass
|
||||
workitem_ids = []
|
||||
if workitem_ids:
|
||||
self.process(cr, uid, workitem_ids, context)
|
||||
|
||||
|
||||
Executable → Regular
+9
-4
@@ -182,15 +182,15 @@
|
||||
</group>
|
||||
<group colspan="2" col="2">
|
||||
<separator string="Synchronization" colspan="2"/>
|
||||
<field name="sync_last_date"/>
|
||||
<field name="sync_mode" required="True"/>
|
||||
<field name="sync_last_date"/>
|
||||
<label string="" colspan="1"/>
|
||||
<button string="Synchronize" states="running" name="synchroniz" icon="gtk-apply" type="object"/>
|
||||
</group>
|
||||
<group colspan="2" col="2">
|
||||
<separator string="Dates" colspan="2"/>
|
||||
<field name="date_run" attrs="{'readonly':[('date_run','!=',False),('state','=','running')]}"/>
|
||||
<field name="date_done"/>
|
||||
<field name="date_run" readonly="1"/>
|
||||
<field name="date_done" readonly="1"/>
|
||||
</group>
|
||||
<separator string="Status" colspan="4"/>
|
||||
<group col="10" colspan="4">
|
||||
@@ -397,11 +397,16 @@
|
||||
<button string="Preview" states="todo" name="preview" icon="gtk-apply" type="object"/>
|
||||
</group>
|
||||
</group>
|
||||
<group colspan="4" col="4" attrs="{'invisible':[('state','!=','exception')]}">
|
||||
<separator string="Error Message" colspan="4"/>
|
||||
<field name="error_msg" nolabel="1" colspan="4"/>
|
||||
</group>
|
||||
<separator string="Status" colspan="4"/>
|
||||
<group colspan="4" col="11">
|
||||
<field name="state" nolabel="1" readonly="True" select="1"/>
|
||||
<button string="Retry" states="exception" name="button_draft" type="object" icon="gtk-ok"/>
|
||||
<button string="Process" states="todo" name="process" type="object" icon="gtk-ok"/>
|
||||
<button string="Cancel" states="todo" name="button_cancel" type="object" icon="gtk-cancel"/>
|
||||
<button string="Cancel" states="todo,exception" name="button_cancel" type="object" icon="gtk-cancel"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
|
||||
Reference in New Issue
Block a user