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.

117 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 osv import fields, osv
  22. from tools.translate import _
  23. from lxml import etree
  24. from openerp import tools
  25. class ir_model_fields(osv.osv):
  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 += 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(osv.osv):
  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)])
  59. if model_ids:
  60. model_list += model_ids
  61. return {'value': {'model_list': str(model_list)}}
  62. def create_action(self, cr, uid, ids, context=None):
  63. vals = {}
  64. action_obj = self.pool.get('ir.actions.act_window')
  65. data_obj = self.pool.get('ir.model.data')
  66. ir_values_obj = self.pool.get('ir.values')
  67. for data in self.browse(cr, uid, ids, context=context):
  68. src_obj = data.model_id.model
  69. button_name = _('Mass Editing (%s)') % data.name
  70. vals['ref_ir_act_window'] = action_obj.create(cr, uid, {
  71. 'name': button_name,
  72. 'type': 'ir.actions.act_window',
  73. 'res_model': 'mass.editing.wizard',
  74. 'src_model': src_obj,
  75. 'view_type': 'form',
  76. 'context': "{'mass_editing_object' : %d}" % (data.id),
  77. 'view_mode':'form,tree',
  78. 'target': 'new',
  79. 'auto_refresh':1
  80. }, context)
  81. vals['ref_ir_value'] = ir_values_obj.create(cr, uid, {
  82. 'name': button_name,
  83. 'model': src_obj,
  84. 'key2': 'client_action_multi',
  85. 'value': "ir.actions.act_window," + str(vals['ref_ir_act_window']),
  86. 'object': True,
  87. }, context)
  88. self.write(cr, uid, ids, {
  89. 'ref_ir_act_window': vals.get('ref_ir_act_window', False),
  90. 'ref_ir_value': vals.get('ref_ir_value', False),
  91. }, context)
  92. return True
  93. def unlink_action(self, cr, uid, ids, context=None):
  94. for template in self.browse(cr, uid, ids, context=context):
  95. try:
  96. if template.ref_ir_act_window:
  97. self.pool.get('ir.actions.act_window').unlink(cr, uid, template.ref_ir_act_window.id, context)
  98. if template.ref_ir_value:
  99. ir_values_obj = self.pool.get('ir.values')
  100. ir_values_obj.unlink(cr, uid, template.ref_ir_value.id, context)
  101. except:
  102. raise osv.except_osv(_("Warning"), _("Deletion of the action record failed."))
  103. return True
  104. mass_object()
  105. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: