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.

124 lines
5.1 KiB

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