diff --git a/addons/account/partner_view.xml b/addons/account/partner_view.xml
index a22e6860a15..1c1ae438094 100644
--- a/addons/account/partner_view.xml
+++ b/addons/account/partner_view.xml
@@ -72,8 +72,8 @@
2
-
-
+
+
@@ -121,7 +121,7 @@
-
+
diff --git a/addons/audittrail/audittrail.py b/addons/audittrail/audittrail.py
index 80166298edb..3a56f15ed3d 100644
--- a/addons/audittrail/audittrail.py
+++ b/addons/audittrail/audittrail.py
@@ -25,6 +25,7 @@ from tools.translate import _
import ir
import pooler
import time
+import tools
class audittrail_rule(osv.osv):
"""
@@ -33,25 +34,28 @@ class audittrail_rule(osv.osv):
_name = 'audittrail.rule'
_description = "Audittrail Rule"
_columns = {
- "name": fields.char("Rule Name", size=32, required=True),
- "object_id": fields.many2one('ir.model', 'Object', required=True),
- "user_id": fields.many2many('res.users', 'audittail_rules_users',
- 'user_id', 'rule_id', 'Users'),
- "log_read": fields.boolean("Log reads"),
- "log_write": fields.boolean("Log writes"),
- "log_unlink": fields.boolean("Log deletes"),
- "log_create": fields.boolean("Log creates"),
- "state": fields.selection((("draft", "Draft"),
- ("subscribed", "Subscribed")),
- "State", required=True),
- "action_id": fields.many2one('ir.actions.act_window', "Action ID"),
+ "name": fields.char("Rule Name", size=32, required=True),
+ "object_id": fields.many2one('ir.model', 'Object', required=True),
+ "user_id": fields.many2many('res.users', 'audittail_rules_users',
+ 'user_id', 'rule_id', 'Users', help="if User is not added then it will applicable for all users"),
+ "log_read": fields.boolean("Log Reads"),
+ "log_write": fields.boolean("Log Writes"),
+ "log_unlink": fields.boolean("Log Deletes"),
+ "log_create": fields.boolean("Log Creates"),
+ "log_action": fields.boolean("Log Action"),
+ "log_workflow": fields.boolean("Log Workflow"),
+ "state": fields.selection((("draft", "Draft"),
+ ("subscribed", "Subscribed")),
+ "State", required=True),
+ "action_id": fields.many2one('ir.actions.act_window', "Action ID"),
+
}
_defaults = {
- 'state': lambda *a: 'draft',
- 'log_create': lambda *a: 1,
- 'log_unlink': lambda *a: 1,
- 'log_write': lambda *a: 1,
+ 'state': lambda *a: 'draft',
+ 'log_create': lambda *a: 1,
+ 'log_unlink': lambda *a: 1,
+ 'log_write': lambda *a: 1,
}
_sql_constraints = [
@@ -65,7 +69,7 @@ class audittrail_rule(osv.osv):
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks,
@param ids: List of Auddittrail Rule’s IDs.
- @return: True
+ @return: True
"""
obj_action = self.pool.get('ir.actions.act_window')
obj_model = self.pool.get('ir.model.data')
@@ -74,20 +78,20 @@ class audittrail_rule(osv.osv):
obj = self.pool.get(thisrule.object_id.model)
if not obj:
raise osv.except_osv(
- _('WARNING: audittrail is not part of the pool'),
+ _('WARNING: audittrail is not part of the pool'),
_('Change audittrail depends -- Setting rule as DRAFT'))
self.write(cr, uid, [thisrule.id], {"state": "draft"})
val = {
- "name": 'View Log',
- "res_model": 'audittrail.log',
- "src_model": thisrule.object_id.model,
+ "name": 'View Log',
+ "res_model": 'audittrail.log',
+ "src_model": thisrule.object_id.model,
"domain": "[('object_id','=', " + str(thisrule.object_id.id) + "), ('res_id', '=', active_id)]"
}
- id = obj_action.create(cr, uid, val)
- self.write(cr, uid, [thisrule.id], {"state": "subscribed", "action_id": id})
+ action_id = obj_action.create(cr, uid, val)
+ self.write(cr, uid, [thisrule.id], {"state": "subscribed", "action_id": action_id})
keyword = 'client_action_relate'
- value = 'ir.actions.act_window,' + str(id)
+ value = 'ir.actions.act_window,' + str(action_id)
res = obj_model.ir_set(cr, uid, 'action', keyword, 'View_log_' + thisrule.object_id.model, [thisrule.object_id.model], value, replace=True, isobject=True, xml_id=False)
#End Loop
return True
@@ -98,7 +102,7 @@ class audittrail_rule(osv.osv):
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks,
@param ids: List of Auddittrail Rule’s IDs.
- @return: True
+ @return: True
"""
obj_action = self.pool.get('ir.actions.act_window')
val_obj = self.pool.get('ir.values')
@@ -127,17 +131,28 @@ class audittrail_log(osv.osv):
_name = 'audittrail.log'
_description = "Audittrail Log"
+ def _name_get_resname(self, cr, uid, ids, *args):
+ data = {}
+ for resname in self.browse(cr, uid, ids,[]):
+ model_object = resname.object_id
+ res_id = resname.res_id
+ if model_object and res_id:
+ model_pool = self.pool.get(model_object.model)
+ res = model_pool.read(cr, uid, res_id, ['name'])
+ data[resname.id] = res['name']
+ else:
+ data[resname.id] = False
+ return data
+
_columns = {
- "name": fields.char("Name", size=32),
- "object_id": fields.many2one('ir.model', 'Object'),
- "user_id": fields.many2one('res.users', 'User'),
- "method": fields.selection((('read', 'Read'),
- ('write', 'Write'),
- ('unlink', 'Delete'),
- ('create', 'Create')), "Method"),
- "timestamp": fields.datetime("Date"),
- "res_id": fields.integer('Resource Id'),
- "line_ids": fields.one2many('audittrail.log.line', 'log_id', 'Log lines'),
+ "name": fields.char("Resource Name",size=64),
+ # "name": fields.function(_name_get_resname, type='char', string='Resource Name', method=True),
+ "object_id": fields.many2one('ir.model', 'Object'),
+ "user_id": fields.many2one('res.users', 'User'),
+ "method": fields.char("Method", size=64),
+ "timestamp": fields.datetime("Date"),
+ "res_id": fields.integer('Resource Id'),
+ "line_ids": fields.one2many('audittrail.log.line', 'log_id', 'Log lines'),
}
_defaults = {
@@ -155,14 +170,14 @@ class audittrail_log_line(osv.osv):
_name = 'audittrail.log.line'
_description = "Log Line"
_columns = {
- 'field_id': fields.many2one('ir.model.fields', 'Fields', required=True),
- 'log_id': fields.many2one('audittrail.log', 'Log'),
- 'log': fields.integer("Log ID"),
- 'old_value': fields.text("Old Value"),
- 'new_value': fields.text("New Value"),
- 'old_value_text': fields.text('Old value Text'),
- 'new_value_text': fields.text('New value Text'),
- 'field_description': fields.char('Field Description', size=64),
+ 'field_id': fields.many2one('ir.model.fields', 'Fields', required=True),
+ 'log_id': fields.many2one('audittrail.log', 'Log'),
+ 'log': fields.integer("Log ID"),
+ 'old_value': fields.text("Old Value"),
+ 'new_value': fields.text("New Value"),
+ 'old_value_text': fields.text('Old value Text'),
+ 'new_value_text': fields.text('New value Text'),
+ 'field_description': fields.char('Field Description', size=64),
}
audittrail_log_line()
@@ -170,276 +185,366 @@ audittrail_log_line()
class audittrail_objects_proxy(osv_pool):
""" Uses Object proxy for auditing changes on object of subscribed Rules"""
-
- def get_value_text(self, cr, uid, field_name, values, object, context=None):
+
+ def get_value_text(self, cr, uid, field_name, values, model, context=None):
"""
Gets textual values for the fields
e.g.: For field of type many2one it gives its name value instead of id
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks,
- @param field_name: List of fields for text values
- @param values: Values for field to be converted into textual values
- @return: values: List of textual values for given fields
+ @param field_name: List of fields for text values
+ @param values: Values for field to be converted into textual values
+ @return: values: List of textual values for given fields
"""
if not context:
context = {}
pool = pooler.get_pool(cr.dbname)
- f_id = pool.get('ir.model.fields').search(cr, uid, [('name', '=', field_name), ('model_id', '=', object.id)])
- if f_id:
- field = pool.get('ir.model.fields').read(cr, uid, f_id)[0]
- model = field['relation']
+ field_pool = pool.get('ir.model.fields')
+ model_pool = pool.get('ir.model')
+ obj_pool = pool.get(model.model)
+ if obj_pool._inherits:
+ inherits_ids = model_pool.search(cr, uid, [('model', '=', obj_pool._inherits.keys()[0])])
+ field_ids = field_pool.search(cr, uid, [('name', '=', field_name), ('model_id', 'in', (model.id, inherits_ids[0]))])
+ else:
+ field_ids = field_pool.search(cr, uid, [('name', '=', field_name), ('model_id', '=', model.id)])
+ field_id = field_ids and field_ids[0] or False
+ assert field_id, _("'%s' field is not exits in '%s' model" %(field_name, model.model))
- if field['ttype'] == 'many2one':
- if values:
- if type(values) == tuple:
- values = values[0]
- val = pool.get(model).read(cr, uid, [values], [pool.get(model)._rec_name])
- if val:
- return val[0][pool.get(model)._rec_name]
- elif field['ttype'] == 'many2many':
- value = []
- if values:
- for id in values:
- val = pool.get(model).read(cr, uid, [id], [pool.get(model)._rec_name])
- if val:
- value.append(val[0][pool.get(model)._rec_name])
- return value
+ field = field_pool.read(cr, uid, field_id)
+ relation_model = field['relation']
+ relation_model_pool = relation_model and pool.get(relation_model) or False
- elif field['ttype'] == 'one2many':
- if values:
- value = []
- for id in values:
- val = pool.get(model).read(cr, uid, [id], [pool.get(model)._rec_name])
+ if field['ttype'] == 'many2one':
+ res = False
+ relation_id = False
+ if values and type(values) == tuple:
+ relation_id = values[0]
+ if relation_id and relation_model_pool:
+ relation_model_object = relation_model_pool.read(cr, uid, relation_id, [relation_model_pool._rec_name])
+ res = relation_model_object[relation_model_pool._rec_name]
+ return res
- if val:
- value.append(val[0][pool.get(model)._rec_name])
- return value
- return values
+ elif field['ttype'] in ('many2many','one2many'):
+ res = []
+ for relation_model_object in relation_model_pool.read(cr, uid, values, [relation_model_pool._rec_name]):
+ res.append(relation_model_object[relation_model_pool._rec_name])
+ return res
- def create_log_line(self, cr, uid, id, object, lines=[]):
+ return values
+
+ def create_log_line(self, cr, uid, log_id, model, lines=[]):
"""
Creates lines for changed fields with its old and new values
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks,
- @param object: Object who's values are being changed
+ @param model: Object who's values are being changed
@param lines: List of values for line is to be created
"""
-
pool = pooler.get_pool(cr.dbname)
- obj = pool.get(object.model)
+ obj_pool = pool.get(model.model)
+ model_pool = pool.get('ir.model')
+ field_pool = pool.get('ir.model.fields')
+ log_line_pool = pool.get('audittrail.log.line')
#start Loop
for line in lines:
- if obj._inherits:
- inherits_ids = pool.get('ir.model').search(cr, uid, [('model', '=', obj._inherits.keys()[0])])
- f_id = pool.get('ir.model.fields').search(cr, uid, [('name', '=', line['name']), ('model_id', 'in', (object.id, inherits_ids[0]))])
+ if obj_pool._inherits:
+ inherits_ids = model_pool.search(cr, uid, [('model', '=', obj_pool._inherits.keys()[0])])
+ field_ids = field_pool.search(cr, uid, [('name', '=', line['name']), ('model_id', 'in', (model.id, inherits_ids[0]))])
else:
- f_id = pool.get('ir.model.fields').search(cr, uid, [('name', '=', line['name']), ('model_id', '=', object.id)])
- if f_id:
- fields = pool.get('ir.model.fields').read(cr, uid, f_id)
- old_value = 'old_value' in line and line['old_value'] or ''
- new_value = 'new_value' in line and line['new_value'] or ''
- old_value_text = 'old_value_text' in line and line['old_value_text'] or ''
- new_value_text = 'new_value_text' in line and line['new_value_text'] or ''
-
- if old_value_text == new_value_text:
- continue
- if fields[0]['ttype'] == 'many2one':
- if type(old_value) == tuple:
- old_value = old_value[0]
- if type(new_value) == tuple:
- new_value = new_value[0]
- vals = {
- "log_id": id,
- "field_id": f_id[0],
- "old_value": old_value,
- "new_value": new_value,
- "old_value_text": old_value_text,
- "new_value_text": new_value_text,
- "field_description": fields[0]['field_description']
- }
- line_id = pool.get('audittrail.log.line').create(cr, uid, vals)
- cr.commit()
- #End Loop
+ field_ids = field_pool.search(cr, uid, [('name', '=', line['name']), ('model_id', '=', model.id)])
+ field_id = field_ids and field_ids[0] or False
+ assert field_id, _("'%s' field is not exits in '%s' model" %(line['name'], model.model))
+
+ field = field_pool.read(cr, uid, field_id)
+ old_value = 'old_value' in line and line['old_value'] or ''
+ new_value = 'new_value' in line and line['new_value'] or ''
+ old_value_text = 'old_value_text' in line and line['old_value_text'] or ''
+ new_value_text = 'new_value_text' in line and line['new_value_text'] or ''
+
+ if old_value_text == new_value_text:
+ continue
+ if field['ttype'] == 'many2one':
+ if type(old_value) == tuple:
+ old_value = old_value[0]
+ if type(new_value) == tuple:
+ new_value = new_value[0]
+ vals = {
+ "log_id": log_id,
+ "field_id": field_id,
+ "old_value": old_value,
+ "new_value": new_value,
+ "old_value_text": old_value_text,
+ "new_value_text": new_value_text,
+ "field_description": field['field_description']
+ }
+ line_id = log_line_pool.create(cr, uid, vals)
+ #End Loop
return True
- def log_fct(self, db, uid, object, method, fct_src, *args):
+
+ def log_fct(self, db, uid, model, method, fct_src, *args):
"""
Logging function: This function is performs logging oprations according to method
@param db: the current database
@param uid: the current user’s ID for security checks,
@param object: Object who's values are being changed
- @param method: method to log: create, read, write, unlink
+ @param method: method to log: create, read, write, unlink
@param fct_src: execute method of Object proxy
-
- @return: Returns result as per method of Object proxy
+
+ @return: Returns result as per method of Object proxy
"""
- logged_uids = []
+ res2 = args
pool = pooler.get_pool(db)
cr = pooler.get_db(db).cursor()
- obj_ids = pool.get('ir.model').search(cr, uid, [('model', '=', object)])
- model_object = pool.get('ir.model').browse(cr, uid, obj_ids)[0]
+ resource_pool = pool.get(model)
+ log_pool = pool.get('audittrail.log')
+ model_pool = pool.get('ir.model')
+
+ model_ids = model_pool.search(cr, uid, [('model', '=', model)])
+ model_id = model_ids and model_ids[0] or False
+ assert model_id, _("'%s' Model is not exits..." %(model))
+ model = model_pool.browse(cr, uid, model_id)
+
if method in ('create'):
- res_id = fct_src(db, uid, object, method, *args)
+ res_id = fct_src(db, uid, model.model, method, *args)
cr.commit()
- new_value = pool.get(model_object.model).read(cr, uid, [res_id], args[0].keys())[0]
- if 'id' in new_value:
- del new_value['id']
- if not logged_uids or uid in logged_uids:
- resource_name = pool.get(model_object.model).name_get(cr, uid, [res_id])
- resource_name = resource_name and resource_name[0][1] or ''
- vals = {
- "method": method,
- "object_id": model_object.id,
- "user_id": uid, "res_id": res_id,
- "name": resource_name
- }
- id = pool.get('audittrail.log').create(cr, uid, vals)
- lines = []
- for field in new_value:
- if new_value[field]:
- line = {
- 'name': field,
- 'new_value': new_value[field],
- 'new_value_text': self.get_value_text(cr, uid, field, new_value[field], model_object)
- }
- lines.append(line)
- self.create_log_line(cr, uid, id, model_object, lines)
+ resource = resource_pool.read(cr, uid, res_id, args[0].keys())
+ vals = {
+ "method": method,
+ "object_id": model.id,
+ "user_id": uid,
+ "res_id": resource['id'],
+ }
+ if 'id' in resource:
+ del resource['id']
+ log_id = log_pool.create(cr, uid, vals)
+ lines = []
+ for field in resource:
+ line = {
+ 'name': field,
+ 'new_value': resource[field],
+ 'new_value_text': self.get_value_text(cr, uid, field, resource[field], model)
+ }
+ lines.append(line)
+ self.create_log_line(cr, uid, log_id, model, lines)
+
cr.commit()
cr.close()
return res_id
- if method in ('write'):
- res_ids = args[0]
- for res_id in res_ids:
- old_values = pool.get(model_object.model).read(cr, uid, res_id, args[1].keys())
- old_values_text = {}
- for field in args[1].keys():
- old_values_text[field] = self.get_value_text(cr, uid, field, old_values[field], model_object)
- res = fct_src(db, uid, object, method, *args)
- cr.commit()
- if res:
- new_values = pool.get(model_object.model).read(cr, uid, res_ids, args[1].keys())[0]
- if not logged_uids or uid in logged_uids:
- resource_name = pool.get(model_object.model).name_get(cr, uid, [res_id])
- resource_name = resource_name and resource_name[0][1] or ''
- id = pool.get('audittrail.log').create(cr, uid, {"method": method, "object_id": model_object.id, "user_id": uid, "res_id": res_id, "name": resource_name})
- lines = []
- for field in args[1].keys():
- if args[1].keys():
- line = {
- 'name': field,
- 'new_value': field in new_values and new_values[field] or '',
- 'old_value': field in old_values and old_values[field] or '',
- 'new_value_text': self.get_value_text(cr, uid, field, new_values[field], model_object),
- 'old_value_text': old_values_text[field]
- }
- lines.append(line)
- cr.commit()
- self.create_log_line(cr, uid, id, model_object, lines)
- cr.close()
- return res
-
- if method in ('read'):
+ elif method in ('read'):
res_ids = args[0]
old_values = {}
- res = fct_src(db, uid, object, method, *args)
+ res = fct_src(db, uid, model.model, method, *args)
if type(res) == list:
-
for v in res:
old_values[v['id']] = v
else:
old_values[res['id']] = res
for res_id in old_values:
- if not logged_uids or uid in logged_uids:
- resource_name = pool.get(model_object.model).name_get(cr, uid, [res_id])
- resource_name = resource_name and resource_name[0][1] or ''
- id = pool.get('audittrail.log').create(cr, uid, {"method": method, "object_id": model_object.id, "user_id": uid, "res_id": res_id, "name": resource_name})
- lines = []
- for field in old_values[res_id]:
- if old_values[res_id][field]:
- line = {
- 'name': field,
- 'old_value': old_values[res_id][field],
- 'old_value_text': self.get_value_text(cr, uid, field, old_values[res_id][field], model_object)
- }
- lines.append(line)
- cr.commit()
- self.create_log_line(cr, uid, id, model_object, lines)
+ vals = {
+ "method": method,
+ "object_id": model.id,
+ "user_id": uid,
+ "res_id": res_id,
+
+ }
+ log_id = log_pool.create(cr, uid, vals)
+ lines = []
+ for field in old_values[res_id]:
+ line = {
+ 'name': field,
+ 'old_value': old_values[res_id][field],
+ 'old_value_text': self.get_value_text(cr, uid, field, old_values[res_id][field], model)
+ }
+ lines.append(line)
+
+ self.create_log_line(cr, uid, log_id, model, lines)
+
cr.close()
return res
- if method in ('unlink'):
+ elif method in ('unlink'):
res_ids = args[0]
old_values = {}
for res_id in res_ids:
- old_values[res_id] = pool.get(model_object.model).read(cr, uid, res_id, [])
+ old_values[res_id] = resource_pool.read(cr, uid, res_id)
for res_id in res_ids:
- if not logged_uids or uid in logged_uids:
- resource_name = pool.get(model_object.model).name_get(cr, uid, [res_id])
- resource_name = resource_name and resource_name[0][1] or ''
- id = pool.get('audittrail.log').create(cr, uid, {"method": method, "object_id": model_object.id, "user_id": uid, "res_id": res_id, "name": resource_name})
- lines = []
- for field in old_values[res_id]:
- if old_values[res_id][field]:
- line = {
- 'name': field,
- 'old_value': old_values[res_id][field],
- 'old_value_text': self.get_value_text(cr, uid, field, old_values[res_id][field], model_object)
- }
- lines.append(line)
- cr.commit()
- self.create_log_line(cr, uid, id, model_object, lines)
- res = fct_src(db, uid, object, method, *args)
+ vals = {
+ "method": method,
+ "object_id": model.id,
+ "user_id": uid,
+ "res_id": res_id,
+
+ }
+ log_id = log_pool.create(cr, uid, vals)
+ lines = []
+ for field in old_values[res_id]:
+ if field in ('id'):
+ continue
+ line = {
+ 'name': field,
+ 'old_value': old_values[res_id][field],
+ 'old_value_text': self.get_value_text(cr, uid, field, old_values[res_id][field], model)
+ }
+ lines.append(line)
+
+ self.create_log_line(cr, uid, log_id, model, lines)
+ res = fct_src(db, uid, model.model, method, *args)
+ cr.commit()
cr.close()
return res
- cr.close()
+ else:
+ res_ids = args[0]
+ old_values = {}
+ fields = []
+ if len(args)>1 and type(args[1]) == dict:
+ fields = args[1].keys()
+ if type(res_ids) in (long, int):
+ res_ids = [res_ids]
+ if res_ids:
+ for resource in resource_pool.read(cr, uid, res_ids):
+ resource_id = resource['id']
+ if 'id' in resource:
+ del resource['id']
+ old_values_text = {}
+ old_value = {}
+ for field in resource.keys():
+ old_value[field] = resource[field]
+ old_values_text[field] = self.get_value_text(cr, uid, field, resource[field], model)
+ old_values[resource_id] = {'text':old_values_text, 'value': old_value}
- def execute(self, db, uid, object, method, *args, **kw):
+ res = fct_src(db, uid, model.model, method, *args)
+ cr.commit()
+
+ if res_ids:
+ for resource in resource_pool.read(cr, uid, res_ids):
+ resource_id = resource['id']
+ if 'id' in resource:
+ del resource['id']
+ vals = {
+ "method": method,
+ "object_id": model.id,
+ "user_id": uid,
+ "res_id": resource_id,
+ }
+
+
+ log_id = log_pool.create(cr, uid, vals)
+ lines = []
+ for field in resource.keys():
+ line = {
+ 'name': field,
+ 'new_value': resource[field],
+ 'old_value': old_values[resource_id]['value'][field],
+ 'new_value_text': self.get_value_text(cr, uid, field, resource[field], model),
+ 'old_value_text': old_values[resource_id]['text'][field]
+ }
+ lines.append(line)
+
+ self.create_log_line(cr, uid, log_id, model, lines)
+ cr.commit()
+ cr.close()
+ return res
+ return True
+
+
+
+ def execute(self, db, uid, model, method, *args, **kw):
"""
Overrides Object Proxy execute method
@param db: the current database
@param uid: the current user’s ID for security checks,
@param object: Object who's values are being changed
- @param method: method to log: create, read, write, unlink
-
- @return: Returns result as per method of Object proxy
+ @param method: get any method and create log
+
+ @return: Returns result as per method of Object proxy
"""
pool = pooler.get_pool(db)
+ model_pool = pool.get('ir.model')
+ rule_pool = pool.get('audittrail.rule')
cr = pooler.get_db(db).cursor()
cr.autocommit(True)
logged_uids = []
fct_src = super(audittrail_objects_proxy, self).execute
- def my_fct(db, uid, object, method, *args):
- field = method
+ def my_fct(db, uid, model, method, *args):
rule = False
- obj_ids = pool.get('ir.model').search(cr, uid, [('model', '=', object)])
- for obj_name in pool.obj_list():
- if obj_name == 'audittrail.rule':
+ model_ids = model_pool.search(cr, uid, [('model', '=', model)])
+ model_id = model_ids and model_ids[0] or False
+
+ for model_name in pool.obj_list():
+ if model_name == 'audittrail.rule':
rule = True
if not rule:
- return fct_src(db, uid, object, method, *args)
- if not obj_ids:
- return fct_src(db, uid, object, method, *args)
- rule_ids = pool.get('audittrail.rule').search(cr, uid, [('object_id', '=', obj_ids[0]), ('state', '=', 'subscribed')])
- if not rule_ids:
- return fct_src(db, uid, object, method, *args)
+ return fct_src(db, uid, model, method, *args)
+ if not model_id:
+ return fct_src(db, uid, model, method, *args)
- for thisrule in pool.get('audittrail.rule').browse(cr, uid, rule_ids):
+ rule_ids = rule_pool.search(cr, uid, [('object_id', '=', model_id), ('state', '=', 'subscribed')])
+ if not rule_ids:
+ return fct_src(db, uid, model, method, *args)
+
+ for thisrule in rule_pool.browse(cr, uid, rule_ids):
for user in thisrule.user_id:
logged_uids.append(user.id)
if not logged_uids or uid in logged_uids:
- if field in ('read', 'write', 'create', 'unlink'):
- if getattr(thisrule, 'log_' + field):
- return self.log_fct(db, uid, object, method, fct_src, *args)
- return fct_src(db, uid, object, method, *args)
- res = my_fct(db, uid, object, method, *args)
+ if method in ('read', 'write', 'create', 'unlink'):
+ if getattr(thisrule, 'log_' + method):
+ return self.log_fct(db, uid, model, method, fct_src, *args)
+
+ elif method not in ('default_get','read','fields_view_get','fields_get','search','search_count','name_search','name_get','get','request_get', 'get_sc', 'unlink', 'write', 'create'):
+ if thisrule.log_action:
+ return self.log_fct(db, uid, model, method, fct_src, *args)
+
+ return fct_src(db, uid, model, method, *args)
+ res = my_fct(db, uid, model, method, *args)
cr.close()
return res
+
+ def exec_workflow(self, db, uid, model, method, *args, **argv):
+ pool = pooler.get_pool(db)
+ cr = pooler.get_db(db).cursor()
+ cr.autocommit(True)
+ logged_uids = []
+ fct_src = super(audittrail_objects_proxy, self).exec_workflow
+ field = method
+ rule = False
+ model_pool = pool.get('ir.model')
+ rule_pool = pool.get('audittrail.rule')
+ model_ids = model_pool.search(cr, uid, [('model', '=', model)])
+ for obj_name in pool.obj_list():
+ if obj_name == 'audittrail.rule':
+ rule = True
+ if not rule:
+ cr.close()
+ return super(audittrail_objects_proxy, self).exec_workflow(db, uid, model, method, *args, **argv)
+ if not model_ids:
+ cr.close()
+ return super(audittrail_objects_proxy, self).exec_workflow(db, uid, model, method, *args, **argv)
+
+ rule_ids = rule_pool.search(cr, uid, [('object_id', 'in', model_ids), ('state', '=', 'subscribed')])
+ if not rule_ids:
+ cr.close()
+ return super(audittrail_objects_proxy, self).exec_workflow(db, uid, model, method, *args, **argv)
+
+ for thisrule in rule_pool.browse(cr, uid, rule_ids):
+ for user in thisrule.user_id:
+ logged_uids.append(user.id)
+ if not logged_uids or uid in logged_uids:
+ if thisrule.log_workflow:
+ cr.close()
+ return self.log_fct(db, uid, model, method, fct_src, *args)
+ cr.close()
+ return super(audittrail_objects_proxy, self).exec_workflow(db, uid, model, method, *args, **argv)
+
+ cr.close()
+ return True
+
audittrail_objects_proxy()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/audittrail/audittrail_view.xml b/addons/audittrail/audittrail_view.xml
index a79e6a0b6c0..17b2594d470 100644
--- a/addons/audittrail/audittrail_view.xml
+++ b/addons/audittrail/audittrail_view.xml
@@ -12,12 +12,15 @@
diff --git a/addons/crm/__openerp__.py b/addons/crm/__openerp__.py
index 5dcb655e8db..6e7a8edb807 100644
--- a/addons/crm/__openerp__.py
+++ b/addons/crm/__openerp__.py
@@ -69,7 +69,6 @@ Create dashboard for CRM that includes:
'crm_opportunity_data.xml',
'crm_phonecall_data.xml',
],
-
'update_xml': [
'wizard/crm_lead_to_partner_view.xml',
'wizard/crm_lead_to_opportunity_view.xml',
diff --git a/addons/crm/crm_data.xml b/addons/crm/crm_data.xml
index 1873f53f573..e8d5965a4c0 100644
--- a/addons/crm/crm_data.xml
+++ b/addons/crm/crm_data.xml
@@ -5,18 +5,5 @@
Sales Department
Sales
-
-
-
- Check cases rules
- 4
- hours
- -1
-
-
-
-
-
-
diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py
index c1060f3e658..2260a9f0965 100644
--- a/addons/crm/crm_lead.py
+++ b/addons/crm/crm_lead.py
@@ -30,12 +30,10 @@ from crm import crm_case
class crm_lead(osv.osv, crm_case):
""" CRM Lead Case """
-
_name = "crm.lead"
_description = "Lead"
_order = "priority, id desc"
- _inherit = ['res.partner.address']
- _inherits = {'mailgate.thread': 'thread_id'}
+ _inherit = ['mailgate.thread','res.partner.address']
def _compute_day(self, cr, uid, ids, fields, args, context={}):
"""
@@ -112,7 +110,6 @@ and users by email"),
'write_date': fields.datetime('Update Date' , readonly=True),
# Lead fields
- 'thread_id': fields.many2one('mailgate.thread', 'Thread', required=False),
'categ_id': fields.many2one('crm.case.categ', 'Lead Source', \
domain="[('section_id','=',section_id),\
('object_id.model', '=', 'crm.lead')]"),
@@ -142,6 +139,8 @@ and users by email"),
\nIf the case is in progress the state is set to \'Open\'.\
\nWhen the case is over, the state is set to \'Done\'.\
\nIf the case needs to be reviewed then the state is set to \'Pending\'.'),
+ 'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('history', '=', True),('res_model','=',_name)]),
+ 'log_ids': fields.one2many('mailgate.message', 'res_id', 'Logs', domain=[('history', '=', False),('res_model','=',_name)]),
}
_defaults = {
diff --git a/addons/crm/crm_mailgate.py b/addons/crm/crm_mailgate.py
index f2380182aad..d39293e4716 100644
--- a/addons/crm/crm_mailgate.py
+++ b/addons/crm/crm_mailgate.py
@@ -38,9 +38,8 @@ from tools import command_re
class mailgate_thread(osv.osv):
""" mailgate_thread """
-
_name = "mailgate.thread"
- _inherit = "mailgate.thread"
+ _inherit = "mailgate.thread"
def message_new(self, cr, uid, msg, context):
"""
diff --git a/addons/crm/crm_meeting.py b/addons/crm/crm_meeting.py
index e45ee85b31d..f90d1dc896f 100644
--- a/addons/crm/crm_meeting.py
+++ b/addons/crm/crm_meeting.py
@@ -43,9 +43,7 @@ class crm_meeting(osv.osv, crm_case):
_name = 'crm.meeting'
_description = "Meeting"
_order = "id desc"
- _inherit = ["calendar.event"]
- _inherits = {'mailgate.thread': 'thread_id'}
-
+ _inherit = ['mailgate.thread',"calendar.event"]
_columns = {
# From crm.case
'name': fields.char('Summary', size=124, required=True),
@@ -59,7 +57,6 @@ class crm_meeting(osv.osv, crm_case):
'id': fields.integer('ID'),
# Meeting fields
- 'thread_id': fields.many2one('mailgate.thread', 'Thread', required=False),
'categ_id': fields.many2one('crm.case.categ', 'Meeting Type', \
domain="[('object_id.model', '=', 'crm.meeting')]", \
),
@@ -69,6 +66,8 @@ class crm_meeting(osv.osv, crm_case):
'event_id', 'attendee_id', 'Attendees'),
'date_closed': fields.datetime('Closed', readonly=True),
'date_deadline': fields.datetime('Deadline'),
+ 'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('history', '=', True),('res_model','=',_name)]),
+ 'log_ids': fields.one2many('mailgate.message', 'res_id', 'Logs', domain=[('history', '=', False),('res_model','=',_name)]),
'state': fields.selection([('open', 'Confirmed'),
('draft', 'Unconfirmed'),
('cancel', 'Cancelled'),
diff --git a/addons/crm/crm_phonecall.py b/addons/crm/crm_phonecall.py
index 657360a4206..a94bf5d9b59 100644
--- a/addons/crm/crm_phonecall.py
+++ b/addons/crm/crm_phonecall.py
@@ -31,13 +31,11 @@ class crm_phonecall(osv.osv, crm_case):
_name = "crm.phonecall"
_description = "Phonecall"
_order = "id desc"
- _inherits = {'mailgate.thread': 'thread_id'}
-
+ _inherit = ['mailgate.thread']
_columns = {
# From crm.case
'name': fields.char('Name', size=64),
'active': fields.boolean('Active', required=False),
- 'thread_id': fields.many2one('mailgate.thread', 'Thread', required=False),
'date_action_last': fields.datetime('Last Action', readonly=1),
'date_action_next': fields.datetime('Next Action', readonly=1),
'create_date': fields.datetime('Creation Date' , readonly=True),
@@ -84,6 +82,8 @@ class crm_phonecall(osv.osv, crm_case):
'date_closed': fields.datetime('Closed', readonly=True),
'date': fields.datetime('Date'),
'opportunity_id': fields.many2one ('crm.lead', 'Opportunity'),
+ 'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('history', '=', True),('res_model','=',_name)]),
+ 'log_ids': fields.one2many('mailgate.message', 'res_id', 'Logs', domain=[('history', '=', False),('res_model','=',_name)]),
}
_defaults = {
diff --git a/addons/crm/process/crm_configuration_process.xml b/addons/crm/process/crm_configuration_process.xml
index 146d76cc8d2..362c8982b96 100644
--- a/addons/crm/process/crm_configuration_process.xml
+++ b/addons/crm/process/crm_configuration_process.xml
@@ -1,91 +1,87 @@
-
+
-
+
-
-
-
-
+
+
+
-
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
\ No newline at end of file
+
+
diff --git a/addons/crm/report/crm_lead_report.py b/addons/crm/report/crm_lead_report.py
index db9837b5d0c..9061e6a62d4 100644
--- a/addons/crm/report/crm_lead_report.py
+++ b/addons/crm/report/crm_lead_report.py
@@ -109,7 +109,6 @@ class crm_lead_report(osv.osv):
'date_closed': fields.date('Close Date', readonly=True),
'company_id': fields.many2one('res.company', 'Company', readonly=True),
'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority'),
-
'type':fields.selection([
('lead','Lead'),
('opportunity','Opportunity'),
@@ -148,7 +147,7 @@ class crm_lead_report(osv.osv):
0 as avg_answers,
0.0 as perc_done,
0.0 as perc_cancel,
- (select count(id) from mailgate_message where thread_id=c.id) as email,
+ (select count(id) from mailgate_message where res_id=c.id and res_model='crm.lead') as email,
date_trunc('day',c.create_date) as create_date,
avg(extract('epoch' from (c.date_closed-c.create_date)))/(3600*24) as delay_close,
avg(extract('epoch' from (c.date_deadline - c.date_closed)))/(3600*24) as delay_expected,
diff --git a/addons/crm/wizard/crm_forward_to_partner.py b/addons/crm/wizard/crm_forward_to_partner.py
index 945066506d7..47bc02e0ca1 100644
--- a/addons/crm/wizard/crm_forward_to_partner.py
+++ b/addons/crm/wizard/crm_forward_to_partner.py
@@ -185,23 +185,12 @@ class crm_lead_forward_to_partner(osv.osv_memory):
email_from = this.email_from or False
case_pool._history(cr, uid, [case], _('Forward'), history=True, email=this.email_to, details=body, email_from=email_from)
- flag = False
- if case.section_id and case.section_id.server_id:
- flag = smtp_pool.send_email(
- cr=cr,
- uid=uid,
- server_id=case.section_id.server_id.id,
- emailto=emails,
- subject=this.subject,
- body="%s
" % body,
- )
- else:
- flag = tools.email_send(
- email_from,
- emails,
- this.subject,
- body,
- )
+ flag = tools.email_send(
+ email_from,
+ emails,
+ this.subject,
+ body,
+ )
if this.add_cc:
case_pool.write(cr, uid, case.id, {'email_cc' : case.email_cc and case.email_cc + ', ' + this.email_to or this.email_to})
return {}
diff --git a/addons/crm/wizard/crm_send_email.py b/addons/crm/wizard/crm_send_email.py
index 3588371984b..68930e2b85f 100644
--- a/addons/crm/wizard/crm_send_email.py
+++ b/addons/crm/wizard/crm_send_email.py
@@ -96,11 +96,10 @@ class crm_send_new_email(osv.osv_memory):
else:
hist = hist_obj.browse(cr, uid, res_id)
message_id = hist.message_id
- model = hist.model_id.model
+ model = hist.res_model
model_pool = self.pool.get(model)
- res_ids = model_pool.search(cr, uid, [('thread_id','=', hist.thread_id.id)])
- res_id = res_ids and res_ids[0] or False
- case = model_pool.browse(cr, uid, res_id)
+ case = model_pool.browse(cr, uid, hist.res_id)
+ res_id = hist.res_id
emails = [obj.email_to] + (obj.email_cc or '').split(',')
emails = filter(None, emails)
body = obj.text
@@ -120,15 +119,14 @@ class crm_send_new_email(osv.osv_memory):
if message_id:
x_headers['References'] = "%s" % (message_id)
- flag = False
-
+ print case.section_id
flag = tools.email_send(
email_from,
emails,
obj.subject,
body,
attach=attach,
- reply_to=case.section_id.reply_to,
+ reply_to=case.section_id and case.section_id.reply_to or email_from,
openobject_id=str(case.id),
x_headers=x_headers
)
@@ -196,15 +194,14 @@ class crm_send_new_email(osv.osv_memory):
include_original = context and context.get('include_original', False) or False
res = {}
for hist in hist_obj.browse(cr, uid, res_ids, context=context):
- model = hist.model_id.model
+ model = hist.res_model
# In the case where the crm.case does not exist in the database
if not model:
return {}
model_pool = self.pool.get(model)
- res_ids = model_pool.search(cr, uid, [('thread_id','=', hist.thread_id.id)])
- res_id = res_ids and res_ids[0] or False
+ res_id = hist.res_id or False
case = model_pool.browse(cr, uid, res_id)
if 'email_to' in fields:
res.update({'email_to': case.email_from or hist.email_from or False})
diff --git a/addons/crm/wizard/crm_send_email_view.xml b/addons/crm/wizard/crm_send_email_view.xml
index f56bf5e6a88..c0125014c1a 100644
--- a/addons/crm/wizard/crm_send_email_view.xml
+++ b/addons/crm/wizard/crm_send_email_view.xml
@@ -9,13 +9,15 @@
crm.send.mail
form
-
-
-
+
+
diff --git a/addons/crm_claim/crm_claim.py b/addons/crm_claim/crm_claim.py
index e8a14df42a8..b068f121b8a 100644
--- a/addons/crm_claim/crm_claim.py
+++ b/addons/crm_claim/crm_claim.py
@@ -29,10 +29,8 @@ class crm_claim(osv.osv, crm.crm_case):
_name = "crm.claim"
_description = "Claim Cases"
_order = "id desc"
- _inherits = {'mailgate.thread': 'thread_id'}
-
+ _inherit = ['mailgate.thread']
_columns = {
- 'thread_id': fields.many2one('mailgate.thread', 'Thread', required=False),
'id': fields.integer('ID', readonly=True),
'name': fields.char('Name', size=128, required=True),
'active': fields.boolean('Active', required=False),
@@ -90,6 +88,8 @@ class crm_claim(osv.osv, crm.crm_case):
\nIf the case is in progress the state is set to \'Open\'.\
\nWhen the case is over, the state is set to \'Done\'.\
\nIf the case needs to be reviewed then the state is set to \'Pending\'.'),
+ 'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('history', '=', True),('res_model','=',_name)]),
+ 'log_ids': fields.one2many('mailgate.message', 'res_id', 'Logs', domain=[('history', '=', False),('res_model','=',_name)]),
}
_defaults = {
diff --git a/addons/crm_fundraising/crm_fundraising.py b/addons/crm_fundraising/crm_fundraising.py
index 356c3baec73..0841fdac998 100644
--- a/addons/crm_fundraising/crm_fundraising.py
+++ b/addons/crm_fundraising/crm_fundraising.py
@@ -28,10 +28,8 @@ class crm_fundraising(osv.osv, crm.crm_case):
_name = "crm.fundraising"
_description = "Fund Raising Cases"
_order = "id desc"
- _inherits = {'mailgate.thread': 'thread_id'}
-
+ _inherit = ['mailgate.thread']
_columns = {
- 'thread_id': fields.many2one('mailgate.thread', 'Thread', required=False),
'id': fields.integer('ID'),
'name': fields.char('Name', size=128, required=True),
'active': fields.boolean('Active', required=False),
@@ -87,6 +85,8 @@ class crm_fundraising(osv.osv, crm.crm_case):
\nIf the case is in progress the state is set to \'Open\'.\
\nWhen the case is over, the state is set to \'Done\'.\
\nIf the case needs to be reviewed then the state is set to \'Pending\'.'),
+ 'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('history', '=', True),('res_model','=',_name)]),
+ 'log_ids': fields.one2many('mailgate.message', 'res_id', 'Logs', domain=[('history', '=', False),('res_model','=',_name)]),
}
_defaults = {
diff --git a/addons/crm_helpdesk/crm_helpdesk.py b/addons/crm_helpdesk/crm_helpdesk.py
index d07d2261013..e3f0bd476d9 100644
--- a/addons/crm_helpdesk/crm_helpdesk.py
+++ b/addons/crm_helpdesk/crm_helpdesk.py
@@ -28,10 +28,8 @@ class crm_helpdesk(osv.osv, crm.crm_case):
_name = "crm.helpdesk"
_description = "Helpdesk Cases"
_order = "id desc"
- _inherits = {'mailgate.thread': 'thread_id'}
-
+ _inherit = ['mailgate.thread']
_columns = {
- 'thread_id': fields.many2one('mailgate.thread', 'Thread', required=False),
'id': fields.integer('ID', readonly=True),
'name': fields.char('Name', size=128, required=True),
'active': fields.boolean('Active', required=False),
diff --git a/addons/hr_recruitment/hr_recruitment.py b/addons/hr_recruitment/hr_recruitment.py
index a335e233585..4764887fff5 100644
--- a/addons/hr_recruitment/hr_recruitment.py
+++ b/addons/hr_recruitment/hr_recruitment.py
@@ -57,11 +57,11 @@ class hr_applicant(osv.osv, crm.crm_case):
_name = "hr.applicant"
_description = "Applicant"
_order = "id desc"
- _inherits = {'mailgate.thread': 'thread_id'}
-
+ _inherit = ['mailgate.thread']
_columns = {
- 'thread_id': fields.many2one('mailgate.thread', 'Thread', required=False),
'name': fields.char('Name', size=128, required=True),
+ 'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('history', '=', True),('res_model','=',_name)]),
+ 'log_ids': fields.one2many('mailgate.message', 'res_id', 'Logs', domain=[('history', '=', False),('res_model','=',_name)]),
'active': fields.boolean('Active', help="If the active field is set to false, it will allow you to hide the case without removing it."),
'description': fields.text('Description'),
'section_id': fields.many2one('crm.case.section', 'Sales Team', \
diff --git a/addons/mail_gateway/mail_gateway.py b/addons/mail_gateway/mail_gateway.py
index 48b3a12aee4..fd7a5753ecf 100644
--- a/addons/mail_gateway/mail_gateway.py
+++ b/addons/mail_gateway/mail_gateway.py
@@ -30,14 +30,10 @@ class mailgate_thread(osv.osv):
'''
_name = 'mailgate.thread'
_description = 'Mailgateway Thread'
- _rec_name = 'thread'
-
_columns = {
- 'thread': fields.char('Thread', size=32, required=False),
- 'message_ids': fields.one2many('mailgate.message', 'thread_id', 'Messages', domain=[('history', '=', True)], required=False),
- 'log_ids': fields.one2many('mailgate.message', 'thread_id', 'Logs', domain=[('history', '=', False)], required=False),
+ 'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('history', '=', True)]),
+ 'log_ids': fields.one2many('mailgate.message', 'res_id', 'Logs', domain=[('history', '=', False)]),
}
-
def _history(self, cr, uid, cases, keyword, history=False, subject=None, email=False, details=None, email_from=False, message_id=False, attach=None, context=None):
"""
@param self: The object pointer
@@ -60,18 +56,16 @@ class mailgate_thread(osv.osv):
if all(isinstance(case_id, (int, long)) for case_id in cases):
cases = self.browse(cr, uid, cases, context=context)
- model_obj = self.pool.get('ir.model')
att_obj = self.pool.get('ir.attachment')
obj = self.pool.get('mailgate.message')
for case in cases:
- model_ids = model_obj.search(cr, uid, [('model', '=', case._name)])
data = {
'name': keyword,
'user_id': uid,
- 'model_id' : model_ids and model_ids[0] or False,
+ 'res_model' : case._name,
+ 'res_id': case.id,
'date': time.strftime('%Y-%m-%d %H:%M:%S'),
- 'thread_id': case.thread_id.id,
'message_id': message_id,
}
attachments = []
@@ -83,7 +77,7 @@ class mailgate_thread(osv.osv):
'name': subject or 'History',
'history': True,
'user_id': uid,
- 'model_id' : model_ids and model_ids[0] or False,
+ 'res_model' : case._name,
'res_id': case.id,
'date': time.strftime('%Y-%m-%d %H:%M:%S'),
'description': details or (hasattr(case, 'description') and case.description or False),
@@ -94,16 +88,11 @@ class mailgate_thread(osv.osv):
(hasattr(case, 'user_id') and case.user_id and case.user_id.address_id and \
case.user_id.address_id.email) or tools.config.get('email_from', False),
'partner_id': hasattr(case, 'partner_id') and (case.partner_id and case.partner_id.id or False) or False,
- 'thread_id': case.thread_id.id,
'message_id': message_id,
'attachment_ids': [(6, 0, attachments)]
}
res = obj.create(cr, uid, data, context)
return True
-
- __history = history = _history
-
-
mailgate_thread()
class mailgate_message(osv.osv):
@@ -112,15 +101,13 @@ class mailgate_message(osv.osv):
'''
_name = 'mailgate.message'
_description = 'Mailgateway Message'
- _order = 'date desc'
-
+ _order = 'id desc'
_columns = {
'name':fields.char('Message', size=64),
- 'model_id': fields.many2one('ir.model', 'Model'),
+ 'res_model': fields.char('Object Name', size=128),
'res_id': fields.integer('Resource ID'),
- 'thread_id':fields.many2one('mailgate.thread', 'Thread'),
'date': fields.datetime('Date'),
- 'history': fields.boolean('Is History?', required=False),
+ 'history': fields.boolean('Is History?'),
'user_id': fields.many2one('res.users', 'User Responsible', readonly=True),
'message': fields.text('Description'),
'email_from': fields.char('Email From', size=84),
@@ -135,5 +122,3 @@ class mailgate_message(osv.osv):
mailgate_message()
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/mail_gateway/scripts/openerp_mailgate/openerp_mailgate.py b/addons/mail_gateway/scripts/openerp_mailgate/openerp_mailgate.py
index c4cad98b046..b9a9eefee15 100755
--- a/addons/mail_gateway/scripts/openerp_mailgate/openerp_mailgate.py
+++ b/addons/mail_gateway/scripts/openerp_mailgate/openerp_mailgate.py
@@ -127,13 +127,11 @@ class rpc_proxy(object):
return self.rpc.execute(self.dbname, self.user_id, self.passwd, *request, **kwargs)
class email_parser(object):
- def __init__(self, uid, password, model, email, email_default, dbname, host, port):
+ def __init__(self, uid, password, model, email, email_default, dbname, host, port):
self.rpc = rpc_proxy(uid, password, host=host, port=port, dbname=dbname)
try:
- self.model_id = int(model)
self.model = str(model)
except:
- self.model_id = self.rpc('ir.model', 'search', [('model', '=', model)])[0]
self.model = str(model)
self.email = email
self.email_default = email_default
@@ -188,7 +186,7 @@ class email_parser(object):
values = {
'message_ids' : [
(0, 0, {
- 'model_id' : self.rpc('ir.model', 'search', [('name', '=', self.model)])[0],
+ 'res_model' : self.model,
'date' : time.strftime('%Y-%m-%d %H:%M:%S'),
'description' : message['body'],
'email_from' : msg_from,
@@ -200,8 +198,6 @@ class email_parser(object):
)
]
}
- thread_id = self.rpc('mailgate.thread', 'create', values)
- data['thread_id'] = thread_id
oid = self.rpc(self.model, 'create', data)
attachments = message['attachment']
@@ -216,7 +212,7 @@ class email_parser(object):
}
self.rpc('ir.attachment', 'create', data_attach)
- return (oid, thread_id,)
+ return (oid, )
def msg_body_get(self, msg):
message = {
@@ -320,8 +316,7 @@ class email_parser(object):
> create_message(id, msg['From'], msg['To'], 'Send', message['body'])
"""
values = {
- 'thread_id' : self.rpc(self.model, 'read', [oid], ['thread_id'])[0]['thread_id'][0],
- 'model_id' : self.rpc('ir.model', 'search', [('name', '=', self.model)])[0],
+ 'res_model' : self.model,
'res_id' : oid,
'date' : time.strftime('%Y-%m-%d %H:%M:%S'),
'description' : body,
@@ -390,13 +385,7 @@ class email_parser(object):
logging.info("email: %s -> %s -- %s", msg['From'], self.email, msg['Subject'])
(case_id, emails) = self.msg_test(msg, case_str)
- thread_id = None
if case_id:
- values = self.rpc(self.model, 'read', [case_id], ['thread_id'])
- if values:
- thread_id = values[0]['thread_id'][0]
- emails = emails[str(thread_id)]
-
user_email = filter(None, emails['user_email'])[0]
if user_email and self.email_get(user_email) == self.email_get(self._decode_header(msg['From'])):
@@ -404,13 +393,12 @@ class email_parser(object):
else:
self.msg_partner(msg, case_id)
else:
- case_id, thread_id = self.msg_new(msg)
+ case_id = self.msg_new(msg)
subject = self._decode_header(msg['Subject'])
msg['Subject'] = "[%s] %s" % (case_id, subject,)
msg['Message-Id'] = "<%s-openerpcrm-%s@%s>" % (time.time(), case_id, socket.gethostname(),)
logging.info(" case: %r", case_id)
- logging.info(" thread: %r", thread_id)
values = self.rpc(self.model, 'emails_get', [case_id])
@@ -431,7 +419,7 @@ class email_parser(object):
a = self._decode_header(msg['Subject'])
msg['Subject'] = '[OpenERP-CaseError] ' + a
self.msg_send(msg, self.email_default.split(','))
- return case_id, thread_id, emails
+ return case_id, emails
if __name__ == '__main__':
parser = optparse.OptionParser(usage='usage: %prog [options]', version='%prog v1.0')
diff --git a/addons/project_issue/project_issue.py b/addons/project_issue/project_issue.py
index c763306e602..675818214a5 100644
--- a/addons/project_issue/project_issue.py
+++ b/addons/project_issue/project_issue.py
@@ -36,7 +36,7 @@ class project_issue(osv.osv, crm.crm_case):
_name = "project.issue"
_description = "Project Issue"
_order = "priority, id desc"
- _inherits = {'mailgate.thread': 'thread_id'}
+ _inherit = ['mailgate.thread']
def case_open(self, cr, uid, ids, *args):
"""
@@ -121,7 +121,6 @@ class project_issue(osv.osv, crm.crm_case):
return res
_columns = {
- 'thread_id': fields.many2one('mailgate.thread', 'Thread', required=False),
'id': fields.integer('ID'),
'name': fields.char('Name', size=128, required=True),
'active': fields.boolean('Active', required=False),
@@ -179,6 +178,8 @@ class project_issue(osv.osv, crm.crm_case):
method=True, multi='working_days_open', type="float", store=True),
'working_hours_close': fields.function(_compute_day, string='Working Hours to Close the Issue', \
method=True, multi='working_days_close', type="float", store=True),
+ 'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('history', '=', True),('res_model','=',_name)]),
+ 'log_ids': fields.one2many('mailgate.message', 'res_id', 'Logs', domain=[('history', '=', False),('res_model','=',_name)]),
}
def _get_project(self, cr, uid, context):
diff --git a/addons/sale/sale.py b/addons/sale/sale.py
index 9fbdac14a23..a371757f360 100644
--- a/addons/sale/sale.py
+++ b/addons/sale/sale.py
@@ -205,7 +205,8 @@ class sale_order(osv.osv):
return result.keys()
_columns = {
- 'name': fields.char('Order Reference', size=64, required=True, select=True, help="unique number of the sale order,computed automatically when the sale order is created"),
+ 'name': fields.char('Order Reference', size=64, required=True,
+ readonly=True, states={'draft': [('readonly', False)]}, select=True),
'shop_id': fields.many2one('sale.shop', 'Shop', required=True, readonly=True, states={'draft': [('readonly', False)]}),
'origin': fields.char('Source document', size=64, help="Reference of the document that generated this sale order request."),
'client_order_ref': fields.char('Customer Reference', size=64),