1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2011 TeMPO Consulting, MSF
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.
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.
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/>.
20
##############################################################################
23
from osv import fields
25
from tools.translate import _
27
class project_leadtime_setup(osv.osv_memory):
28
_name = 'project.leadtime.setup'
29
_inherit = 'res.config'
32
'preparation_leadtime': fields.integer(string='Preparation lead time', help='In days'),
33
'shipment_leadtime': fields.integer(string='Shipment lead time', help='In days.'),
36
def default_get(self, cr, uid, fields, context=None):
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})
47
def onchange_leadtime(self, cr, uid, ids, leadtime, field='preparation_leadtime', context=None):
49
Check the value of the leadtime and display warning message if
50
the value is not between 0 and 9
55
if leadtime and leadtime < 0:
57
m.update({'title': _('Error'),
58
'message': _('You cannot have a negative lead time !')})
59
elif leadtime and leadtime > 9:
61
m.update({'title': _('Error'),
62
'message': _('You cannot have a lead time greater than 9 !')})
64
return {'value': v, 'warning': m}
66
def execute(self, cr, uid, ids, context=None):
68
Fill the lead times in the company
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
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)
77
project_leadtime_setup()