26
27
from tools.config import config
27
28
from tools.translate import _
31
32
class project_project(osv.osv):
32
33
_inherit = "project.project"
34
"event_ids": fields.one2many('project.event', 'project_id', 'Events', readonly=True),
35
"event_configuration_ids": fields.one2many('project.event.configuration', 'project_id', 'Event Configuration'),
35
"event_ids": fields.one2many('project.event', 'project_id', 'Events', readonly=True),
36
"event_configuration_ids": fields.one2many('project.event.configuration', 'project_id', 'Event Configuration'),
38
39
def _log_event(self, cr, uid, project_id, values={}, context={}):
39
obj_project_event = self.pool.get('project.event')
40
values['project_id'] = project_id
41
obj_project_event.create(cr, uid, values)
40
values['project_id'] = project_id
41
if type(project_id) == type([]):
42
values['project_id'] = project_id[0]
43
self.pool.get('project.event').create(cr, uid, values, context)
48
47
class project_event_type(osv.osv):
49
48
_name = "project.event.type"
51
'name': fields.char('Name',size=64, required=True),
52
'code': fields.char('Code',size=64, required=True)
50
'name': fields.char('Name',size=64, required=True),
51
'code': fields.char('Code',size=64, required=True)
55
54
project_event_type()
63
62
class project_event(osv.osv):
64
63
_name = "project.event"
66
'name': fields.char('Events',size=64, required=True),
67
'description': fields.text('Description'),
68
'res_id': fields.integer('Resource Id'),
65
'name': fields.char('Events', size=64, required=True),
66
'description': fields.text('Description'),
67
'res_id': fields.integer('Resource Id'),
69
68
'project_id': fields.many2one('project.project', 'Project', select=True, required=True),
70
69
'date': fields.datetime('Date', size=16),
71
70
'user_id': fields.many2one('res.users', 'User', required=True),
72
'action' : fields.selection([('create','Create'),('write','Modify'),('unlink','Remove')], 'Action', required=True),
73
'type': fields.selection(_links_get, 'Type of Event', required=True),
71
'action' : fields.selection([('create','Create'),('write','Modify'),('unlink','Remove')], 'Action', required=True),
72
'type': fields.selection(_links_get, 'Type of Event', required=True),
75
74
_order = 'date desc'
77
76
'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
79
79
def create(self, cr, uid, values, *args, **kwargs):
83
83
if key != 'attach':
84
new_values[key] = values[key]
84
new_values[key] = values[key]
85
85
event_id = super(project_event, self).create(cr, uid, new_values, *args, **kwargs)
87
87
project_id = values.get('project_id',False)
89
89
obj_configuration = self.pool.get('project.event.configuration')
90
90
config_ids = obj_configuration.search(cr, uid, [('project_id','=',project_id)])
91
91
obj_configuration.run(cr, uid, config_ids, values)
93
95
class project_event_configuration(osv.osv):
94
96
_name = "project.event.configuration"
96
98
'name': fields.char('Name',size=64, required=True),
97
'project_id': fields.many2one('project.project', 'Project', select=True, required=True),
98
'create' :fields.boolean('On Create'),
99
'write' :fields.boolean('On Write'),
99
'project_id': fields.many2one('project.project', 'Project', select=True, required=True),
100
'create' :fields.boolean('On Create'),
101
'write' :fields.boolean('On Write'),
100
102
'unlink' :fields.boolean('On Delete'),
101
'type': fields.selection(_links_get, 'Type of Event', required=True),
103
'type': fields.selection(_links_get, 'Type of Event', required=True),
102
104
'action_type': fields.selection([('email','Email'),('sms','SMS'),('request','Request')], 'Action Type', required=True),
105
107
'action_type': lambda *a: 'email',
108
def send_mail(self, to_address, subject, body, attach=None):
109
sent = tools.email_send(config['email_from'], to_address, subject, body, attach=attach)
110
def send_mail(self, to_address, subject, body, attach=None):
111
sent = tools.email_send(config['email_from'], to_address, subject, body, attach=attach, ssl=True)
110
112
logger = netsvc.Logger()
112
114
logger.notifyChannel('email', netsvc.LOG_ERROR, 'Failed to send email to : %s' % (to_address))
114
116
logger.notifyChannel('email', netsvc.LOG_INFO, 'Email successfully send to : %s' % (to_address))
116
118
def run(self, cr, uid, ids, values, context={}):
117
for config in self.browse(cr, uid, ids, context=context):
119
for config in self.browse(cr, uid, ids, context=context):
118
120
if values.get('action',False) and config[values['action']] and config.type == values.get('type',False):
120
122
for member in config.project_id.members:
128
130
action = 'Modified'
129
131
elif config.unlink:
130
132
action = 'Deleted'
131
subject = '[%s] %s - %d : %s (%s)' %(config.project_id.name, config.type, values.get('res_id',False), values.get('name',False),action)
133
subject = '[%s] %s - %d : %s ' %(config.project_id.name, config.type, values.get('res_id',False), values.get('name',False))
132
134
body = values.get('description',False)
133
self.send_mail(action_to, subject, body, attach=values.get('attach',False))
135
self.send_mail(action_to, subject, body, attach=values.get('attach',False))
134
136
elif config.action_type == 'sms':
137
139
elif config.action_type == 'request':
141
143
project_event_configuration()
143
145
class project_task(osv.osv):
144
146
_inherit = 'project.task'
146
148
def create(self, cr, uid, values, context={}):
147
149
res = super(project_task, self).create(cr, uid, values, context=context)
149
151
task = self.browse(cr, uid, res, context=context)
153
desc = ''' Hello, \n \t The new task is created for the Project: %s \n\n And its Details are: \n \n Task: %s \n Created on: %s \n Assigned to: %s \n Deadline: %s \n Planned hours: %s \n Remaining hours: %s \n Total Hours: %s \n For Partner: %s \n Task Summary: \n ====== \n %s \n \n ======= \n \nThanks,\nProject Manager \n%s''' \
154
%(task.project_id.name,\
155
task.name, task.date_start, task.user_id.name, \
156
task.date_deadline or '', task.planned_hours or 0, \
157
task.remaining_hours or 0, task.total_hours or 0,\
158
task.partner_id and task.partner_id.name or '',\
159
task.description or '',task.project_id.manager and task.project_id.manager.name or '')
151
160
self.pool.get('project.project')._log_event(cr, uid, task.project_id.id, {
152
161
'res_id' : task.id,
154
'description' : task.description,
163
'description' : desc,
156
165
'action' : 'create',
157
166
'type' : 'task'})
160
169
def write(self, cr, uid, ids, vals, context={}):
170
task = self.browse(cr, uid, ids)[0]
161
171
res = super(project_task, self).write(cr, uid, ids, vals, context={})
163
for task in self.browse(cr, uid, ids, context=context):
165
self.pool.get('project.project')._log_event(cr, uid, task.project_id.id, {
168
'description' : task.description,
173
task_data = self.browse(cr, uid, ids[0], context)
174
desc = '''Hello ,\n\n The task is updated for the project: %s\n\nModified Datas are:\n''' %(str(task.project_id.name),)
176
if val.endswith('id') or val.endswith('ids'):
178
desc += val + ':' + str(vals[val]) + "\n"
179
desc += '\nThanks,\n' + 'Project Manager\n' + (task_data.project_id.manager and task_data.project_id.manager.name) or ''
180
self.pool.get('project.project')._log_event(cr, uid, task.project_id.id, {
182
'name' : task.name or '',
183
'description' : desc,
175
191
class document_file(osv.osv):
176
192
_inherit = 'ir.attachment'
178
194
def create(self, cr, uid, values, *args, **kwargs):
179
195
res = super(document_file, self).create(cr, uid, values, *args, **kwargs)
181
197
document = self.browse(cr, uid, res)
182
if document.res_model == 'project.project' and document.res_id:
198
if document.file_size >= 1073741824:
199
size = str((document.file_size) / 1024 / 1024 / 1024) + ' GB'
200
elif document.file_size >= 1048576:
201
size = str((document.file_size) / 1024 / 1024) + ' MB'
202
elif document.file_size >= 1024:
203
size = str((document.file_size) / 1024) + ' KB'
204
elif document.file_size < 1024:
205
size = str(document.file_size) + ' bytes'
207
if document.res_model == 'project.project' and document.res_id:
208
desc = ''' Hello, \n \n \t The new document is uploaded on the Project: %s \n\n Document attached: %s \n Attachment name: %s \n Owner: %s \n Size: %s \n Creator: %s \n Date Created: %s \n Document Summary: %s \n \n Thanks,\n Project Manager\n''' \
209
%(document.title, document.datas_fname, document.name, \
210
document.user_id.name, size, document.create_uid.name, document.create_date, document.description or '')
183
211
self.pool.get('project.project')._log_event(cr, uid, document.res_id, {
184
212
'res_id' : document.id,
185
213
'name' : document.name,
186
'description' : document.description,
214
'description' :desc,#document description,
188
216
'attach' : [(document.datas_fname, document.datas)],
189
217
'action' : 'create',
190
'type' : 'document'})
218
'type' : 'document'})
196
223
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: