~openerp-commiter/openobject-addons/trunk-extra-addons

« back to all changes in this revision

Viewing changes to currency_rate_date_check/company.py

  • Committer: Alexis de Lattre
  • Date: 2012-03-28 09:49:50 UTC
  • Revision ID: alexis@via.ecp.fr-20120328094950-7r54ggyb5xj8nwhs
Add currency_rate_date_check module. Refer to __openerp__.py for a description.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    Currency rate date check module for OpenERP
 
5
#    Copyright (C) 2012 Akretion (http://www.akretion.com). All Rights Reserved
 
6
#    @author Alexis de Lattre <alexis.delattre@akretion.com>
 
7
#
 
8
#    This program is free software: you can redistribute it and/or modify
 
9
#    it under the terms of the GNU Affero General Public License as
 
10
#    published by the Free Software Foundation, either version 3 of the
 
11
#    License, or (at your option) any later version.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU Affero General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU Affero General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
##############################################################################
 
22
 
 
23
from osv import osv, fields
 
24
 
 
25
class res_company(osv.osv):
 
26
    _inherit = 'res.company'
 
27
 
 
28
    _columns = {
 
29
        'currency_rate_max_delta': fields.integer('Max time delta in days for currency rates', help="This is the maximum interval in days between the date associated with the amount to convert and the currency rate available in OpenERP with the nearest date."),
 
30
    }
 
31
 
 
32
    _defaults = {
 
33
        'currency_rate_max_delta': lambda *a: 7,
 
34
    }
 
35
 
 
36
    def _check_currency_rate_max_delta(self, cr, uid, ids):
 
37
        for company in self.read(cr, uid, ids, ['currency_rate_max_delta']):
 
38
            if company['currency_rate_max_delta'] >= 0:
 
39
                continue
 
40
            else:
 
41
                return False
 
42
        return True
 
43
 
 
44
    _constraints = [
 
45
        (_check_currency_rate_max_delta, "The value must be positive", ['currency_rate_max_delta']),
 
46
    ]
 
47
 
 
48
res_company()