From 6365760a5d75e9180aab98663bee8d4dfa737f6c Mon Sep 17 00:00:00 2001 From: Serpent Consulting Services Date: Wed, 13 Feb 2013 18:27:36 +0530 Subject: [PATCH] [ADD] Added mass_editing module compatible to version 7.0 --- mass_editing/ChangeLog.txt | 11 ++ mass_editing/__init__.py | 26 +++++ mass_editing/__openerp__.py | 43 ++++++++ mass_editing/mass_editing.py | 117 +++++++++++++++++++++ mass_editing/mass_editing_view.xml | 73 +++++++++++++ mass_editing/security/ir.model.access.csv | 2 + mass_editing/wizard/__init__.py | 24 +++++ mass_editing/wizard/mass_editing_wizard.py | 117 +++++++++++++++++++++ 8 files changed, 413 insertions(+) create mode 100755 mass_editing/ChangeLog.txt create mode 100644 mass_editing/__init__.py create mode 100644 mass_editing/__openerp__.py create mode 100644 mass_editing/mass_editing.py create mode 100644 mass_editing/mass_editing_view.xml create mode 100755 mass_editing/security/ir.model.access.csv create mode 100644 mass_editing/wizard/__init__.py create mode 100644 mass_editing/wizard/mass_editing_wizard.py diff --git a/mass_editing/ChangeLog.txt b/mass_editing/ChangeLog.txt new file mode 100755 index 0000000..143abf1 --- /dev/null +++ b/mass_editing/ChangeLog.txt @@ -0,0 +1,11 @@ +=============================================================================== + Version Change Log (mass_editing) +=============================================================================== +1.3 * March 11,2013 : Serpent Consulting Services + * Improved and optimized the code of mass_editing + +1.2 * Feb 14,2013 : Serpent Consulting Services + * Corrected code as per the review by Community + +1.1 * Feb 12,2013 : Serpent Consulting Services + * Added the module diff --git a/mass_editing/__init__.py b/mass_editing/__init__.py new file mode 100644 index 0000000..f203ff2 --- /dev/null +++ b/mass_editing/__init__.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module uses OpenERP, Open Source Management Solution Framework. +# Copyright (C) 2012-Today Serpent Consulting Services () +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see +# +############################################################################## + +import mass_editing +import wizard + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + diff --git a/mass_editing/__openerp__.py b/mass_editing/__openerp__.py new file mode 100644 index 0000000..011e0be --- /dev/null +++ b/mass_editing/__openerp__.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module uses OpenERP, Open Source Management Solution Framework. +# Copyright (C) 2012-Today Serpent Consulting Services () +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see +# +############################################################################## +{ + "name" : "Mass Editing", + "version" : "1.3", + "author" : "Serpent Consulting Services", + "category" : "Tools", + "website" : "http://www.serpentcs.com", + "description": """This module provides the functionality to add, update or remove the values of more than one records on the fly at the same time. + You can configure mass editing for any OpenERP model. + The video explaining the features and how-to for OpenERP Version 6 is here http://t.co/wukYMx1A + The video explaining the features and how-to for OpenERP Version 7 is here : http://www.youtube.com/watch?v=9BH0o74A748&feature=youtu.be + For more details/customization/feedback contact us on contact@serpentcs.com. + """, + 'depends': ['base'], + 'data': [ + "security/ir.model.access.csv", + 'mass_editing_view.xml', + ], + 'installable': True, + 'application': True, + 'auto_install': False, +} + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/mass_editing/mass_editing.py b/mass_editing/mass_editing.py new file mode 100644 index 0000000..d99e550 --- /dev/null +++ b/mass_editing/mass_editing.py @@ -0,0 +1,117 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module uses OpenERP, Open Source Management Solution Framework. +# Copyright (C) 2012-Today Serpent Consulting Services () +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see +# +############################################################################## + +from osv import fields, osv +from tools.translate import _ +from lxml import etree +from openerp import tools + +class ir_model_fields(osv.osv): + _inherit = 'ir.model.fields' + + def search(self, cr, uid, args, offset=0, limit=0, order=None, context=None, count=False): + model_domain = [] + for domain in args: + if domain[0] == 'model_id' and domain[2] and type(domain[2]) != list: + model_domain += [('model_id', 'in', map(int, domain[2][1:-1].split(',')))] + else: + model_domain += domain + return super(ir_model_fields, self).search(cr, uid, model_domain, offset=offset, limit=limit, order=order, context=context, count=count) + + +ir_model_fields() + +class mass_object(osv.osv): + _name = "mass.object" + + _columns = { + 'name' : fields.char("Name", size=64, required=True, select=1), + 'model_id' : fields.many2one('ir.model', 'Model', required=True, select=1), + 'field_ids' : fields.many2many('ir.model.fields', 'mass_field_rel', 'mass_id', 'field_id', 'Fields'), + 'ref_ir_act_window':fields.many2one('ir.actions.act_window', 'Sidebar action', readonly=True, + help="Sidebar action to make this template available on records " + "of the related document model"), + 'ref_ir_value':fields.many2one('ir.values', 'Sidebar button', readonly=True, + help="Sidebar button to open the sidebar action"), + 'model_list': fields.char('Model List', size=256) + } + + def onchange_model(self, cr, uid, ids, model_id, context=None): + if context is None: context = {} + if not model_id: + return {'value': {'model_list': ''}} + model_list = [model_id] + model_obj = self.pool.get('ir.model') + active_model_obj = self.pool.get(model_obj.browse(cr, uid, model_id).model) + if active_model_obj._inherits: + for key, val in active_model_obj._inherits.items(): + model_ids = model_obj.search(cr, uid, [('model', '=', key)]) + if model_ids: + model_list += model_ids + return {'value': {'model_list': str(model_list)}} + + def create_action(self, cr, uid, ids, context=None): + vals = {} + action_obj = self.pool.get('ir.actions.act_window') + data_obj = self.pool.get('ir.model.data') + ir_values_obj = self.pool.get('ir.values') + for data in self.browse(cr, uid, ids, context=context): + src_obj = data.model_id.model + button_name = _('Mass Editing (%s)') % data.name + vals['ref_ir_act_window'] = action_obj.create(cr, uid, { + 'name': button_name, + 'type': 'ir.actions.act_window', + 'res_model': 'mass.editing.wizard', + 'src_model': src_obj, + 'view_type': 'form', + 'context': "{'mass_editing_object' : %d}" % (data.id), + 'view_mode':'form,tree', + 'target': 'new', + 'auto_refresh':1 + }, context) + vals['ref_ir_value'] = ir_values_obj.create(cr, uid, { + 'name': button_name, + 'model': src_obj, + 'key2': 'client_action_multi', + 'value': "ir.actions.act_window," + str(vals['ref_ir_act_window']), + 'object': True, + }, context) + self.write(cr, uid, ids, { + 'ref_ir_act_window': vals.get('ref_ir_act_window', False), + 'ref_ir_value': vals.get('ref_ir_value', False), + }, context) + return True + + def unlink_action(self, cr, uid, ids, context=None): + for template in self.browse(cr, uid, ids, context=context): + try: + if template.ref_ir_act_window: + self.pool.get('ir.actions.act_window').unlink(cr, uid, template.ref_ir_act_window.id, context) + if template.ref_ir_value: + ir_values_obj = self.pool.get('ir.values') + ir_values_obj.unlink(cr, uid, template.ref_ir_value.id, context) + except: + raise osv.except_osv(_("Warning"), _("Deletion of the action record failed.")) + return True + +mass_object() + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/mass_editing/mass_editing_view.xml b/mass_editing/mass_editing_view.xml new file mode 100644 index 0000000..c304b81 --- /dev/null +++ b/mass_editing/mass_editing_view.xml @@ -0,0 +1,73 @@ + + + + + + mass.object.form + mass.object + form + +
+ + + + + + + + + +