|
24 | 24 | #########################################################################
|
25 | 25 | #__author__="sharoon"
|
26 | 26 | #__date__ ="$4 Aug, 2009 1:47:16 PM$"
|
27 |
| -from osv import fields,osv |
| 27 | +from osv import fields, osv |
28 | 28 | import netsvc
|
29 | 29 | from tools.translate import _
|
30 | 30 |
|
31 | 31 | class actions_server(osv.osv):
|
32 | 32 | _inherit = 'ir.actions.server'
|
33 | 33 | _description = 'Server action with Power Email update'
|
34 | 34 | _columns = {
|
35 |
| - 'state': fields.selection([ |
36 |
| - ('poweremail','Power Email'), |
37 |
| - ('client_action','Client Action'), |
38 |
| - ('dummy','Dummy'), |
39 |
| - ('loop','Iteration'), |
40 |
| - ('code','Python Code'), |
41 |
| - ('trigger','Trigger'), |
42 |
| - ('email','Email'), |
43 |
| - ('sms','SMS'), |
44 |
| - ('object_create','Create Object'), |
45 |
| - ('object_write','Write Object'), |
46 |
| - ('other','Multi Actions'), |
47 |
| - ], 'Action Type', required=True, size=32, help="Type of the Action that is to be executed"), |
48 |
| - 'poweremail_template':fields.many2one('poweremail.templates','Template',ondelete='cascade')#In view customize such that domain('object_name','=',model_id) |
| 35 | + 'state': fields.selection( |
| 36 | + [ |
| 37 | + ('poweremail', 'Power Email'), |
| 38 | + ('client_action', 'Client Action'), |
| 39 | + ('dummy', 'Dummy'), |
| 40 | + ('loop', 'Iteration'), |
| 41 | + ('code', 'Python Code'), |
| 42 | + ('trigger', 'Trigger'), |
| 43 | + ('email', 'Email'), |
| 44 | + ('sms', 'SMS'), |
| 45 | + ('object_create', 'Create Object'), |
| 46 | + ('object_write', 'Write Object'), |
| 47 | + ('other', 'Multi Actions'), |
| 48 | + ], 'Action Type', |
| 49 | + required=True, size=32, |
| 50 | + help="Type of the Action that is to be executed"), |
| 51 | + 'poweremail_template':fields.many2one( |
| 52 | + 'poweremail.templates', |
| 53 | + 'Template', |
| 54 | + ondelete='cascade') |
49 | 55 | }
|
50 | 56 |
|
51 | 57 | def run(self, cr, uid, ids, context=None):
|
52 |
| - print cr,uid,ids,context |
| 58 | + """ |
| 59 | + Crap code inherited from Server Actions |
| 60 | + TODO: |
| 61 | + Improve quality and check if it affects |
| 62 | + Looks like var names are important in the call |
| 63 | + """ |
53 | 64 | if context is None:
|
54 | 65 | context = {}
|
55 | 66 | logger = netsvc.Logger()
|
56 |
| - logger.notifyChannel('Server Action', netsvc.LOG_INFO, 'Started Server Action with Power Email update') |
| 67 | + logger.notifyChannel( |
| 68 | + 'Server Action', |
| 69 | + netsvc.LOG_INFO, |
| 70 | + 'Started Server Action with Power Email update') |
57 | 71 |
|
58 | 72 | for action in self.browse(cr, uid, ids, context):
|
59 |
| - if action.state=='poweremail': |
| 73 | + obj_pool = self.pool.get(action.model_id.model) |
| 74 | + obj = obj_pool.browse(cr, uid, context['active_id'], context=context) |
| 75 | + cxt = { |
| 76 | + 'context':context, |
| 77 | + 'object': obj, |
| 78 | + 'time':time, |
| 79 | + 'cr': cr, |
| 80 | + 'pool' : self.pool, |
| 81 | + 'uid' : uid |
| 82 | + } |
| 83 | + expr = eval(str(action.condition), cxt) |
| 84 | + if not expr: |
| 85 | + continue |
| 86 | + |
| 87 | + if action.state == 'poweremail': |
60 | 88 | if not action.poweremail_template:
|
61 | 89 | raise osv.except_osv(_('Error'), _("Please specify an template to use for auto email in poweremail !"))
|
62 | 90 | templ_id = action.poweremail_template.id
|
63 | 91 |
|
64 | 92 | self.pool.get('poweremail.templates').generate_mail(cr, uid, templ_id, [context['active_id']], context)
|
65 | 93 | return False
|
66 | 94 | else:
|
67 |
| - return super(actions_server,self).run(cr, uid, ids, context) |
| 95 | + return super(actions_server, self).run(cr, uid, ids, context) |
68 | 96 | actions_server()
|
69 | 97 |
|
70 | 98 | # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
0 commit comments