~unifield-team/unifield-wm/us-671-homere

« back to all changes in this revision

Viewing changes to unifield_setup/installer/vat_setup.py

  • Committer: jf
  • Date: 2012-04-17 15:29:16 UTC
  • mfrom: (631.3.7 UF_828)
  • Revision ID: jf@tempo4-20120417152916-svm6ioq8ur2bi5tu
UF-955 [DEV] Reporting (Month-end) - 2 remaining reports
lp:~unifield-team/unifield-wm/UF_955

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) 2011 TeMPO Consulting, MSF
6
 
#
7
 
#    This program is free software: you can redistribute it and/or modify
8
 
#    it under the terms of the GNU Affero General Public License as
9
 
#    published by the Free Software Foundation, either version 3 of the
10
 
#    License, or (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 Affero General Public License for more details.
16
 
#
17
 
#    You should have received a copy of the GNU Affero General Public License
18
 
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 
#
20
 
##############################################################################
21
 
 
22
 
from osv import osv
23
 
from osv import fields
24
 
 
25
 
from tools.translate import _
26
 
 
27
 
 
28
 
class vat_setup(osv.osv_memory):
29
 
    _name = 'vat.setup'
30
 
    _inherit = 'res.config'
31
 
 
32
 
    _columns = {
33
 
        'vat_ok': fields.boolean(string='Do you manage VAT locally ?'),
34
 
    }
35
 
 
36
 
    def default_get(self, cr, uid, fields, context=None):
37
 
        '''
38
 
        Display the default value for delivery process
39
 
        '''
40
 
        setup_id = self.pool.get('unifield.setup.configuration').get_config(cr, uid)
41
 
        res = super(vat_setup, self).default_get(cr, uid, fields, context=context)
42
 
        res['vat_ok'] = setup_id.vat_ok
43
 
 
44
 
        return res
45
 
 
46
 
 
47
 
    def execute(self, cr, uid, ids, context=None):
48
 
        '''
49
 
        Fill the vats_ok field and active/de-activate menu entries
50
 
        '''
51
 
        assert len(ids) == 1, "We should only get one object from the form"
52
 
        payload = self.browse(cr, uid, ids[0], context=context)
53
 
 
54
 
        setup_obj = self.pool.get('unifield.setup.configuration')
55
 
        data_obj = self.pool.get('ir.model.data')
56
 
 
57
 
        setup_id = setup_obj.get_config(cr, uid)
58
 
 
59
 
        # Get all menu ids concerned by this modification
60
 
        taxes_menu_id = data_obj.get_object_reference(cr, uid, 'account', 'next_id_27')[1]
61
 
 
62
 
        menu_ids = [taxes_menu_id]
63
 
 
64
 
        if payload.vat_ok:
65
 
            # If the feature is not activate, inactive the menu entries
66
 
            self.pool.get('ir.ui.menu').write(cr, uid, menu_ids, {'active': True}, context=context)
67
 
        else:
68
 
            self.pool.get('ir.ui.menu').write(cr, uid, menu_ids, {'active': False}, context=context)
69
 
 
70
 
        setup_obj.write(cr, uid, [setup_id.id], {'vat_ok': payload.vat_ok}, context=context)
71
 
 
72
 
 
73
 
vat_setup()