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.

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