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.

102 lines
4.7 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_list': fields.char('Model List', size=256)
  36. }
  37. def onchange_model(self, cr, uid, ids, model_id):
  38. model_list = ""
  39. if model_id:
  40. model_obj = self.pool.get('ir.model')
  41. model_data = model_obj.browse(cr, uid, model_id)
  42. model_list = "[" + str(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. model_ids = model_obj.search(cr, uid, [('model', '=', key)])
  47. if model_ids:
  48. model_list += "," + str(model_ids[0]) + ""
  49. model_list += "]"
  50. return {'value': {'model_list': model_list}}
  51. def create_action(self, cr, uid, ids, context=None):
  52. vals = {}
  53. action_obj = self.pool.get('ir.actions.act_window')
  54. data_obj = self.pool.get('ir.model.data')
  55. for data in self.browse(cr, uid, ids, context=context):
  56. src_obj = data.model_id.model
  57. button_name = _('Mass Editing (%s)') % data.name
  58. vals['ref_ir_act_window'] = action_obj.create(cr, uid, {
  59. 'name': button_name,
  60. 'type': 'ir.actions.act_window',
  61. 'res_model': 'mass.editing.wizard',
  62. 'src_model': src_obj,
  63. 'view_type': 'form',
  64. 'context': "{'mass_editing_object' : %d}" % (data.id),
  65. 'view_mode':'form,tree',
  66. 'target': 'new',
  67. 'auto_refresh':1
  68. }, context)
  69. vals['ref_ir_value'] = self.pool.get('ir.values').create(cr, uid, {
  70. 'name': button_name,
  71. 'model': src_obj,
  72. 'key2': 'client_action_multi',
  73. 'value': "ir.actions.act_window," + str(vals['ref_ir_act_window']),
  74. 'object': True,
  75. }, context)
  76. self.write(cr, uid, ids, {
  77. 'ref_ir_act_window': vals.get('ref_ir_act_window',False),
  78. 'ref_ir_value': vals.get('ref_ir_value',False),
  79. }, context)
  80. return True
  81. def unlink_action(self, cr, uid, ids, context=None):
  82. for template in self.browse(cr, uid, ids, context=context):
  83. try:
  84. if template.ref_ir_act_window:
  85. self.pool.get('ir.actions.act_window').unlink(cr, uid, template.ref_ir_act_window.id, context)
  86. if template.ref_ir_value:
  87. ir_values_obj = self.pool.get('ir.values')
  88. ir_values_obj.unlink(cr, uid, template.ref_ir_value.id, context)
  89. except:
  90. raise osv.except_osv(_("Warning"), _("Deletion of the action record failed."))
  91. return True
  92. mass_object()
  93. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: