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.

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