mass_editing.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 import models, fields, api, tools, _
  22. from lxml import etree
  23. class ir_model_fields(models.Model):
  24. _inherit = 'ir.model.fields'
  25. @api.v7
  26. def search(self, cr, uid, args, offset=0, limit=0, order=None, context=None, count=False):
  27. model_domain = []
  28. for domain in args:
  29. if domain[0] == 'model_id' and domain[2] and type(domain[2]) != list:
  30. model_domain += [('model_id', 'in', map(int, domain[2][1:-1].split(',')))]
  31. else:
  32. model_domain.append(domain)
  33. return super(ir_model_fields, self).search(cr, uid, model_domain, offset=offset, limit=limit, order=order, context=context, count=count)
  34. ir_model_fields()
  35. class mass_object(models.Model):
  36. _name = "mass.object"
  37. name = fields.Char(string="Name", required=True, select=1)
  38. model_id = fields.Many2one('ir.model', string='Model', required=False)
  39. field_ids = fields.Many2many('ir.model.fields', 'mass_field_rel', 'mass_id', 'field_id', string='Fields')
  40. ref_ir_act_window = fields.Many2one('ir.actions.act_window', string='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', string='Sidebar button', readonly=True,
  44. help="Sidebar button to open the sidebar action")
  45. model_ids = fields.Many2many('ir.model', string='Model List')
  46. model_list = fields.Char(string='Model List', size=256)
  47. _sql_constraints = [
  48. ('name_uniq', 'unique (name)', _('Name must be unique!')), ]
  49. @api.multi
  50. @api.onchange('model_id')
  51. def onchange_model(self):
  52. if self._context is None: self._context = {}
  53. if not self.model_id:
  54. self.model_ids = [(6, 0, [])]
  55. model_ids = [self.model_id.id]
  56. model_obj = self.env['ir.model']
  57. # active_model_obj = self.env[model_obj.browse(self.model_id.id).model]
  58. self.model_ids = [[6, 0, model_ids]]
  59. self.model_list = [self.model_ids.id]
  60. @api.multi
  61. def create_action(self):
  62. vals = {}
  63. action_obj = self.env['ir.actions.act_window']
  64. data_obj = self.env['ir.model.data']
  65. src_obj = self.model_id.model
  66. button_name = _('Mass Editing (%s)') % self.name
  67. vals['ref_ir_act_window'] = action_obj.create({
  68. 'name': button_name,
  69. 'type': 'ir.actions.act_window',
  70. 'res_model': 'mass.editing.wizard',
  71. 'src_model': src_obj,
  72. 'view_type': 'form',
  73. 'context': "{'mass_editing_object' : %d}" % (self.id),
  74. 'view_mode':'form,tree',
  75. 'target': 'new',
  76. 'auto_refresh':1
  77. }).id
  78. vals['ref_ir_value'] = self.env['ir.values'].create({
  79. 'name': button_name,
  80. 'model': src_obj,
  81. 'key2': 'client_action_multi',
  82. 'value': "ir.actions.act_window," + str(vals['ref_ir_act_window']),
  83. 'object': True,
  84. }).id
  85. self.write({
  86. 'ref_ir_act_window': vals.get('ref_ir_act_window', False),
  87. 'ref_ir_value': vals.get('ref_ir_value', False),
  88. })
  89. return True
  90. @api.one
  91. def unlink_action(self):
  92. if self.ref_ir_act_window:
  93. winid = self.ref_ir_act_window.id
  94. self.env['ir.actions.act_window'].search([('id', '=', winid)]).unlink()
  95. if self.ref_ir_value:
  96. uinid = self.ref_ir_value.id
  97. self.env['ir_values'].search([('id', '=', uinid)]).unlink()
  98. @api.one
  99. def unlink(self):
  100. self.unlink_action()
  101. return super(mass_object, self).unlink()
  102. @api.multi
  103. def copy(self, default):
  104. if default is None:
  105. default = {}
  106. default.update({'name':'', 'field_ids': []})
  107. return super(mass_object, self).copy(default)
  108. mass_object()
  109. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: