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

« back to all changes in this revision

Viewing changes to unifield_setup/installer/project_leadtime.py

UF-359 [ADD] Account override module integration

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
 
class project_leadtime_setup(osv.osv_memory):
28
 
    _name = 'project.leadtime.setup'
29
 
    _inherit = 'res.config'
30
 
    
31
 
    _columns = {
32
 
        'preparation_leadtime': fields.integer(string='Preparation lead time', help='In days'),
33
 
        'shipment_leadtime': fields.integer(string='Shipment lead time', help='In days.'),
34
 
    }
35
 
    
36
 
    def default_get(self, cr, uid, fields, context=None):
37
 
        '''
38
 
        Load data in company
39
 
        '''
40
 
        res = super(project_leadtime_setup, self).default_get(cr, uid, fields, context=context)
41
 
        company = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id
42
 
        res.update({'preparation_leadtime': company.preparation_lead_time,
43
 
                    'shipment_leadtime': company.shipment_lead_time})
44
 
        
45
 
        return res
46
 
    
47
 
    def onchange_leadtime(self, cr, uid, ids, leadtime, field='preparation_leadtime', context=None):
48
 
        '''
49
 
        Check the value of the leadtime and display warning message if
50
 
        the value is not between 0 and 9
51
 
        '''
52
 
        v = {}
53
 
        m = {}
54
 
        
55
 
        if leadtime and leadtime < 0:
56
 
            v.update({field: 0})
57
 
            m.update({'title': _('Error'),
58
 
                      'message': _('You cannot have a negative lead time !')})
59
 
        elif leadtime and leadtime > 9:
60
 
            v.update({field: 9})
61
 
            m.update({'title': _('Error'),
62
 
                      'message': _('You cannot have a lead time greater than 9 !')})
63
 
            
64
 
        return {'value': v, 'warning': m}
65
 
    
66
 
    def execute(self, cr, uid, ids, context=None):
67
 
        '''
68
 
        Fill the lead times in the company
69
 
        '''
70
 
        assert len(ids) == 1, "We should only get one object from the form"
71
 
        payload = self.browse(cr, uid, ids[0], context=context)
72
 
        company = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id
73
 
        
74
 
        self.pool.get('res.company').write(cr, 1, company.id, {'preparation_lead_time': payload.preparation_leadtime,
75
 
                                                                 'shipment_lead_time': payload.shipment_leadtime}, context=context)
76
 
    
77
 
project_leadtime_setup()