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.

129 lines
5.8 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 openerp.osv import orm, fields
  22. import openerp.tools
  23. from openerp.tools.translate import _
  24. from lxml import etree
  25. class ir_model_fields(orm.Model):
  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.append(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(orm.Model):
  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. _sql_constraints = [
  50. ('name_uniq', 'unique (name)', 'Name must be unique!'),
  51. ]
  52. def onchange_model(self, cr, uid, ids, model_id, context=None):
  53. if context is None: context = {}
  54. if not model_id:
  55. return {'value': {'model_list': ''}}
  56. model_list = [model_id]
  57. model_obj = self.pool.get('ir.model')
  58. active_model_obj = self.pool.get(model_obj.browse(cr, uid, model_id).model)
  59. if active_model_obj._inherits:
  60. for key, val in active_model_obj._inherits.items():
  61. model_ids = model_obj.search(cr, uid, [('model', '=', key)], context=context)
  62. model_list += model_ids
  63. return {'value': {'model_list': str(model_list)}}
  64. def create_action(self, cr, uid, ids, context=None):
  65. vals = {}
  66. action_obj = self.pool.get('ir.actions.act_window')
  67. data_obj = self.pool.get('ir.model.data')
  68. ir_values_obj = self.pool.get('ir.values')
  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'] = ir_values_obj.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. def unlink(self, cr, uid, ids, context=None):
  107. self.unlink_action(cr, uid, ids, context)
  108. return super(mass_object, self).unlink(cr, uid, ids, context)
  109. def copy(self, cr, uid, record_id, default=None, context=None):
  110. if default is None:
  111. default = {}
  112. default.update({'name':'','field_ids': []})
  113. return super(mass_object, self).copy(cr, uid, record_id, default, context)
  114. mass_object()
  115. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: