~openerp-community-leaders/poweremail/poweremail-github-mirror

« back to all changes in this revision

Viewing changes to template.py

  • Committer: Sharoon Thomas
  • Date: 2012-04-20 11:12:10 UTC
  • mfrom: (237.1.2)
  • Revision ID: git-v1:903e8c8b76ec0d2150336cc2dec07aac18e0537a
Merge pull request #21 from eLBati/dev

[FIX] allowing multiple templates to be associated to the same model

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
 
71
71
def send_on_create(self, cr, uid, vals, context=None):
72
72
    id = self.old_create(cr, uid, vals, context)
73
 
    template = self.pool.get('poweremail.templates').browse(cr, uid, self.template_id, context)
74
 
    # Ensure it's still configured to send on create
75
 
    if template.send_on_create:
76
 
        self.pool.get('poweremail.templates').generate_mail(cr, uid, self.template_id, [id], context)
 
73
    templates = self.pool.get('poweremail.templates').browse(cr, uid, self.template_ids, context)
 
74
    for template in templates:
 
75
        # Ensure it's still configured to send on create
 
76
        if template.send_on_create:
 
77
            self.pool.get('poweremail.templates').generate_mail(cr, uid, template.id, [id], context)
77
78
    return id
78
79
 
79
80
def send_on_write(self, cr, uid, ids, vals, context=None):
80
81
    result = self.old_write(cr, uid, ids, vals, context)
81
 
    template = self.pool.get('poweremail.templates').browse(cr, uid, self.template_id, context)
82
 
    # Ensure it's still configured to send on write
83
 
    if template.send_on_write:
84
 
        self.pool.get('poweremail.templates').generate_mail(cr, uid, self.template_id, ids, context)
 
82
    templates = self.pool.get('poweremail.templates').browse(cr, uid, self.template_ids, context)
 
83
    for template in templates:
 
84
        # Ensure it's still configured to send on write
 
85
        if template.send_on_write:
 
86
            self.pool.get('poweremail.templates').generate_mail(cr, uid, template.id, ids, context)
85
87
    return result
86
88
 
87
89
 
120
122
            if hasattr(obj, 'old_write'):
121
123
                obj.write = obj.old_write
122
124
                del obj.old_write
 
125
            if not hasattr(obj, 'template_ids'):
 
126
                obj.template_ids = []
123
127
            if soc:
124
 
                obj.template_id = id
 
128
                obj.template_ids.append(id)
125
129
                obj.old_create = obj.create
126
130
                obj.create = types.MethodType(send_on_create, obj, osv.osv)
127
131
            if sow:
128
 
                obj.template_id = id
 
132
                obj.template_ids.append(id)
129
133
                obj.old_write = obj.write
130
134
                obj.write = types.MethodType(send_on_write, obj, osv.osv)
131
135
        return value
423
427
            if hasattr(obj, 'old_write'):
424
428
                obj.write = obj.old_write
425
429
                del obj.old_write
 
430
            if not hasattr(obj, 'template_ids'):
 
431
                obj.template_ids = []
426
432
            if template.send_on_create:
427
 
                obj.template_id = template.id
 
433
                obj.template_ids.append(template.id)
428
434
                obj.old_create = obj.create
429
435
                obj.create = types.MethodType(send_on_create, obj, osv.osv)
430
436
            if template.send_on_write:
431
 
                obj.template_id = template.id
 
437
                obj.template_ids.append(template.id)
432
438
                obj.old_write = obj.write
433
439
                obj.write = types.MethodType(send_on_write, obj, osv.osv)
434
440
 
946
952
        if template.use_filter and template.filter:
947
953
            filtered_record_ids=[]
948
954
            for record in self.pool.get(template.object_name.model).browse(cursor, user, record_ids, context=context):
949
 
                if safe_eval(template.filter, {'o':record, 'self':self, 'cr':cursor, 'context':context}):
 
955
                if safe_eval(template.filter,
 
956
                    {'o':record, 'self':self, 'cr':cursor, 'context':context, 'uid': user}):
950
957
                    filtered_record_ids.append(record.id)
951
958
            record_ids=filtered_record_ids
952
959