Skip to content
Browse files

Merge pull request #21 from eLBati/dev

[FIX] allowing multiple templates to be associated to the same model
  • Loading branch information...
2 parents bc8556b + b419f7a commit 903e8c8b76ec0d2150336cc2dec07aac18e0537a Sharoon Thomas committed Apr 20, 2012
Showing with 23 additions and 15 deletions.
  1. +3 −2 serveraction.py
  2. +20 −13 template.py
View
5 serveraction.py
@@ -70,15 +70,16 @@ def run(self, cr, uid, ids, context=None):
for action in self.browse(cr, uid, ids, context):
obj_pool = self.pool.get(action.model_id.model)
- obj = obj_pool.browse(cr, uid, context['active_id'], context=context)
cxt = {
'context':context,
- 'object': obj,
'time':time,
'cr': cr,
'pool' : self.pool,
'uid' : uid
}
+ if context.get('active_id', False):
+ obj = obj_pool.browse(cr, uid, context['active_id'], context=context)
+ cxt['object'] = obj
expr = eval(str(action.condition), cxt)
if not expr:
continue
View
33 template.py
@@ -70,18 +70,20 @@
def send_on_create(self, cr, uid, vals, context=None):
id = self.old_create(cr, uid, vals, context)
- template = self.pool.get('poweremail.templates').browse(cr, uid, self.template_id, context)
- # Ensure it's still configured to send on create
- if template.send_on_create:
- self.pool.get('poweremail.templates').generate_mail(cr, uid, self.template_id, [id], context)
+ templates = self.pool.get('poweremail.templates').browse(cr, uid, self.template_ids, context)
+ for template in templates:
+ # Ensure it's still configured to send on create
+ if template.send_on_create:
+ self.pool.get('poweremail.templates').generate_mail(cr, uid, template.id, [id], context)
return id
def send_on_write(self, cr, uid, ids, vals, context=None):
result = self.old_write(cr, uid, ids, vals, context)
- template = self.pool.get('poweremail.templates').browse(cr, uid, self.template_id, context)
- # Ensure it's still configured to send on write
- if template.send_on_write:
- self.pool.get('poweremail.templates').generate_mail(cr, uid, self.template_id, ids, context)
+ templates = self.pool.get('poweremail.templates').browse(cr, uid, self.template_ids, context)
+ for template in templates:
+ # Ensure it's still configured to send on write
+ if template.send_on_write:
+ self.pool.get('poweremail.templates').generate_mail(cr, uid, template.id, ids, context)
return result
@@ -120,12 +122,14 @@ def register_all(self, cr):
if hasattr(obj, 'old_write'):
obj.write = obj.old_write
del obj.old_write
+ if not hasattr(obj, 'template_ids'):
+ obj.template_ids = []
if soc:
- obj.template_id = id
+ obj.template_ids.append(id)
obj.old_create = obj.create
obj.create = types.MethodType(send_on_create, obj, osv.osv)
if sow:
- obj.template_id = id
+ obj.template_ids.append(id)
obj.old_write = obj.write
obj.write = types.MethodType(send_on_write, obj, osv.osv)
return value
@@ -423,12 +427,14 @@ def update_send_on_store(self, cr, uid, ids, context):
if hasattr(obj, 'old_write'):
obj.write = obj.old_write
del obj.old_write
+ if not hasattr(obj, 'template_ids'):
+ obj.template_ids = []
if template.send_on_create:
- obj.template_id = template.id
+ obj.template_ids.append(template.id)
obj.old_create = obj.create
obj.create = types.MethodType(send_on_create, obj, osv.osv)
if template.send_on_write:
- obj.template_id = template.id
+ obj.template_ids.append(template.id)
obj.old_write = obj.write
obj.write = types.MethodType(send_on_write, obj, osv.osv)
@@ -946,7 +952,8 @@ def generate_mail(self,
if template.use_filter and template.filter:
filtered_record_ids=[]
for record in self.pool.get(template.object_name.model).browse(cursor, user, record_ids, context=context):
- if safe_eval(template.filter, {'o':record, 'self':self, 'cr':cursor, 'context':context}):
+ if safe_eval(template.filter,
+ {'o':record, 'self':self, 'cr':cursor, 'context':context, 'uid': user}):
filtered_record_ids.append(record.id)
record_ids=filtered_record_ids

0 comments on commit 903e8c8

Please sign in to comment.
Something went wrong with that request. Please try again.