You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
12 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # Copyright (C) 2012 Serpent Consulting Services (<http://www.serpentcs.com>)
  6. # Copyright (C) 2010-Today OpenERP SA (<http://www.openerp.com>)
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>
  20. #
  21. ##############################################################################
  22. from osv import osv
  23. from osv import fields
  24. from lxml import etree
  25. import tools
  26. class mass_editing_wizard(osv.osv_memory):
  27. _name = 'mass.editing.wizard'
  28. _columns = {
  29. 'serpent_image': fields.binary('Image'),
  30. }
  31. _defaults = {
  32. 'serpent_image': '/9j/4AAQSkZJRgABAQEASABIAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2NjIpLCBxdWFsaXR5ID0gOTAK/9sAQwADAgIDAgIDAwMDBAMDBAUIBQUEBAUKBwcGCAwKDAwLCgsLDQ4SEA0OEQ4LCxAWEBETFBUVFQwPFxgWFBgSFBUU/9sAQwEDBAQFBAUJBQUJFA0LDRQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU/8AAEQgAJgBoAwEiAAIRAQMRAf/EAB0AAAICAgMBAAAAAAAAAAAAAAAHAQgEBQIGCQP/xAA1EAABAwMDAwIEBAQHAAAAAAABAgMEBQYRAAcSEyExCEEUIjJhFRZRcSQzgaFCUmKChJ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iFI5HJyUjAznU5A2ceD3/po1IGe+jUAg+41xCBjwNGjTGQCRjx76k4OjRoA0aNGgJ1B7d/00aNAHvqfto0aAMZ1GO+jRoCT27aNGjQH//Z',
  33. }
  34. def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
  35. result = super(mass_editing_wizard, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar,submenu)
  36. if context.get('mass_editing_object'):
  37. mass_object = self.pool.get('mass.object')
  38. editing_data = mass_object.browse(cr, uid, context.get('mass_editing_object'), context)
  39. all_fields = {}
  40. xml_form = etree.Element('form', {'string': tools.ustr(editing_data.name)})
  41. xml_group = etree.SubElement(xml_form, 'group', {'colspan': '4'})
  42. etree.SubElement(xml_group, 'field', {'name': 'serpent_image', 'nolabel': '1','colspan': '1', 'modifiers': '{"readonly": true}', 'widget':'image'})
  43. etree.SubElement(xml_group, 'label', {'string': '','colspan': '2'})
  44. all_fields['serpent_image'] = {'type':'binary', 'string':''}
  45. xml_group = etree.SubElement(xml_form, 'group', {'colspan': '4'})
  46. model_obj = self.pool.get(context.get('active_model'))
  47. for field in editing_data.field_ids:
  48. if field.ttype == "many2many":
  49. field_info = model_obj.fields_get(cr, uid, [field.name], context)
  50. all_fields[field.name] = field_info[field.name]
  51. all_fields["selection_"+field.name] = {'type':'selection', 'string': field_info[field.name]['string'],'selection':[('set','Set'),('remove_m2m','Remove'),('add','Add')]}
  52. xml_group = etree.SubElement(xml_group, 'group', {'colspan': '4'})
  53. etree.SubElement(xml_group, 'separator', {'string': field_info[field.name]['string'],'colspan': '2'})
  54. etree.SubElement(xml_group, 'field', {'name': "selection_"+field.name,'colspan': '2','nolabel':'1'})
  55. etree.SubElement(xml_group, 'field', {'name': field.name, 'colspan':'4', 'nolabel':'1', 'attrs':"{'invisible':[('selection_"+field.name+"','=','remove_m2m')]}"})
  56. elif field.ttype == "many2one":
  57. field_info = model_obj.fields_get(cr, uid, [field.name], context)
  58. if field_info:
  59. all_fields["selection_"+field.name] = {'type':'selection', 'string': field_info[field.name]['string'],'selection':[('set','Set'),('remove','Remove')]}
  60. all_fields[field.name] = {'type':field.ttype, 'string': field.field_description, 'relation': field.relation}
  61. etree.SubElement(xml_group, 'field', {'name': "selection_"+field.name, 'colspan':'2'})
  62. etree.SubElement(xml_group, 'field', {'name': field.name,'nolabel':'1','colspan':'2', 'attrs':"{'invisible':[('selection_"+field.name+"','=','remove')]}"})
  63. elif field.ttype == "char":
  64. field_info = model_obj.fields_get(cr, uid, [field.name], context)
  65. all_fields["selection_"+field.name] = {'type':'selection', 'string': field_info[field.name]['string'],'selection':[('set','Set'),('remove','Remove')]}
  66. all_fields[field.name] = {'type':field.ttype, 'string': field.field_description, 'size': field.size or 256}
  67. etree.SubElement(xml_group, 'field', {'name': "selection_"+field.name,'colspan':'2', 'colspan':'2'})
  68. etree.SubElement(xml_group, 'field', {'name': field.name,'nolabel':'1', 'attrs':"{'invisible':[('selection_"+field.name+"','=','remove')]}", 'colspan':'2'})
  69. elif field.ttype == 'selection':
  70. field_info = model_obj.fields_get(cr, uid, [field.name], context)
  71. all_fields["selection_"+field.name] = {'type':'selection', 'string': field_info[field.name]['string'],'selection':[('set','Set'),('remove','Remove')]}
  72. field_info = model_obj.fields_get(cr, uid, [field.name], context)
  73. etree.SubElement(xml_group, 'field', {'name': "selection_"+field.name, 'colspan':'2'})
  74. etree.SubElement(xml_group, 'field', {'name': field.name,'nolabel':'1','colspan':'2', 'attrs':"{'invisible':[('selection_"+field.name+"','=','remove')]}"})
  75. all_fields[field.name] = {'type':field.ttype, 'string': field.field_description, 'selection': field_info[field.name]['selection']}
  76. else:
  77. field_info = model_obj.fields_get(cr, uid, [field.name], context)
  78. all_fields[field.name] = {'type':field.ttype, 'string': field.field_description}
  79. all_fields["selection_"+field.name] = {'type':'selection', 'string': field_info[field.name]['string'],'selection':[('set','Set'),('remove','Remove')]}
  80. if field.ttype == 'text':
  81. xml_group = etree.SubElement(xml_group, 'group', {'colspan': '6'})
  82. etree.SubElement(xml_group, 'separator', {'string': all_fields[field.name]['string'],'colspan': '2'})
  83. etree.SubElement(xml_group, 'field', {'name': "selection_"+field.name,'colspan': '2','nolabel':'1'})
  84. etree.SubElement(xml_group, 'field', {'name': field.name, 'colspan':'4', 'nolabel':'1', 'attrs':"{'invisible':[('selection_"+field.name+"','=','remove')]}"})
  85. else:
  86. all_fields["selection_"+field.name] = {'type':'selection', 'string': field_info[field.name]['string'],'selection':[('set','Set'),('remove','Remove')]}
  87. etree.SubElement(xml_group, 'field', {'name': "selection_"+field.name, 'colspan': '2',})
  88. etree.SubElement(xml_group, 'field', {'name': field.name,'nolabel':'1', 'attrs':"{'invisible':[('selection_"+field.name+"','=','remove')]}",'colspan': '2',})
  89. etree.SubElement(xml_form, 'separator', {'string' : '','colspan': '6'})
  90. xml_group3 = etree.SubElement(xml_form, 'group', {'col': '2', 'colspan': '4'})
  91. etree.SubElement(xml_group3, 'button', {'string' :'Close','icon': "gtk-close", 'special' :'cancel'})
  92. etree.SubElement(xml_group3, 'button', {'string' :'Apply','icon': "gtk-execute", 'type' :'object','name':"action_apply"})
  93. root = xml_form.getroottree()
  94. result['arch'] = etree.tostring(root)
  95. result['fields'] = all_fields
  96. return result
  97. def create(self, cr, uid, vals, context=None):
  98. if context.get('active_model') and context.get('active_ids'):
  99. model_obj = self.pool.get(context.get('active_model'))
  100. dict = {}
  101. for key ,val in vals.items():
  102. if key.startswith('selection_'):
  103. split_key= key.split('_',1)[1]
  104. if val == 'set':
  105. dict.update({split_key: vals.get(split_key, False)})
  106. elif val == 'remove':
  107. dict.update({split_key: False})
  108. elif val == 'remove_m2m':
  109. dict.update({split_key: [(5,0,[])]})
  110. elif val == 'add':
  111. m2m_list = []
  112. for m2m_id in vals.get(split_key, False)[0][2]:
  113. m2m_list.append((4, m2m_id))
  114. dict.update({split_key: m2m_list})
  115. if dict:
  116. model_obj.write(cr, uid, context.get('active_ids'), dict, context)
  117. result = super(mass_editing_wizard, self).create(cr, uid, {}, context)
  118. return result
  119. def action_apply(self, cr, uid, ids, context=None):
  120. return {'type': 'ir.actions.act_window_close'}
  121. mass_editing_wizard()
  122. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: