[FIX] More fixes landed
parent
099f593621
commit
7dae0d6f69
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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",
|
||||||
|
|
|
@ -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:
|
if domain[0] == 'model_id' and domain[2] and type(domain[2]) != list:
|
||||||
res = self.search(cr, uid, [('model_id', 'in', map(int, domain[2][1:-1].split(',')))])
|
model_domain += [('model_id', 'in', map(int, domain[2][1:-1].split(',')))]
|
||||||
return res
|
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()
|
||||||
|
|
||||||
|
@ -53,24 +56,23 @@ class mass_object(osv.osv):
|
||||||
|
|
||||||
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 not model_id:
|
||||||
if model_id:
|
return {'value': {'model_list': ''}}
|
||||||
model_obj = self.pool.get('ir.model')
|
model_list = [model_id]
|
||||||
model_data = model_obj.browse(cr, uid, model_id)
|
model_obj = self.pool.get('ir.model')
|
||||||
model_list = "[" + str(model_id) + ""
|
active_model_obj = self.pool.get(model_obj.browse(cr, uid, model_id).model)
|
||||||
active_model_obj = self.pool.get(model_data.model)
|
if active_model_obj._inherits:
|
||||||
if active_model_obj._inherits:
|
for key, val in active_model_obj._inherits.items():
|
||||||
for key, val in active_model_obj._inherits.items():
|
model_ids = model_obj.search(cr, uid, [('model', '=', key)])
|
||||||
model_ids = model_obj.search(cr, uid, [('model', '=', key)])
|
if model_ids:
|
||||||
if model_ids:
|
model_list += model_ids
|
||||||
model_list += "," + str(model_ids[0]) + ""
|
return {'value': {'model_list': str(model_list)}}
|
||||||
model_list += "]"
|
|
||||||
return {'value': {'model_list': 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
|
||||||
|
@ -85,7 +87,7 @@ class mass_object(osv.osv):
|
||||||
'target': 'new',
|
'target': 'new',
|
||||||
'auto_refresh':1
|
'auto_refresh':1
|
||||||
}, context)
|
}, context)
|
||||||
vals['ref_ir_value'] = self.pool.get('ir.values').create(cr, uid, {
|
vals['ref_ir_value'] = ir_values_obj.create(cr, uid, {
|
||||||
'name': button_name,
|
'name': button_name,
|
||||||
'model': src_obj,
|
'model': src_obj,
|
||||||
'key2': 'client_action_multi',
|
'key2': 'client_action_multi',
|
||||||
|
|
|
@ -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[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["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': "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': 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': "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': 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': "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': 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')]}
|
||||||
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': "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': 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': "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': 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')]}
|
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': "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_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_'):
|
if key.startswith('selection__'):
|
||||||
split_key = key.split('_', 1)[1]
|
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…
Reference in New Issue