From acf23616b71c94d20f7d0001b77a78b92f1f1bbd Mon Sep 17 00:00:00 2001 From: "ksa (Open ERP)" Date: Fri, 11 Jun 2010 19:42:11 +0530 Subject: [PATCH 1/5] [IMP] Improvement for delete the recrod bzr revid: ksa@tinyerp.co.in-20100611141211-1wi39kn5up15309v --- addons/audittrail/audittrail.py | 110 +++++++++++++++++++------------- 1 file changed, 66 insertions(+), 44 deletions(-) diff --git a/addons/audittrail/audittrail.py b/addons/audittrail/audittrail.py index 1a72a26ea5f..0233f2fb624 100644 --- a/addons/audittrail/audittrail.py +++ b/addons/audittrail/audittrail.py @@ -131,8 +131,22 @@ 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.name +# res_id = resname.res_id +# if model_object and res_id: +# # model_pool = self.pool.get(model_object) +# res = model_object.name_get(cr,uid,[res_id]) +# data[resname.id] = res and res[0][1] +# else: +# data[resname.id] = False +# return data + _columns = { "name": fields.char("Name", size=32), + # '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), @@ -187,14 +201,20 @@ class audittrail_objects_proxy(osv_pool): context = {} pool = pooler.get_pool(cr.dbname) field_pool = pool.get('ir.model.fields') - field_ids = field_pool.search(cr, uid, [('name', '=', field_name), ('model_id', '=', model.id)]) + 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)) - + field = field_pool.read(cr, uid, field_id) relation_model = field['relation'] relation_model_pool = relation_model and pool.get(relation_model) or False - + if field['ttype'] == 'many2one': res = False relation_id = False @@ -206,11 +226,11 @@ class audittrail_objects_proxy(osv_pool): return res 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 = [] + 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 - + return values def create_log_line(self, cr, uid, log_id, model, lines=[]): @@ -236,7 +256,7 @@ class audittrail_objects_proxy(osv_pool): 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 '' @@ -259,7 +279,7 @@ class audittrail_objects_proxy(osv_pool): "new_value_text": new_value_text, "field_description": field['field_description'] } - line_id = log_line_pool.create(cr, uid, vals) + line_id = log_line_pool.create(cr, uid, vals) #End Loop return True @@ -281,43 +301,43 @@ class audittrail_objects_proxy(osv_pool): 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 + + 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, model.model, method, *args) - cr.commit() + cr.commit() resource = resource_pool.read(cr, uid, res_id, args[0].keys()) vals = { "method": method, "object_id": model.id, - "user_id": uid, + "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: + 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) + self.create_log_line(cr, uid, log_id, model, lines) cr.commit() cr.close() - return res_id + return res_id elif method in ('read'): res_ids = args[0] old_values = {} - res = fct_src(db, uid, model, method, *args) + res = fct_src(db, uid, model.model, method, *args) if type(res) == list: for v in res: old_values[v['id']] = v @@ -327,22 +347,22 @@ class audittrail_objects_proxy(osv_pool): vals = { "method": method, "object_id": model.id, - "user_id": uid, + "user_id": uid, "res_id": res_id, - + } log_id = log_pool.create(cr, uid, vals) lines = [] - for field in old_values[res_id]: + 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 @@ -356,27 +376,29 @@ class audittrail_objects_proxy(osv_pool): vals = { "method": method, "object_id": model.id, - "user_id": uid, + "user_id": uid, "res_id": res_id, - + } - log_id = log_pool.create(cr, uid, vals) + log_id = log_pool.create(cr, uid, vals) lines = [] - for field in old_values[res_id]: + 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, method, *args) + res = fct_src(db, uid, model.model, method, *args) cr.commit() cr.close() return res else: - res_ids = args[0] + res_ids = args[0] old_values = {} fields = [] if len(args)>1 and type(args[1]) == dict: @@ -384,10 +406,10 @@ class audittrail_objects_proxy(osv_pool): if type(res_ids) in (long, int): res_ids = [res_ids] if res_ids: - for resource in resource_pool.read(cr, uid, res_ids, fields): - resource_id = resource['id'] + for resource in resource_pool.read(cr, uid, res_ids, fields): + resource_id = resource['id'] if 'id' in resource: - del resource['id'] + del resource['id'] old_values_text = {} old_value = {} for field in resource.keys(): @@ -406,14 +428,14 @@ class audittrail_objects_proxy(osv_pool): vals = { "method": method, "object_id": model.id, - "user_id": uid, - "res_id": resource_id, + "user_id": uid, + "res_id": resource_id, } - - + + log_id = log_pool.create(cr, uid, vals) lines = [] - for field in resource.keys(): + for field in resource.keys(): line = { 'name': field, 'new_value': resource[field], @@ -422,14 +444,14 @@ class audittrail_objects_proxy(osv_pool): '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): """ @@ -449,11 +471,11 @@ class audittrail_objects_proxy(osv_pool): logged_uids = [] fct_src = super(audittrail_objects_proxy, self).execute - def my_fct(db, uid, model, method, *args): + def my_fct(db, uid, model, method, *args): rule = False - model_ids = model_pool.search(cr, uid, [('model', '=', model)]) - model_id = model_ids and model_ids[0] or False - + 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 @@ -481,7 +503,7 @@ class audittrail_objects_proxy(osv_pool): return fct_src(db, uid, model, method, *args) res = my_fct(db, uid, model, method, *args) cr.close() - return res + return res def exec_workflow(self, db, uid, model, method, *args, **argv): From cc6e6d5853210284b1a93ef6d9cc72eb40872c9f Mon Sep 17 00:00:00 2001 From: "ksa (Open ERP)" Date: Mon, 14 Jun 2010 12:30:43 +0530 Subject: [PATCH 2/5] [IMP] Apply function for resource name bzr revid: ksa@tinyerp.co.in-20100614070043-t7zfy1y6gvryyc54 --- addons/audittrail/audittrail.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/addons/audittrail/audittrail.py b/addons/audittrail/audittrail.py index 0233f2fb624..d5b0761b65a 100644 --- a/addons/audittrail/audittrail.py +++ b/addons/audittrail/audittrail.py @@ -131,22 +131,21 @@ 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.name -# res_id = resname.res_id -# if model_object and res_id: -# # model_pool = self.pool.get(model_object) -# res = model_object.name_get(cr,uid,[res_id]) -# data[resname.id] = res and res[0][1] -# else: -# data[resname.id] = False -# return data + 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), - # 'name': fields.function(_name_get_resname, type='char', string='Resource Name', method=True), + "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), From da49bdd33df26f292674bc5360e89853c6494b57 Mon Sep 17 00:00:00 2001 From: "ksa (Open ERP)" Date: Mon, 14 Jun 2010 18:18:37 +0530 Subject: [PATCH 3/5] [IMP] solve problem related with osv memory object bzr revid: ksa@tinyerp.co.in-20100614124837-zjod15jf112bkrso --- addons/audittrail/audittrail.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/addons/audittrail/audittrail.py b/addons/audittrail/audittrail.py index d5b0761b65a..11ec8cb7a1e 100644 --- a/addons/audittrail/audittrail.py +++ b/addons/audittrail/audittrail.py @@ -131,21 +131,22 @@ 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 +# 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.function(_name_get_resname, type='char', string='Resource Name', method=True), + "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), @@ -405,7 +406,7 @@ class audittrail_objects_proxy(osv_pool): if type(res_ids) in (long, int): res_ids = [res_ids] if res_ids: - for resource in resource_pool.read(cr, uid, res_ids, fields): + for resource in resource_pool.read(cr, uid, res_ids): resource_id = resource['id'] if 'id' in resource: del resource['id'] @@ -414,13 +415,13 @@ class audittrail_objects_proxy(osv_pool): 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} + old_values[resource_id] = {'text':old_values_text, 'value': old_value} res = fct_src(db, uid, model.model, method, *args) cr.commit() if res_ids: - for resource in resource_pool.read(cr, uid, res_ids, fields): + for resource in resource_pool.read(cr, uid, res_ids): resource_id = resource['id'] if 'id' in resource: del resource['id'] From 23a57fc7f45d0e2377a758d298e83a3818b66fcb Mon Sep 17 00:00:00 2001 From: "Harry (OpenERP)" Date: Tue, 15 Jun 2010 10:54:29 +0530 Subject: [PATCH 4/5] [REVERT] account: log message put wrong place bzr revid: hmo@tinyerp.com-20100615052429-ki2knnkrhpqks3bg --- addons/account/invoice.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/addons/account/invoice.py b/addons/account/invoice.py index b15b4e94ad6..cf0a6760481 100644 --- a/addons/account/invoice.py +++ b/addons/account/invoice.py @@ -863,6 +863,7 @@ class account_invoice(osv.osv): # make the invoice point to that move self.write(cr, uid, [inv.id], {'move_id': move_id,'period_id':period_id, 'move_name':new_move_name}) self.pool.get('account.move').post(cr, uid, [move_id]) + self._log_event(cr, uid, ids) return True def line_get_convert(self, cr, uid, x, part, date, context=None): @@ -916,7 +917,6 @@ class account_invoice(osv.osv): 'WHERE account_move_line.move_id = %s ' \ 'AND account_analytic_line.move_id = account_move_line.id', (ref, move_id)) - self._log_event(cr, uid, ids) return True def action_cancel(self, cr, uid, ids, *args): @@ -952,17 +952,7 @@ class account_invoice(osv.osv): return taxes.values() def _log_event(self, cr, uid, ids, factor=1.0, name='Open Invoice'): - for (invoice_id,number) in self.name_get(cr, uid, ids): - invoice = self.browse(cr,uid,invoice_id) - message = ("%s %s %s %s %s %s %s") % ( - _('Invoice'), - _("INV/"), - number.split('/')[-1], - _("Opened,"), - _('journal entries'), - invoice.move_id.name, - _("Created")) - self.log(cr, uid, invoice_id, message) + #TODO: implement messages system return True def name_get(self, cr, uid, ids, context=None): From f5487a188e4dc3e584d7c09124e582eea416adca Mon Sep 17 00:00:00 2001 From: "Harry (OpenERP)" Date: Tue, 15 Jun 2010 15:43:48 +0530 Subject: [PATCH 5/5] [FIX] document_webdav: missing import osv bzr revid: hmo@tinyerp.com-20100615101348-8778waohibz0cb30 --- addons/document_webdav/webdav.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/document_webdav/webdav.py b/addons/document_webdav/webdav.py index b9b1a1f8a65..eec6c69ae16 100644 --- a/addons/document_webdav/webdav.py +++ b/addons/document_webdav/webdav.py @@ -23,13 +23,15 @@ import xml.dom.minidom domimpl = xml.dom.minidom.getDOMImplementation() import urlparse import urllib +from osv import osv +import tools try: from DAV import utils from DAV.propfind import PROPFIND except ImportError: raise osv.except_osv('PyWebDAV Import Error!','Please install pywebdav \ - from http://pywebdav.googlecode.com/files/PyWebDAV-0.9.3.tar.gz/') -import tools +from http://pywebdav.googlecode.com') + super_mk_prop_response = PROPFIND.mk_prop_response