35
35
_order = 'date desc'
38
'state': fields.selection((('success', 'Success'),
40
'Status', required=True, readonly=True),
41
38
'res_model': fields.char('Resource Object', size=64,
42
39
required=True, readonly=True),
43
40
'res_id': fields.integer('Resource Id', readonly=True),
59
56
"date": lambda *a: time.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
62
def _prepare_log_vals(self, cr, uid, state, model, action, res_id,
59
def _prepare_log_vals(self, cr, uid, model, action, res_id,
63
60
external_id, referential_id, data_record, context=None):
66
62
'res_model': model,
71
67
'data_record': data_record,
74
def _prepare_log_info(self, cr, uid, state, origin_defaults, origin_context, context=None):
70
def _prepare_log_info(self, cr, uid, origin_defaults, origin_context, context=None):
71
exc_type, exc_value, exc_traceback = sys.exc_info()
77
73
'date': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
78
74
'origin_defaults': origin_defaults,
79
'origin_context': origin_context
75
'origin_context': origin_context,
76
'exception_type': exc_type,
77
'error_message': exc_value,
78
'traceback': ''.join(traceback.format_exception(
79
exc_type, exc_value, exc_traceback)),
82
exc_type, exc_value, exc_traceback = sys.exc_info()
84
'exception_type': exc_type,
85
'error_message': exc_value,
86
'traceback': ''.join(traceback.format_exception(
87
exc_type, exc_value, exc_traceback)),
91
def _log_base(self, cr, uid, model, action, referential_id, state=None,
82
def log_failed(self, cr, uid, model, action, referential_id,
92
83
res_id=None, external_id=None,
93
84
data_record=None, defaults=None, context=None):
94
85
defaults = defaults or {}
99
90
# This ensure a backward compatibility, synchro will continue to
100
91
# work exactly the same way if use_external_log is not in context
101
92
if not(existing_line_id or context.get('use_external_log', False)):
106
95
log_cr = pooler.get_db(cr.dbname).cursor()
115
104
if origin_context.get('conn_obj', False):
116
105
del origin_context['conn_obj']
117
106
info = self._prepare_log_info(
118
log_cr, uid, state, origin_defaults, origin_context, context=context)
107
log_cr, uid, origin_defaults, origin_context, context=context)
119
108
if existing_line_id:
126
115
vals = self._prepare_log_vals(
127
log_cr, uid, state, model, action, res_id, external_id,
116
log_cr, uid, model, action, res_id, external_id,
128
117
referential_id, data_record, context=context)
129
118
vals.update(info)
130
119
existing_line_id = self.create(
140
129
return existing_line_id
142
def log_failed(self, cr, uid, model, action, referential_id,
143
res_id=None, external_id=None,
144
data_record=None, defaults=None, context=None):
145
return self._log_base(
146
cr, uid, model, action, referential_id, 'fail', res_id=res_id,
147
external_id=external_id,
148
data_record=data_record, defaults=defaults,
151
131
def log_success(self, cr, uid, model, action, referential_id,
152
132
res_id=None, external_id=None, context=None):
153
133
if res_id is None and external_id is None:
161
141
domain += ('res_id', '=', res_id),
162
142
if external_id is not None:
163
143
domain += ('external_id', '=', external_id),
164
log_ids = self.search(
165
cr, uid, domain, context=context)
166
self.unlink(cr, uid, log_ids, context=context)
144
log_cr = pooler.get_db(cr.dbname).cursor()
146
log_ids = self.search(
147
log_cr, uid, domain, context=context)
148
self.unlink(log_cr, uid, log_ids, context=context)
169
158
def retry(self, cr, uid, ids, context=None):