Browse Source

[FIX] More fixes landed

pull/2/head
Serpent Consulting Services 12 years ago
parent
commit
7dae0d6f69
  1. 3
      mass_editing/ChangeLog.txt
  2. 2
      mass_editing/__openerp__.py
  3. 82
      mass_editing/mass_editing.py
  4. 53
      mass_editing/wizard/mass_editing_wizard.py

3
mass_editing/ChangeLog.txt

@ -1,6 +1,9 @@
=============================================================================== ===============================================================================
Version Change Log (mass_editing) 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 1.2 * Feb 14,2013 : Serpent Consulting Services
* Corrected code as per the review by Community * Corrected code as per the review by Community

2
mass_editing/__openerp__.py

@ -20,7 +20,7 @@
############################################################################## ##############################################################################
{ {
"name" : "Mass Editing", "name" : "Mass Editing",
"version" : "1.2",
"version" : "1.3",
"author" : "Serpent Consulting Services", "author" : "Serpent Consulting Services",
"category" : "Tools", "category" : "Tools",
"website" : "http://www.serpentcs.com", "website" : "http://www.serpentcs.com",

82
mass_editing/mass_editing.py

@ -28,11 +28,14 @@ class ir_model_fields(osv.osv):
_inherit = 'ir.model.fields' _inherit = 'ir.model.fields'
def search(self, cr, uid, args, offset=0, limit=0, order=None, context=None, count=False): def search(self, cr, uid, args, offset=0, limit=0, order=None, context=None, count=False):
res = super(ir_model_fields, self).search(cr, uid, args, offset=offset, limit=limit, order=order, context=context, count=count)
model_domain = []
for domain in args: for domain in args:
if domain[0]== 'model_id' and type(domain[2]) != list:
res = self.search(cr, uid, [('model_id', 'in', map(int, domain[2][1:-1].split(',')))])
return res
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() ir_model_fields()
@ -40,61 +43,60 @@ class mass_object(osv.osv):
_name = "mass.object" _name = "mass.object"
_columns = { _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,
'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 " 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"),
"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) 'model_list': fields.char('Model List', size=256)
} }
def onchange_model(self, cr, uid, ids, model_id, context=None): def onchange_model(self, cr, uid, ids, model_id, context=None):
if context is None: context = {} if context is None: context = {}
model_list = ""
if model_id:
model_obj = self.pool.get('ir.model')
model_data = model_obj.browse(cr, uid, model_id)
model_list = "[" + str(model_id) + ""
active_model_obj = self.pool.get(model_data.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 += "," + str(model_ids[0]) + ""
model_list += "]"
return {'value': {'model_list': model_list}}
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): def create_action(self, cr, uid, ids, context=None):
vals = {} vals = {}
action_obj = self.pool.get('ir.actions.act_window') action_obj = self.pool.get('ir.actions.act_window')
data_obj = self.pool.get('ir.model.data') 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): for data in self.browse(cr, uid, ids, context=context):
src_obj = data.model_id.model src_obj = data.model_id.model
button_name = _('Mass Editing (%s)') % data.name button_name = _('Mass Editing (%s)') % data.name
vals['ref_ir_act_window'] = action_obj.create(cr, uid, { 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',
'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 'auto_refresh':1
}, context) }, context)
vals['ref_ir_value'] = self.pool.get('ir.values').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,
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) }, context)
self.write(cr, uid, ids, { 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),
'ref_ir_act_window': vals.get('ref_ir_act_window', False),
'ref_ir_value': vals.get('ref_ir_value', False),
}, context) }, context)
return True return True

53
mass_editing/wizard/mass_editing_wizard.py

