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.

105 lines
4.8 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 fields, osv
  23. from tools.translate import _
  24. class mass_object(osv.osv):
  25. _name = "mass.object"
  26. _columns = {
  27. 'name' : fields.char("Name", size=64, required=True, select=1),
  28. 'model_id' : fields.many2one('ir.model', 'Model', required=True, select=1),
  29. 'field_ids' : fields.many2many('ir.model.fields', 'mass_field_rel', 'mass_id', 'field_id', 'Fields'),
  30. 'ref_ir_act_window':fields.many2one('ir.actions.act_window', 'Sidebar action', readonly=True,
  31. help="Sidebar action to make this template available on records "
  32. "of the related document model"),
  33. 'ref_ir_value':fields.many2one('ir.values', 'Sidebar button', readonly=True,
  34. help="Sidebar button to open the sidebar action"),
  35. 'model_ids': fields.many2many('ir.model', string='Model List')
  36. }
  37. def onchange_model(self, cr, uid, ids, model_id):
  38. model_ids = []
  39. if model_id:
  40. model_obj = self.pool.get('ir.model')
  41. model_data = model_obj.browse(cr, uid, model_id)
  42. model_ids = [model_id]
  43. active_model_obj = self.pool.get(model_data.model)
  44. if active_model_obj._inherits:
  45. for key, val in active_model_obj._inherits.items():
  46. found_model_ids = model_obj.search(cr, uid, [('model', '=', key)])
  47. if found_model_ids:
  48. model_ids.append(found_model_ids[0])
  49. return {'value': {'model_ids': [(6, 0, model_ids)]}}
  50. def create_action(self, cr, uid, ids, context=None):
  51. vals = {}
  52. action_obj = self.pool.get('ir.actions.act_window')
  53. data_obj = self.pool.get('ir.model.data')
  54. for data in self.browse(cr, uid, ids, context=context):
  55. src_obj = data.model_id.model
  56. button_name = _('Mass Editing (%s)') % data.name
  57. vals['ref_ir_act_window'] = action_obj.create(cr, uid, {
  58. 'name': button_name,
  59. 'type': 'ir.actions.act_window',
  60. 'res_model': 'mass.editing.wizard',
  61. 'src_model': src_obj,
  62. 'view_type': 'form',
  63. 'context': "{'mass_editing_object' : %d}" % (data.id),
  64. 'view_mode':'form,tree',
  65. 'target': 'new',
  66. 'auto_refresh':1
  67. }, context)
  68. vals['ref_ir_value'] = self.pool.get('ir.values').create(cr, uid, {
  69. 'name': button_name,
  70. 'model': src_obj,
  71. 'key2': 'client_action_multi',
  72. 'value': "ir.actions.act_window," + str(vals['ref_ir_act_window']),
  73. 'object': True,
  74. }, context)
  75. self.write(cr, uid, ids, {
  76. 'ref_ir_act_window': vals.get('ref_ir_act_window',False),
  77. 'ref_ir_value': vals.get('ref_ir_value',False),
  78. }, context)
  79. return True
  80. def unlink_action(self, cr, uid, ids, context=None):
  81. for template in self.browse(cr, uid, ids, context=context):
  82. try:
  83. if template.ref_ir_act_window:
  84. self.pool.get('ir.actions.act_window').unlink(cr, uid, template.ref_ir_act_window.id, context)
  85. if template.ref_ir_value:
  86. ir_values_obj = self.pool.get('ir.values')
  87. ir_values_obj.unlink(cr, uid, template.ref_ir_value.id, context)
  88. except:
  89. raise osv.except_osv(_("Warning"), _("Deletion of the action record failed."))
  90. return True
  91. def unlink(self, cr, uid, ids, context=None):
  92. self.unlink_action(cr, uid, ids, context)
  93. return super(mass_object, self).unlink(cr, uid, ids, context)
  94. mass_object()
  95. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: