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.

114 lines
5.3 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # This module uses OpenERP, Open Source Management Solution Framework.
  5. # Copyright (C) 2012-Today Serpent Consulting Services (<http://www.serpentcs.com>)
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>
  19. #
  20. ##############################################################################
  21. from openerp.osv import orm, fields
  22. import openerp.tools
  23. from openerp.tools.translate import _
  24. from lxml import etree
  25. class ir_model_fields(orm.Model):
  26. _inherit = 'ir.model.fields'
  27. def search(self, cr, uid, args, offset=0, limit=0, order=None, context=None, count=False):
  28. model_domain = []
  29. for domain in args:
  30. if domain[0] == 'model_id' and domain[2] and type(domain[2]) != list:
  31. model_domain += [('model_id', 'in', map(int, domain[2][1:-1].split(',')))]
  32. else:
  33. model_domain.append(domain)
  34. return super(ir_model_fields, self).search(cr, uid, model_domain, offset=offset, limit=limit, order=order, context=context, count=count)
  35. ir_model_fields()
  36. class mass_object(orm.Model):
  37. _name = "mass.object"
  38. _columns = {
  39. 'name' : fields.char("Name", size=64, required=True, select=1),
  40. 'model_id' : fields.many2one('ir.model', 'Model', required=True, select=1),
  41. 'field_ids' : fields.many2many('ir.model.fields', 'mass_field_rel', 'mass_id', 'field_id', 'Fields'),
  42. 'ref_ir_act_window':fields.many2one('ir.actions.act_window', 'Sidebar Action', readonly=True,
  43. help="Sidebar action to make this template available on records \
  44. of the related document model"),
  45. 'ref_ir_value':fields.many2one('ir.values', 'Sidebar Button', readonly=True,
  46. help="Sidebar button to open the sidebar action"),
  47. 'model_list': fields.char('Model List', size=256)
  48. }
  49. def onchange_model(self, cr, uid, ids, model_id, context=None):
  50. if context is None: context = {}
  51. if not model_id:
  52. return {'value': {'model_list': ''}}
  53. model_list = [model_id]
  54. model_obj = self.pool.get('ir.model')
  55. active_model_obj = self.pool.get(model_obj.browse(cr, uid, model_id).model)
  56. if active_model_obj._inherits:
  57. for key, val in active_model_obj._inherits.items():
  58. model_ids = model_obj.search(cr, uid, [('model', '=', key)], context=context)
  59. model_list += model_ids
  60. return {'value': {'model_list': str(model_list)}}
  61. def create_action(self, cr, uid, ids, context=None):
  62. vals = {}
  63. action_obj = self.pool.get('ir.actions.act_window')
  64. data_obj = self.pool.get('ir.model.data')
  65. ir_values_obj = self.pool.get('ir.values')
  66. for data in self.browse(cr, uid, ids, context=context):
  67. src_obj = data.model_id.model
  68. button_name = _('Mass Editing (%s)') % data.name
  69. vals['ref_ir_act_window'] = action_obj.create(cr, uid, {
  70. 'name': button_name,
  71. 'type': 'ir.actions.act_window',
  72. 'res_model': 'mass.editing.wizard',
  73. 'src_model': src_obj,
  74. 'view_type': 'form',
  75. 'context': "{'mass_editing_object' : %d}" % (data.id),
  76. 'view_mode':'form,tree',
  77. 'target': 'new',
  78. 'auto_refresh':1
  79. }, context)
  80. vals['ref_ir_value'] = ir_values_obj.create(cr, uid, {
  81. 'name': button_name,
  82. 'model': src_obj,
  83. 'key2': 'client_action_multi',
  84. 'value': "ir.actions.act_window," + str(vals['ref_ir_act_window']),
  85. 'object': True,
  86. }, context)
  87. self.write(cr, uid, ids, {
  88. 'ref_ir_act_window': vals.get('ref_ir_act_window', False),
  89. 'ref_ir_value': vals.get('ref_ir_value', False),
  90. }, context)
  91. return True
  92. def unlink_action(self, cr, uid, ids, context=None):
  93. for template in self.browse(cr, uid, ids, context=context):
  94. try:
  95. if template.ref_ir_act_window:
  96. self.pool.get('ir.actions.act_window').unlink(cr, uid, template.ref_ir_act_window.id, context)
  97. if template.ref_ir_value:
  98. ir_values_obj = self.pool.get('ir.values')
  99. ir_values_obj.unlink(cr, uid, template.ref_ir_value.id, context)
  100. except:
  101. raise osv.except_osv(_("Warning"), _("Deletion of the action record failed."))
  102. return True
  103. mass_object()
  104. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: