[FIX] error reporting in _.sprintf
[odoo/odoo.git] / addons / purchase_double_validation / purchase_double_validation_installer.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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 fields, osv
23
24 class purchase_double_validation_installer(osv.osv_memory):
25     _name = 'purchase.double.validation.installer'
26     _inherit = 'res.config'
27     _columns = {
28         'limit_amount': fields.integer('Maximum Purchase Amount', required=True, help="Maximum amount after which validation of purchase is required."),
29     }
30
31     _defaults = {
32         'limit_amount': 5000,
33     }
34
35     def execute(self, cr, uid, ids, context=None):
36         data = self.read(cr, uid, ids, context=context)
37         if not data:
38             return {}
39         amt = data[0]['limit_amount']
40         data_pool = self.pool.get('ir.model.data')
41         transition_obj = self.pool.get('workflow.transition')
42         waiting = data_pool._get_id(cr, uid, 'purchase', 'trans_confirmed_router')
43         waiting_id = data_pool.browse(cr, uid, waiting, context=context).res_id
44         confirm = data_pool._get_id(cr, uid, 'purchase_double_validation', 'trans_waiting_confirmed')
45         confirm_id = data_pool.browse(cr, uid, confirm, context=context).res_id
46         transition_obj.write(cr, uid, waiting_id, {'condition': 'amount_total>=%s' % (amt)})
47         transition_obj.write(cr, uid, confirm_id, {'condition': 'amount_total<%s' % (amt)})
48         return {}
49
50 purchase_double_validation_installer()
51
52
53
54 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
55