@ -41,53 +41,47 @@ class mass_editing_wizard(osv.osv_memory):
etree.SubElement(xml_group, 'label', {'string': '', 'colspan': '2'}) etree.SubElement(xml_group, 'label', {'string': '', 'colspan': '2'})
xml_group = etree.SubElement(xml_form, 'group', {'colspan': '4'}) xml_group = etree.SubElement(xml_form, 'group', {'colspan': '4'})
model_obj = self.pool.get(context.get('active_model')) model_obj = self.pool.get(context.get('active_model'))
field_info = model_obj.fields_get(cr, uid, [], context)
for field in editing_data.field_ids: for field in editing_data.field_ids:
if field.ttype == "many2many": if field.ttype == "many2many":
field_info = model_obj.fields_get(cr, uid, [field.name], context)
all_fields[field.name] = field_info[field.name]
all_fields["selection_"+field.name] = {'type':'selection', 'string': field_info[field.name]['string'], 'selection':[('set', 'Set'), ('remove_m2m', 'Remove'), ('add', 'Add')]}
all_fields[field.name] = field_info[field.name]
all_fields["selection__" + field.name] = {'type':'selection', 'string': field_info[field.name]['string'], 'selection':[('set', 'Set'), ('remove_m2m', 'Remove'), ('add', 'Add')]}
xml_group = etree.SubElement(xml_group, 'group', {'colspan': '4'}) xml_group = etree.SubElement(xml_group, 'group', {'colspan': '4'})
etree.SubElement(xml_group, 'separator', {'string': field_info[field.name]['string'], 'colspan': '2'}) etree.SubElement(xml_group, 'separator', {'string': field_info[field.name]['string'], 'colspan': '2'})
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')]}"})
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": elif field.ttype == "many2one":
field_info = model_obj.fields_get(cr, uid, [field.name], context)
if field_info: if field_info:
all_fields["selection_"+field.name] = {'type':'selection', 'string': field_info[field.name]['string'], 'selection':[('set', 'Set'), ('remove', '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} 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')]}"})
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": elif field.ttype == "char":
field_info = model_obj.fields_get(cr, uid, [field.name], context)
all_fields["selection_"+field.name] = {'type':'selection', 'string': field_info[field.name]['string'], 'selection':[('set', 'Set'), ('remove', '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, 'size': field.size or 256} all_fields[field.name] = {'type':field.ttype, 'string': field.field_description, 'size': field.size or 256}
etree.SubElement(xml_group, 'field', {'name': "selection_"+field.name, 'colspan':'2', 'colspan':'2'})
etree.SubElement(xml_group, 'field', {'name': field.name, 'nolabel':'1', 'attrs':"{'invisible':[('selection_"+field.name+"','=','remove')]}", 'colspan':'2'})
etree.SubElement(xml_group, 'field', {'name': "selection__" + field.name, 'colspan':'2', 'colspan':'2'})
etree.SubElement(xml_group, 'field', {'name': field.name, 'nolabel':'1', 'attrs':"{'invisible':[('selection__" + field.name + "','=','remove')]}", 'colspan':'2'})
elif field.ttype == 'selection': elif field.ttype == 'selection':
field_info = model_obj.fields_get(cr, uid, [field.name], context)
all_fields["selection_"+field.name] = {'type':'selection', 'string': field_info[field.name]['string'], 'selection':[('set', 'Set'), ('remove', 'Remove')]}
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')]}
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[field.name] = {'type':field.ttype, 'string': field.field_description, 'selection': field_info[field.name]['selection']} all_fields[field.name] = {'type':field.ttype, 'string': field.field_description, 'selection': field_info[field.name]['selection']}
else: else:
field_info = model_obj.fields_get(cr, uid, [field.name], context)
all_fields[field.name] = {'type':field.ttype, 'string': field.field_description} all_fields[field.name] = {'type':field.ttype, 'string': field.field_description}
all_fields["selection_"+field.name] = {'type':'selection', 'string': field_info[field.name]['string'], 'selection':[('set', 'Set'), ('remove', 'Remove')]}
all_fields["selection__" + field.name] = {'type':'selection', 'string': field_info[field.name]['string'], 'selection':[('set', 'Set'), ('remove', 'Remove')]}
if field.ttype == 'text': if field.ttype == 'text':
xml_group = etree.SubElement(xml_group, 'group', {'colspan': '6'}) xml_group = etree.SubElement(xml_group, 'group', {'colspan': '6'})
etree.SubElement(xml_group, 'separator', {'string': all_fields[field.name]['string'], 'colspan': '2'}) etree.SubElement(xml_group, 'separator', {'string': all_fields[field.name]['string'], 'colspan': '2'})
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')]}"})
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')]}"})
else: else:
all_fields["selection_"+field.name] = {'type':'selection', 'string': field_info[field.name]['string'], 'selection':[('set', 'Set'), ('remove', 'Remove')]}
etree.SubElement(xml_group, 'field', {'name': "selection_"+field.name, 'colspan': '2', })
etree.SubElement(xml_group, 'field', {'name': field.name, 'nolabel':'1', 'attrs':"{'invisible':[('selection_"+field.name+"','=','remove')]}", 'colspan': '2', })
all_fields["selection__" + field.name] = {'type':'selection', 'string': field_info[field.name]['string'], 'selection':[('set', 'Set'), ('remove', 'Remove')]}
etree.SubElement(xml_group, 'field', {'name': "selection__" + field.name, 'colspan': '2', })
etree.SubElement(xml_group, 'field', {'name': field.name, 'nolabel':'1', 'attrs':"{'invisible':[('selection__" + field.name + "','=','remove')]}", 'colspan': '2', })
etree.SubElement(xml_form, 'separator', {'string' : '', 'colspan': '4'}) etree.SubElement(xml_form, 'separator', {'string' : '', 'colspan': '4'})
xml_group3 = etree.SubElement(xml_form, 'footer', {}) xml_group3 = etree.SubElement(xml_form, 'footer', {})
etree.SubElement(xml_group3, 'button', {'string' :'Close', 'icon': "gtk-close", 'special' :'cancel'}) etree.SubElement(xml_group3, 'button', {'string' :'Close', 'icon': "gtk-close", 'special' :'cancel'})
etree.SubElement(xml_group3, 'button', {'string' :'Apply', 'icon': "gtk-execute", 'type' :'object', 'name':"action_apply"}) etree.SubElement(xml_group3, 'button', {'string' :'Apply', 'icon': "gtk-execute", 'type' :'object', 'name':"action_apply"})
root = xml_form.getroottree() root = xml_form.getroottree()
result['arch'] = etree.tostring(root) result['arch'] = etree.tostring(root)
result['fields'] = all_fields result['fields'] = all_fields
@ -98,14 +92,14 @@ class mass_editing_wizard(osv.osv_memory):
model_obj = self.pool.get(context.get('active_model')) model_obj = self.pool.get(context.get('active_model'))
dict = {} dict = {}
for key , val in vals.items(): for key , val in vals.items():
if key.startswith('selection_'):
split_key = key.split('_', 1)[1]
if key.startswith('selection__'):
split_key = key.split('__', 1)[1]
if val == 'set': if val == 'set':
dict.update({split_key: vals.get(split_key, False)}) dict.update({split_key: vals.get(split_key, False)})
elif val == 'remove': elif val == 'remove':
dict.update({split_key: False}) dict.update({split_key: False})
elif val == 'remove_m2m': elif val == 'remove_m2m':
dict.update({split_key: [(5, 0, [])]})
dict.update({split_key: [(3, id) for id in vals.get(split_key, False)[0][2]]})
elif val == 'add': elif val == 'add':
m2m_list = [] m2m_list = []
for m2m_id in vals.get(split_key, False)[0][2]: for m2m_id in vals.get(split_key, False)[0][2]:
@ -120,5 +114,4 @@ class mass_editing_wizard(osv.osv_memory):
return {'type': 'ir.actions.act_window_close'} return {'type': 'ir.actions.act_window_close'}
mass_editing_wizard() mass_editing_wizard()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
Loading…
Cancel
Save