~unifield-team/unifield-wm/us-826

« back to all changes in this revision

Viewing changes to res_currency_tables/res_currency_table.py

UF-663: [IMP] first version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2011 MSF, TeMPO consulting
 
6
#
 
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.
 
11
#
 
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.
 
16
#
 
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/>.
 
19
#
 
20
##############################################################################
 
21
 
 
22
import datetime
 
23
from osv import fields, osv
 
24
 
 
25
class res_currency_table(osv.osv):
 
26
    _name = 'res.currency.table'
 
27
 
 
28
    _columns = {
 
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'),
 
32
    }
 
33
    
 
34
    def create(self, cr, uid, vals, context=None):
 
35
        if not context:
 
36
            context = {}
 
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,
 
52
                             'active': False
 
53
                            }
 
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
 
57
                # create default rate
 
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'),
 
60
                                                                    'rate': 1,
 
61
                                                                    'currency_id': currency_id}, context=context)
 
62
                # Activate currency
 
63
                currency_obj.write(cr, uid, [currency_id], {'active': True}, context=context)
 
64
        return table_id
 
65
    
 
66
res_currency_table()
 
67
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
68
    
 
 
b'\\ No newline at end of file'