1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2011 MSF, TeMPO consulting
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.
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.
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/>.
20
##############################################################################
23
from osv import fields, osv
25
class res_currency_table(osv.osv):
26
_name = 'res.currency.table'
29
'name': fields.char('Currency table name', size=64, required=True),
30
'code': fields.char('Currency table code', size=16, required=True),
31
'currency_ids': fields.one2many('res.currency', 'currency_table_id', 'Currencies'),
34
def create(self, cr, uid, vals, context=None):
37
table_id = super(res_currency_table, self).create(cr, uid, vals, context=context)
38
# Duplicate main currency list
39
currency_obj = self.pool.get('res.currency')
40
main_currency_ids = currency_obj.search(cr, uid, [('currency_table_id', '=', False)], context={'active_test': False})
41
for currency in currency_obj.browse(cr, uid, main_currency_ids, context=context):
42
currency_vals = {'name': currency.name,
43
'currency_name': currency.currency_name,
44
'symbol': currency.symbol,
45
'accuracy': currency.accuracy,
46
'rounding': currency.rounding,
47
'company_id': currency.company_id.id,
48
'date': currency.date,
49
'base': currency.base,
50
'currency_table_id': table_id,
51
'reference_currency_id': currency.id,
54
currency_id = currency_obj.create(cr, uid, currency_vals, context=context)
55
if currency.name in ['EUR', 'CHF']:
56
# EUR and CHF are default ones
58
date_rate = datetime.date(datetime.date.today().year, 1, 1)
59
self.pool.get('res.currency.rate').create(cr, uid, {'name': date_rate.strftime('%Y-%m-%d'),
61
'currency_id': currency_id}, context=context)
63
currency_obj.write(cr, uid, [currency_id], {'active': True}, context=context)
67
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
b'\\ No newline at end of file'