1
# -*- coding: utf-8 -*-
2
##############################################################################
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>)
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.
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.
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/>
21
##############################################################################
24
from osv import fields, osv
25
from tools.translate import _
27
class mass_object(osv.osv):
31
'name' : fields.char("Name", size=64, required=True, select=1),
32
'model_id' : fields.many2one('ir.model', 'Model', required=True, select=1),
33
'field_ids' : fields.many2many('ir.model.fields', 'mass_field_rel', 'mass_id', 'field_id', 'Fields'),
34
'ref_ir_act_window':fields.many2one('ir.actions.act_window', 'Sidebar action', readonly=True,
35
help="Sidebar action to make this template available on records "
36
"of the related document model"),
37
'ref_ir_value':fields.many2one('ir.values', 'Sidebar button', readonly=True,
38
help="Sidebar button to open the sidebar action"),
39
'model_list': fields.char('Model List', size=256)
42
def onchange_model(self, cr, uid, ids, model_id):
45
model_obj = self.pool.get('ir.model')
46
model_data = model_obj.browse(cr, uid, model_id)
47
model_list = "[" + str(model_id) + ""
48
active_model_obj = self.pool.get(model_data.model)
49
if active_model_obj._inherits:
50
for key, val in active_model_obj._inherits.items():
51
model_ids = model_obj.search(cr, uid, [('model', '=', key)])
53
model_list += "," + str(model_ids[0]) + ""
55
return {'value': {'model_list': model_list}}
57
def create_action(self, cr, uid, ids, context=None):
59
action_obj = self.pool.get('ir.actions.act_window')
60
data_obj = self.pool.get('ir.model.data')
61
for data in self.browse(cr, uid, ids, context=context):
62
src_obj = data.model_id.model
63
button_name = _('Mass Editing (%s)') % data.name
64
vals['ref_ir_act_window'] = action_obj.create(cr, uid, {
66
'type': 'ir.actions.act_window',
67
'res_model': 'mass.editing.wizard',
70
'context': "{'mass_editing_object' : %d}" % (data.id),
71
'view_mode':'form,tree',
75
vals['ref_ir_value'] = self.pool.get('ir.values').create(cr, uid, {
78
'key2': 'client_action_multi',
79
'value': "ir.actions.act_window," + str(vals['ref_ir_act_window']),
82
self.write(cr, uid, ids, {
83
'ref_ir_act_window': vals.get('ref_ir_act_window',False),
84
'ref_ir_value': vals.get('ref_ir_value',False),
88
def unlink_action(self, cr, uid, ids, context=None):
89
for template in self.browse(cr, uid, ids, context=context):
91
if template.ref_ir_act_window:
92
self.pool.get('ir.actions.act_window').unlink(cr, uid, template.ref_ir_act_window.id, context)
93
if template.ref_ir_value:
94
ir_values_obj = self.pool.get('ir.values')
95
ir_values_obj.unlink(cr, uid, template.ref_ir_value.id, context)
97
raise osv.except_osv(_("Warning"), _("Deletion of the action record failed."))
102
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: