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

« back to all changes in this revision

Viewing changes to account_override/res_currency.py

[UF-43] fix added noupdate to demo data

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
#-*- encoding:utf-8 -*-
3
 
##############################################################################
4
 
#
5
 
#    OpenERP, Open Source Management Solution
6
 
#    Copyright (C) 2011 TeMPO Consulting, MSF. All Rights Reserved
7
 
#    All Rigts Reserved
8
 
#    Developer: Olivier DOSSMANN
9
 
#
10
 
#    This program is free software: you can redistribute it and/or modify
11
 
#    it under the terms of the GNU Affero General Public License as
12
 
#    published by the Free Software Foundation, either version 3 of the
13
 
#    License, or (at your option) any later version.
14
 
#
15
 
#    This program is distributed in the hope that it will be useful,
16
 
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 
#    GNU Affero General Public License for more details.
19
 
#
20
 
#    You should have received a copy of the GNU Affero General Public License
21
 
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 
#
23
 
##############################################################################
24
 
from osv import osv
25
 
 
26
 
class res_currency_rate(osv.osv):
27
 
    _name = 'res.currency.rate'
28
 
    _inherit = 'res.currency.rate'
29
 
 
30
 
    _sql_constraints = [
31
 
        ('rate_unique', 'unique(name, currency_id)', "Only one rate per date is accorded."),
32
 
    ]
33
 
 
34
 
res_currency_rate()
35
 
 
36
 
class res_currency(osv.osv):
37
 
    _name = 'res.currency'
38
 
    _inherit = 'res.currency'
39
 
 
40
 
    def _check_unicity_currency_name(self, cr, uid, ids, context=None):
41
 
        """
42
 
        Check that no currency have the same name and the same currency_table_id.
43
 
        Check is non case-sensitive.
44
 
        """
45
 
        if not context:
46
 
            context = {}
47
 
        for c in self.browse(cr, uid, ids):
48
 
            if not c.currency_name:
49
 
                continue
50
 
            sql = """SELECT id, name
51
 
            FROM res_currency
52
 
            WHERE currency_name ilike %s"""
53
 
            if c.currency_table_id:
54
 
                sql += """\nAND currency_table_id in %s"""
55
 
                cr.execute(sql, (c.currency_name, tuple([c.currency_table_id.id])))
56
 
            else:
57
 
                sql += """\nAND currency_table_id is Null"""
58
 
                cr.execute(sql, (c.currency_name,))
59
 
            bad_ids = cr.fetchall()
60
 
            if bad_ids and len(bad_ids) > 1:
61
 
                return False
62
 
        return True
63
 
 
64
 
    def _check_unicity_name(self, cr, uid, ids, context=None):
65
 
        """
66
 
        Check that no currency is the same and have the same currency_table_id.
67
 
        Check is non case-sensitive.
68
 
        """
69
 
        if not context:
70
 
            context = {}
71
 
        for c in self.browse(cr, uid, ids):
72
 
            if not c.name:
73
 
                continue
74
 
            sql = """SELECT id, name
75
 
            FROM res_currency
76
 
            WHERE name ilike %s"""
77
 
            if c.currency_table_id:
78
 
                sql += """\nAND currency_table_id in %s"""
79
 
                cr.execute(sql, (c.name, tuple([c.currency_table_id.id])))
80
 
            else:
81
 
                sql += """\nAND currency_table_id is Null"""
82
 
                cr.execute(sql, (c.name,))
83
 
            bad_ids = cr.fetchall()
84
 
            if bad_ids and len(bad_ids) > 1:
85
 
                return False
86
 
        return True
87
 
 
88
 
    _constraints = [
89
 
        (_check_unicity_currency_name, "Another currency have the same name.", ['currency_name']),
90
 
        (_check_unicity_name, "Same currency exists", ['name']),
91
 
    ]
92
 
 
93
 
res_currency()
94
 
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: