~unifield-team/unifield-wm/us-826

« back to all changes in this revision

Viewing changes to msf_button_access_rights/wizards/view_config.py

  • Committer: mmu-openerp
  • Date: 2013-03-13 11:05:40 UTC
  • mfrom: (1349.29.95 button-wm)
  • mto: This revision was merged to the branch mainline in revision 1524.
  • Revision ID: mmu@openerp.com-20130313110540-gk589kzzzkw5ojro
[MERGE] uf-1652 button access rights

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# -*- encoding: utf-8 -*-
 
3
##############################################################################
 
4
#
 
5
#    OpenERP, Open Source Management Solution
 
6
#    Copyright (C) 2011 TeMPO Consulting, MSF. All Rights Reserved
 
7
#    Developer: Max Mumford
 
8
#
 
9
#    This program is free software: you can redistribute it and/or modify
 
10
#    it under the terms of the GNU Affero General Public License as
 
11
#    published by the Free Software Foundation, either version 3 of the
 
12
#    License, or (at your option) any later version.
 
13
#
 
14
#    This program is distributed in the hope that it will be useful,
 
15
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
#    GNU Affero General Public License for more details.
 
18
#
 
19
#    You should have received a copy of the GNU Affero General Public License
 
20
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
21
#
 
22
##############################################################################
 
23
 
 
24
from osv import osv
 
25
from osv import fields
 
26
 
 
27
def _join_dictionary(dict, key_prefix, value_prefix, seperator):
 
28
    s = ''
 
29
    if dict:
 
30
        for k, v in dict.items():
 
31
            s += key_prefix + str(k) + value_prefix + str(v) + seperator
 
32
    return s
 
33
 
 
34
class view_config_install(osv.osv_memory):
 
35
    _name = 'msf_button_access_rights.view_config_wizard_install'
 
36
    _inherit = 'res.config' 
 
37
    
 
38
    def execute(self, cr, uid, ids, context=None):
 
39
        """
 
40
        Perform a write (With no updated values) on each view in the database to trigger the Button Access Rule create / update process. Keep a log of all errors and return a new wizard showing the results.
 
41
        """
 
42
        context = context or {}
 
43
        
 
44
        view_pool = self.pool.get('ir.ui.view')
 
45
        view_ids = view_pool.search(cr, uid, [])
 
46
        errors = {}
 
47
        for id in view_ids:
 
48
            try:
 
49
                view_pool.write(cr, uid, id, {})
 
50
            except Exception as e:
 
51
                errors[id] = e
 
52
                
 
53
        all = self.pool.get('msf_button_access_rights.button_access_rule').search(cr, 1, [])
 
54
        
 
55
        results = {
 
56
           'successes': str(len(view_ids) - len(errors)) + ' Views were processed successfully',
 
57
           'total': 'You now have ' + str(len(all)) + ' Button Access Rules in total',
 
58
           'errors': str(len(errors)) + ' error(s) occurred while processing the Views\n\n' + _join_dictionary(errors, 'View ID: ', ', Error: ', '\n')
 
59
        }
 
60
        
 
61
        results_id = self.pool.get('msf_button_access_rights.view_config_wizard_install_results').create(cr, 1, results, context=context)
 
62
        return {
 
63
            'name': 'Generation Results',
 
64
            'view_type': 'form',
 
65
            'view_mode': 'form',
 
66
            'res_model': 'msf_button_access_rights.view_config_wizard_install_results',
 
67
            'res_id' : results_id,
 
68
            'type': 'ir.actions.act_window',
 
69
            'context' : context,
 
70
            'target' : 'new',
 
71
        }
 
72
 
 
73
view_config_install()
 
74
        
 
75
class view_config_install_results(osv.osv_memory):
 
76
    _name = 'msf_button_access_rights.view_config_wizard_install_results'
 
77
    _columns = {
 
78
        'successes': fields.text('Successes', readonly=True),
 
79
        'total': fields.text('Total', readonly=True),
 
80
        'errors': fields.text('Errors', readonly=True),
 
81
    }
 
82
        
 
83
view_config_install_results()
 
 
b'\\ No newline at end of file'