2
#-*- encoding:utf-8 -*-
3
##############################################################################
5
# OpenERP, Open Source Management Solution
6
# Copyright (C) 2011 TeMPO Consulting, MSF. All Rights Reserved
8
# Developer: Olivier DOSSMANN
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.
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.
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/>.
23
##############################################################################
26
class res_currency_rate(osv.osv):
27
_name = 'res.currency.rate'
28
_inherit = 'res.currency.rate'
31
('rate_unique', 'unique(name, currency_id)', "Only one rate per date is accorded."),
36
class res_currency(osv.osv):
37
_name = 'res.currency'
38
_inherit = 'res.currency'
40
def _check_unicity_currency_name(self, cr, uid, ids, context=None):
42
Check that no currency have the same name and the same currency_table_id.
43
Check is non case-sensitive.
47
for c in self.browse(cr, uid, ids):
48
if not c.currency_name:
50
sql = """SELECT id, name
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])))
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:
64
def _check_unicity_name(self, cr, uid, ids, context=None):
66
Check that no currency is the same and have the same currency_table_id.
67
Check is non case-sensitive.
71
for c in self.browse(cr, uid, ids):
74
sql = """SELECT id, name
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])))
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:
89
(_check_unicity_currency_name, "Another currency have the same name.", ['currency_name']),
90
(_check_unicity_name, "Same currency exists", ['name']),
94
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: