145
153
def _get_default_sequence_number(self, cr, uid, context=None):
146
154
return int(self.pool.get('ir.sequence').get(cr, uid, 'sync.monitor'))
156
def _get_default_instance_id(self, cr, uid, context=None):
157
instance = self.pool.get('res.users').get_browse_user_instance(cr, uid, context)
158
return instance and instance.id
160
def _get_default_destination_instance_id(self, cr, uid, context=None):
161
instance = self.pool.get('res.users').get_browse_user_instance(cr, uid, context)
163
if instance.parent_id:
164
if instance.parent_id.parent_id:
165
return instance.parent_id.parent_id.id
166
return instance.parent_id.id
170
def _get_my_instance(self, cr, uid, ids, field_name, args, context=None):
171
instance = self.pool.get('res.users').get_browse_user_instance(cr, uid, context)
173
return dict.fromkeys(ids, False)
175
for msg in self.read(cr, uid, ids, ['instance']):
176
ret[msg['id']] = msg['instance'] and msg['instance'][0] == instance.id
180
def _search_my_instance(self, cr, uid, obj, name, args, context=None):
182
instance = self.pool.get('res.users').get_browse_user_instance(cr, uid, context)
187
if arg[1] not in ('=', '!='):
188
raise osv.except_osv(_('Error !'), _('Filter not implemented on %s' % name))
189
cond = arg[2] in ('True', 't', '1', 1, True)
193
res += ['|',('instance_id', '=', instance.id),('instance_id', '=', False)]
195
res.append(('instance_id', '!=', instance.id))
148
200
def get_logger(self, cr, uid, defaults={}, context=None):
149
201
return MonitorLogger(cr, uid, defaults=defaults, context=context)
190
242
'error' : fields.text("Messages", readonly=True),
191
243
'state' : fields.function(_is_syncing, method=True, type='selection', string="Is Syncing", selection=[('syncing', 'Syncing'), ('not_syncing', 'Done')]),
245
'instance_id': fields.many2one('msf.instance', 'Instance', select=1),
246
'my_instance': fields.function(_get_my_instance, method=True, type='boolean', fnct_search=_search_my_instance, string="My Instance"),
247
'nb_msg_pull': fields.integer('# pull msg'),
248
'nb_msg_push': fields.integer('# push msg'),
249
'nb_data_pull': fields.integer('# pull data'),
250
'nb_data_push': fields.integer('# push data'),
251
'nb_msg_not_run': fields.integer('# msg not run'),
252
'nb_data_not_run': fields.integer('# data not run'),
253
'destination_instance_id': fields.many2one('msf.instance', 'HQ Instance'),
196
257
'start' : fields.datetime.now,
197
258
'sequence_number' : _get_default_sequence_number,
259
'instance_id': _get_default_instance_id,
260
'destination_instance_id': _get_default_destination_instance_id,
200
263
#must be sequence!
201
_order = "sequence_number desc"
264
_order = "sequence_number desc, start desc, id desc"