Browse Source

[IMP] mass_editing : Improved typos and did some refactoring

pull/2/head
Serpent Consulting Services 12 years ago
parent
commit
099f593621
  1. 3
      mass_editing/__openerp__.py
  2. 47
      mass_editing/mass_editing.py
  3. 4
      mass_editing/mass_editing_view.xml
  4. 50
      mass_editing/wizard/mass_editing_wizard.py

3
mass_editing/__openerp__.py

@ -31,8 +31,7 @@
For more details/customization/feedback contact us on contact@serpentcs.com.
""",
'depends': ['base'],
'init_xml': [],
'update_xml': [
'data': [
'mass_editing_view.xml',
],
'installable': True,

47
mass_editing/mass_editing.py

@ -40,14 +40,14 @@ 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,
'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"),
"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)
}
@ -65,9 +65,6 @@ class mass_object(osv.osv):
if model_ids:
model_list += "," + str(model_ids[0]) + ""
model_list += "]"
# model_list = map(int, model_list[1:-1].split(','))
# context['model_list'] = model_list
# print 'context:::', context
return {'value': {'model_list': model_list}}
def create_action(self, cr, uid, ids, context=None):
@ -78,26 +75,26 @@ class mass_object(osv.osv):
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',
'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'] = 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,
'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),
'ref_ir_act_window': vals.get('ref_ir_act_window', False),
'ref_ir_value': vals.get('ref_ir_value', False),
}, context)
return True

4
mass_editing/mass_editing_view.xml

@ -14,9 +14,9 @@
<notebook colspan="4">
<page string="Fields">
<field name="field_ids" colspan="4" nolabel="1"
domain="[('ttype', 'not in', ['one2many', 'refenrence', 'function']), ('model_id', 'in', model_list)]"/>
domain="[('ttype', 'not in', ['one2many', 'reference', 'function']), ('model_id', 'in', model_list)]"/>
</page>
<page string="Advance">
<page string="Advanced">
<group colspan="2" col="2">
<button name="create_action" string="Add sidebar button" type="object" icon="gtk-execute"
colspan="2" attrs="{'invisible':[('ref_ir_act_window','!=',False)]}"

50
mass_editing/wizard/mass_editing_wizard.py

@ -30,65 +30,63 @@ class mass_editing_wizard(osv.osv_memory):
_columns = {
}
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
result = super(mass_editing_wizard, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar,submenu)
result = super(mass_editing_wizard, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu)
if context.get('mass_editing_object'):
mass_object = self.pool.get('mass.object')
editing_data = mass_object.browse(cr, uid, context.get('mass_editing_object'), context)
all_fields = {}
xml_form = etree.Element('form', {'string': tools.ustr(editing_data.name), 'version':'7.0'})
xml_group = etree.SubElement(xml_form, 'group', {'colspan': '4'})
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'})
model_obj = self.pool.get(context.get('active_model'))
for field in editing_data.field_ids:
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["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'})
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, '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')]}"})
elif field.ttype == "many2one":
field_info = model_obj.fields_get(cr, uid, [field.name], context)
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}
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":
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}
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':
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')]}
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')]}"})
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']}
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["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':
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, 'field', {'name': "selection_"+field.name,'colspan': '2','nolabel':'1'})
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')]}"})
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', {})
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' :'Close', 'icon': "gtk-close", 'special' :'cancel'})
etree.SubElement(xml_group3, 'button', {'string' :'Apply', 'icon': "gtk-execute", 'type' :'object', 'name':"action_apply"})
root = xml_form.getroottree()
result['arch'] = etree.tostring(root)
@ -99,15 +97,15 @@ class mass_editing_wizard(osv.osv_memory):
if context.get('active_model') and context.get('active_ids'):
model_obj = self.pool.get(context.get('active_model'))
dict = {}
for key ,val in vals.items():
for key , val in vals.items():
if key.startswith('selection_'):
split_key= key.split('_',1)[1]
split_key = key.split('_', 1)[1]
if val == 'set':
dict.update({split_key: vals.get(split_key, False)})
elif val == 'remove':
dict.update({split_key: False})
elif val == 'remove_m2m':
dict.update({split_key: [(5,0,[])]})
dict.update({split_key: [(5, 0, [])]})
elif val == 'add':
m2m_list = []
for m2m_id in vals.get(split_key, False)[0][2]:

Loading…
Cancel
Save