From ae59feaff3f3b57a1611094e65f25d543c5d476f Mon Sep 17 00:00:00 2001 From: Anu Patel Date: Thu, 2 May 2013 18:39:12 +0530 Subject: [PATCH] [IMP] mass_editing: Corrections based on the merge comments --- mass_editing/mass_editing.py | 46 ++++++++++++++-------- mass_editing/security/ir.model.access.csv | 2 +- mass_editing/wizard/mass_editing_wizard.py | 16 ++++---- 3 files changed, 37 insertions(+), 27 deletions(-) diff --git a/mass_editing/mass_editing.py b/mass_editing/mass_editing.py index d99e550..8db6c4c 100644 --- a/mass_editing/mass_editing.py +++ b/mass_editing/mass_editing.py @@ -19,12 +19,12 @@ # ############################################################################## -from osv import fields, osv -from tools.translate import _ +from openerp.osv import orm, fields +import openerp.tools +from openerp.tools.translate import _ from lxml import etree -from openerp import tools -class ir_model_fields(osv.osv): +class ir_model_fields(orm.Model): _inherit = 'ir.model.fields' def search(self, cr, uid, args, offset=0, limit=0, order=None, context=None, count=False): @@ -33,27 +33,30 @@ class ir_model_fields(osv.osv): 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 + model_domain.append(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): +class mass_object(orm.Model): _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, + '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) } - + + _sql_constraints = [ + ('name_uniq', 'unique (name)', _('Name must be unique!')), + ] + def onchange_model(self, cr, uid, ids, model_id, context=None): if context is None: context = {} if not model_id: @@ -63,9 +66,8 @@ class mass_object(osv.osv): 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 + model_ids = model_obj.search(cr, uid, [('model', '=', key)], context=context) + model_list += model_ids return {'value': {'model_list': str(model_list)}} def create_action(self, cr, uid, ids, context=None): @@ -112,6 +114,16 @@ class mass_object(osv.osv): raise osv.except_osv(_("Warning"), _("Deletion of the action record failed.")) return True -mass_object() + def unlink(self, cr, uid, ids, context=None): + self.unlink_action(cr, uid, ids, context) + return super(mass_object, self).unlink(cr, uid, ids, context) + + def copy(self, cr, uid, record_id, default=None, context=None): + if default is None: + default = {} + default.update({'name':'','field_ids': []}) + return super(mass_object, self).copy(cr, uid, record_id, default, context) + +mass_object() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/mass_editing/security/ir.model.access.csv b/mass_editing/security/ir.model.access.csv index d899b59..80ee747 100755 --- a/mass_editing/security/ir.model.access.csv +++ b/mass_editing/security/ir.model.access.csv @@ -1,2 +1,2 @@ "id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" -"access_mass_editing_normal_user","mass.editing.normal.user","model_mass_object","base.group_user",1,1,1,0 +"access_mass_editing_normal_user","mass.editing.normal.user","model_mass_object","base.group_user",1,0,0,0 diff --git a/mass_editing/wizard/mass_editing_wizard.py b/mass_editing/wizard/mass_editing_wizard.py index c43bd72..a773cf3 100644 --- a/mass_editing/wizard/mass_editing_wizard.py +++ b/mass_editing/wizard/mass_editing_wizard.py @@ -19,12 +19,11 @@ # ############################################################################## -from osv import osv -from osv import fields +from openerp.osv import orm, fields +import openerp.tools as tools from lxml import etree -import tools -class mass_editing_wizard(osv.osv_memory): +class mass_editing_wizard(orm.TransientModel): _name = 'mass.editing.wizard' _columns = { @@ -51,11 +50,10 @@ class mass_editing_wizard(osv.osv_memory): etree.SubElement(xml_group, 'field', {'name': "selection__" + field.name, 'colspan': '2', 'nolabel':'1'}) etree.SubElement(xml_group, 'field', {'name': field.name, 'colspan':'4', 'nolabel':'1', 'attrs':"{'invisible':[('selection__" + field.name + "','=','remove_m2m')]}"}) elif field.ttype == "many2one": - if field_info: - all_fields["selection__" + field.name] = {'type':'selection', 'string': field_info[field.name]['string'], 'selection':[('set', 'Set'), ('remove', 'Remove')]} - all_fields[field.name] = {'type':field.ttype, 'string': field.field_description, 'relation': field.relation} - etree.SubElement(xml_group, 'field', {'name': "selection__" + field.name, 'colspan':'2'}) - etree.SubElement(xml_group, 'field', {'name': field.name, 'nolabel':'1', 'colspan':'2', 'attrs':"{'invisible':[('selection__" + field.name + "','=','remove')]}"}) + all_fields["selection__" + field.name] = {'type':'selection', 'string': field_info[field.name]['string'], 'selection':[('set', 'Set'), ('remove', 'Remove')]} + all_fields[field.name] = {'type':field.ttype, 'string': field.field_description, 'relation': field.relation} + etree.SubElement(xml_group, 'field', {'name': "selection__" + field.name, 'colspan':'2'}) + etree.SubElement(xml_group, 'field', {'name': field.name, 'nolabel':'1', 'colspan':'2', 'attrs':"{'invisible':[('selection__" + field.name + "','=','remove')]}"}) elif field.ttype == "char": all_fields["selection__" + field.name] = {'type':'selection', 'string': field_info[field.name]['string'], 'selection':[('set', 'Set'), ('remove', 'Remove')]} all_fields[field.name] = {'type':field.ttype, 'string': field.field_description, 'size': field.size or 256}