Skip to content

Commit

Permalink
Merge pull request #21 from eLBati/dev
Browse files Browse the repository at this point in the history
[FIX] allowing multiple templates to be associated to the same model
  • Loading branch information
Sharoon Thomas committed Apr 20, 2012
2 parents bc8556b + b419f7a commit 903e8c8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
5 changes: 3 additions & 2 deletions serveraction.py
Expand Up @@ -70,15 +70,16 @@ def run(self, cr, uid, ids, context=None):


for action in self.browse(cr, uid, ids, context): for action in self.browse(cr, uid, ids, context):
obj_pool = self.pool.get(action.model_id.model) obj_pool = self.pool.get(action.model_id.model)
obj = obj_pool.browse(cr, uid, context['active_id'], context=context)
cxt = { cxt = {
'context':context, 'context':context,
'object': obj,
'time':time, 'time':time,
'cr': cr, 'cr': cr,
'pool' : self.pool, 'pool' : self.pool,
'uid' : uid '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) expr = eval(str(action.condition), cxt)
if not expr: if not expr:
continue continue
Expand Down
33 changes: 20 additions & 13 deletions template.py
Expand Up @@ -70,18 +70,20 @@


def send_on_create(self, cr, uid, vals, context=None): def send_on_create(self, cr, uid, vals, context=None):
id = self.old_create(cr, uid, vals, context) id = self.old_create(cr, uid, vals, context)
template = self.pool.get('poweremail.templates').browse(cr, uid, self.template_id, context) templates = self.pool.get('poweremail.templates').browse(cr, uid, self.template_ids, context)
# Ensure it's still configured to send on create for template in templates:
if template.send_on_create: # Ensure it's still configured to send on create
self.pool.get('poweremail.templates').generate_mail(cr, uid, self.template_id, [id], context) if template.send_on_create:
self.pool.get('poweremail.templates').generate_mail(cr, uid, template.id, [id], context)
return id return id


def send_on_write(self, cr, uid, ids, vals, context=None): def send_on_write(self, cr, uid, ids, vals, context=None):
result = self.old_write(cr, uid, ids, vals, context) result = self.old_write(cr, uid, ids, vals, context)
template = self.pool.get('poweremail.templates').browse(cr, uid, self.template_id, context) templates = self.pool.get('poweremail.templates').browse(cr, uid, self.template_ids, context)
# Ensure it's still configured to send on write for template in templates:
if template.send_on_write: # Ensure it's still configured to send on write
self.pool.get('poweremail.templates').generate_mail(cr, uid, self.template_id, ids, context) if template.send_on_write:
self.pool.get('poweremail.templates').generate_mail(cr, uid, template.id, ids, context)
return result return result




Expand Down Expand Up @@ -120,12 +122,14 @@ def register_all(self, cr):
if hasattr(obj, 'old_write'): if hasattr(obj, 'old_write'):
obj.write = obj.old_write obj.write = obj.old_write
del obj.old_write del obj.old_write
if not hasattr(obj, 'template_ids'):
obj.template_ids = []
if soc: if soc:
obj.template_id = id obj.template_ids.append(id)
obj.old_create = obj.create obj.old_create = obj.create
obj.create = types.MethodType(send_on_create, obj, osv.osv) obj.create = types.MethodType(send_on_create, obj, osv.osv)
if sow: if sow:
obj.template_id = id obj.template_ids.append(id)
obj.old_write = obj.write obj.old_write = obj.write
obj.write = types.MethodType(send_on_write, obj, osv.osv) obj.write = types.MethodType(send_on_write, obj, osv.osv)
return value return value
Expand Down Expand Up @@ -423,12 +427,14 @@ def update_send_on_store(self, cr, uid, ids, context):
if hasattr(obj, 'old_write'): if hasattr(obj, 'old_write'):
obj.write = obj.old_write obj.write = obj.old_write
del obj.old_write del obj.old_write
if not hasattr(obj, 'template_ids'):
obj.template_ids = []
if template.send_on_create: if template.send_on_create:
obj.template_id = template.id obj.template_ids.append(template.id)
obj.old_create = obj.create obj.old_create = obj.create
obj.create = types.MethodType(send_on_create, obj, osv.osv) obj.create = types.MethodType(send_on_create, obj, osv.osv)
if template.send_on_write: if template.send_on_write:
obj.template_id = template.id obj.template_ids.append(template.id)
obj.old_write = obj.write obj.old_write = obj.write
obj.write = types.MethodType(send_on_write, obj, osv.osv) obj.write = types.MethodType(send_on_write, obj, osv.osv)


Expand Down Expand Up @@ -946,7 +952,8 @@ def generate_mail(self,
if template.use_filter and template.filter: if template.use_filter and template.filter:
filtered_record_ids=[] filtered_record_ids=[]
for record in self.pool.get(template.object_name.model).browse(cursor, user, record_ids, context=context): 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) filtered_record_ids.append(record.id)
record_ids=filtered_record_ids record_ids=filtered_record_ids


Expand Down

0 comments on commit 903e8c8

Please sign in to comment.