~therp-nl/server-env-tools/view_groups_id_attribution

« back to all changes in this revision

Viewing changes to mass_editing/mass_editing.py

  • Committer: Serpent Consulting Services
  • Author(s): Maxime Chambreuil
  • Date: 2013-05-01 11:50:48 UTC
  • Revision ID: support@serpentcs.com-20130501115048-6e454129ypkji9vr
[REV] Reverting previous commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
23
 
 
24
 
from osv import fields, osv
25
 
from tools.translate import _
26
 
 
27
 
class mass_object(osv.osv):
28
 
    _name = "mass.object"
29
 
 
30
 
    _columns = {
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)
40
 
    }
41
 
 
42
 
    def onchange_model(self, cr, uid, ids, model_id):
43
 
        model_list = ""
44
 
        if 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)])
52
 
                    if model_ids:
53
 
                        model_list += "," + str(model_ids[0]) + ""
54
 
            model_list += "]"
55
 
        return {'value': {'model_list': model_list}}
56
 
 
57
 
    def create_action(self, cr, uid, ids, context=None):
58
 
        vals = {}
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, {
65
 
                 'name': button_name,
66
 
                 'type': 'ir.actions.act_window',
67
 
                 'res_model': 'mass.editing.wizard',
68
 
                 'src_model': src_obj,
69
 
                 'view_type': 'form',
70
 
                 'context': "{'mass_editing_object' : %d}" % (data.id),
71
 
                 'view_mode':'form,tree',
72
 
                 'target': 'new',
73
 
                 'auto_refresh':1
74
 
            }, context)
75
 
            vals['ref_ir_value'] = self.pool.get('ir.values').create(cr, uid, {
76
 
                 'name': button_name,
77
 
                 'model': src_obj,
78
 
                 'key2': 'client_action_multi',
79
 
                 'value': "ir.actions.act_window," + str(vals['ref_ir_act_window']),
80
 
                 'object': True,
81
 
             }, context)
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),
85
 
                }, context)
86
 
        return True
87
 
 
88
 
    def unlink_action(self, cr, uid, ids, context=None):
89
 
        for template in self.browse(cr, uid, ids, context=context):
90
 
            try:
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)
96
 
            except:
97
 
                raise osv.except_osv(_("Warning"), _("Deletion of the action record failed."))
98
 
        return True
99
 
 
100
 
mass_object()
101
 
 
102
 
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: