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
##############################################################################
25
from osv import fields
26
from tools.misc import ustr
28
class res_currency_rate(osv.osv):
29
_name = 'res.currency.rate'
30
_inherit = 'res.currency.rate'
33
('rate_unique', 'unique(name, currency_id)', "Only one rate per date is accorded."),
38
class res_currency(osv.osv):
39
_name = 'res.currency'
40
_inherit = 'res.currency'
42
def _check_unicity_currency_name(self, cr, uid, ids, context=None):
44
Check that no currency have the same name and the same currency_table_id.
45
Check is non case-sensitive.
49
for c in self.browse(cr, uid, ids):
50
if not c.currency_name:
52
sql = """SELECT id, name
54
WHERE currency_name ilike %s"""
55
if c.currency_table_id:
56
sql += """\nAND currency_table_id in %s"""
57
cr.execute(sql, (c.currency_name, tuple([c.currency_table_id.id])))
59
sql += """\nAND currency_table_id is Null"""
60
cr.execute(sql, (c.currency_name,))
61
bad_ids = cr.fetchall()
62
if bad_ids and len(bad_ids) > 1:
66
def _check_unicity_name(self, cr, uid, ids, context=None):
68
Check that no currency is the same and have the same currency_table_id.
69
Check is non case-sensitive.
73
for c in self.browse(cr, uid, ids):
76
sql = """SELECT id, name
78
WHERE name ilike %s"""
79
if c.currency_table_id:
80
sql += """\nAND currency_table_id in %s"""
81
cr.execute(sql, (c.name, tuple([c.currency_table_id.id])))
83
sql += """\nAND currency_table_id is Null"""
84
cr.execute(sql, (c.name,))
85
bad_ids = cr.fetchall()
86
if bad_ids and len(bad_ids) > 1:
91
(_check_unicity_currency_name, "Another currency have the same name.", ['currency_name']),
92
(_check_unicity_name, "Same currency exists", ['name']),
96
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: