diff --git a/__init__.py b/__init__.py index e22016b060..2c3c7fc814 100644 --- a/__init__.py +++ b/__init__.py @@ -24,7 +24,6 @@ # ############################################################################## -from currency import * from account import * from fiscalyear import * from period import * diff --git a/__tryton__.py b/__tryton__.py index ca6ab7fed5..017def2960 100644 --- a/__tryton__.py +++ b/__tryton__.py @@ -11,10 +11,10 @@ 'res', 'company', 'partner', + 'currency', ], 'xml': [ 'account.xml', - 'currency.xml', 'fiscalyear.xml', 'period.xml', 'journal.xml', diff --git a/account.py b/account.py index ceba6db73c..3dd1344745 100644 --- a/account.py +++ b/account.py @@ -53,7 +53,7 @@ class Type(OSV): def get_amount(self, cursor, user, ids, name, arg, context=None): company_obj = self.pool.get('company.company') account_obj = self.pool.get('account.account') - currency_obj = self.pool.get('account.currency') + currency_obj = self.pool.get('currency.currency') if context is None: context = {} @@ -175,8 +175,8 @@ class Account(OSV): active = fields.Boolean('Active', select=2) company = fields.Many2One('company.company', 'Company', required=True) currency = fields.Function('get_currency', type='many2one', - relation='account.currency', string='Currency') - second_currency = fields.Many2One('account.currency', 'Secondary currency', + relation='currency.currency', string='Currency') + second_currency = fields.Many2One('currency.currency', 'Secondary currency', help='Force all moves for this account \n' \ 'to have this secondary currency.') type = fields.Many2One('account.account.type', 'Type', required=True, @@ -255,7 +255,7 @@ class Account(OSV): return True def get_currency(self, cursor, user, ids, name, arg, context=None): - currency_obj = self.pool.get('account.currency') + currency_obj = self.pool.get('currency.currency') res = {} for account in self.browse(cursor,user, ids, context=context): res[account.id] = account.company.currency.id @@ -274,7 +274,7 @@ class Account(OSV): def get_balance(self, cursor, user, ids, name, arg, context=None): res = {} company_obj = self.pool.get('company.company') - currency_obj = self.pool.get('account.currency') + currency_obj = self.pool.get('currency.currency') move_line_obj = self.pool.get('account.move.line') child_ids = self.search(cursor, user, [('parents', 'child_of', ids)], @@ -326,7 +326,7 @@ class Account(OSV): res = {} move_line_obj = self.pool.get('account.move.line') company_obj = self.pool.get('company.company') - currency_obj = self.pool.get('account.currency') + currency_obj = self.pool.get('currency.currency') if name not in ('credit', 'debit'): raise Exception('Bad argument') diff --git a/currency.py b/currency.py deleted file mode 100644 index 98397c7a42..0000000000 --- a/currency.py +++ /dev/null @@ -1,148 +0,0 @@ -"Currency" - -from trytond.osv import fields, OSV, ExceptOSV -import time -from decimal import Decimal -import datetime - - -class Currency(OSV): - 'Currency' - _name = 'account.currency' - _description = __doc__ - name = fields.Char('Name', size=128, required=True, translate=True) - code = fields.Char('Code', size=3, required=True) - rate = fields.Function('get_rate', string='Current rate', digits=(12, 6)) - rates = fields.One2Many('account.currency.rate', 'currency', 'Rates') - rounding = fields.Numeric('Rounding factor', digits=(12, 6)) - digits = fields.Integer('Diplay Digits') - active = fields.Boolean('Active') - - def __init__(self): - super(Currency, self).__init__() - self._order.insert(0, ('code', 'ASC')) - - def default_active(self, cursor, user, context=None): - return True - - def default_rounding(self, cursor, user, context=None): - return 0.01 - - def default_digits(self, cursor, user, context=None): - return 2 - - def name_search(self, cursor, user, name, args=None, operator='ilike', - context=None, limit=None): - if args is None: - args = [] - args_name = args[:] - args_code = args[:] - if name: - args_name += [(self._rec_name, operator, name)] - args_code += [('code', operator, name)] - ids = self.search(cursor, user, args_code, limit=limit, context=context) - if len(ids) != 1: - ids += self.search(cursor, user, args_name, limit=limit, - context=context) - res = self.name_get(cursor, user, ids, context=context) - return res - - def get_rate(self, cursor, user, ids, name, arg, context=None): - ''' - Return the rate at the date from the context or the current date - ''' - res = {} - rate_obj = self.pool.get('account.currency.rate') - if context is None: - context = {} - date = context.get('date', time.strftime('%Y-%m-%d')) - for currency_id in ids: - rate_ids = rate_obj.search(cursor, user, [ - ('currency', '=', currency_id), - ('date', '<=', date), - ], limit=1, order=[('date', 'DESC')]) - if rate_ids: - res[currency_id] = rate_ids[0] - else: - res[currency_id] = 0.0 - rate_ids = [x for x in res.values() if x] - rates = rate_obj.browse(cursor, user, rate_ids, context=context) - id2rate = {} - for rate in rates: - id2rate[rate.id] = rate - for currency_id in res.keys(): - if res[currency_id]: - res[currency_id] = id2rate[res[currency_id]].rate - return res - - def round(self, cursor, user, currency, amount): - 'Round the amount depending of the currency' - return (amount / currency.rounding).quantize(Decimal('1.')) * currency.rounding - - def is_zero(self, cursor, user, currency, amount): - 'Return True if the amount can be considered as zero for the currency' - return abs(self.round(cursor, user, currency, amount)) < currency.rounding - - def compute(self, cursor, user, from_currency, amount, to_currency, - round=True, context=None): - ''' - Take a currency and an amount - Return the amount to the new currency - Use the rate of the date of the context or the current date - ''' - if isinstance(from_currency, (int, long)): - from_currency = self.browse(cursor, user, from_currency, context=context) - if isinstance(to_currency, (int, long)): - to_currency = self.browse(cursor, user, to_currency, context=context) - if (not from_currency.rate) or (not to_currency.rate): - date = context.get('date', time.strftime('%Y-%m-%d')) - if not from_currency.rate: - name = from_currency.name - else: - name = to_currency.name - raise ExceptOSV('UserError', 'No rate found \n' \ - 'for the currency: %s \n' \ - 'at the date: %s' % (name, date)) - if to_currency == from_currency: - if round: - return self.round(cursor, user, to_currency, amount) - else: - return amount - else: - if round: - return self.round(cursor, user, to_currency, - amount * to_currency.rate / from_currency.rate) - else: - return amount * to_currency.rate / from_currency.rate - -Currency() - - -class Rate(OSV): - 'Rate' - _name = 'account.currency.rate' - _description = __doc__ - _rec_name = 'date' - date = fields.Date('Date', required=True, select=1) - rate = fields.Numeric('Rate', digits=(12, 6), required=1) - currency = fields.Many2One('account.currency', 'Currency') - - def __init__(self): - super(Rate, self).__init__() - self._sql_constraints = [ - ('date_currency_uniq', 'UNIQUE(date, currency)', - 'A currency can only have one rate by date!'), - ] - self._order.insert(0, ('date', 'DESC')) - - def default_date(self, cursor, user, context=None): - return datetime.date.today() - -Rate() - - -class Company(OSV): - _name = 'company.company' - currency = fields.Many2One('account.currency', 'Currency', required=True) - -Company() diff --git a/currency.xml b/currency.xml deleted file mode 100644 index 314e41efb1..0000000000 --- a/currency.xml +++ /dev/null @@ -1,163 +0,0 @@ - - - - - account.currency - form - - - - - account.currency - tree - - - - - - - - ]]> - - - - Currencies - account.currency - form - - - - - - - - - - - - - - - - - - - - - - - - - - - - - company.company - - - - - - - ]]> - - - - company.company - - - - - - - - ]]> - - - - - - - - - - - - - - - - - - - Euro - EUR - - - - - - - - - - United States dollar - USD - - - - - Swiss franc - CHF - - - - - diff --git a/fiscalyear.py b/fiscalyear.py index ee2f929f7b..4812e14130 100644 --- a/fiscalyear.py +++ b/fiscalyear.py @@ -210,7 +210,7 @@ class CloseFiscalYear(Wizard): ''' Method to override to implement new close method ''' - currency_obj = self.pool.get('account.currency') + currency_obj = self.pool.get('currency.currency') move_line_obj = self.pool.get('account.move.line') fiscalyear_obj = self.pool.get('account.fiscalyear') diff --git a/move.py b/move.py index c78d627102..6daa8b83ea 100644 --- a/move.py +++ b/move.py @@ -169,7 +169,7 @@ class Move(OSV): ''' Validate balanced move and centralise it if in centralised journal ''' - currency_obj = self.pool.get('account.currency') + currency_obj = self.pool.get('currency.currency') move_line_obj = self.pool.get('account.move.line') if isinstance(ids, (int, long)): ids = [ids] @@ -219,7 +219,7 @@ class Move(OSV): return def post(self, cursor, user, ids, context=None): - currency_obj = self.pool.get('account.currency') + currency_obj = self.pool.get('currency.currency') sequence_obj = self.pool.get('ir.sequence') if isinstance(ids, (int, long)): @@ -301,7 +301,7 @@ class Reconciliation(OSV): raise ExceptORM('UserError', 'You can not modify a reconciliation!') def check_lines(self, cursor, user, ids): - currency_obj = self.pool.get('account.currency') + currency_obj = self.pool.get('currency.currency') for reconciliation in self.browse(cursor, user, ids): amount = Decimal('0.0') account = None @@ -354,7 +354,7 @@ class Line(OSV): reference = fields.char('Reference', size=None) amount_second_currency = fields.Numeric('Amount Second Currency', digits=(16, 2), help='The amount expressed in a second currency') - second_currency = fields.Many2One('account.currency', 'Second Currency', + second_currency = fields.Many2One('currency.currency', 'Second Currency', help='The second currency') partner = fields.Many2One('partner.partner', 'Partner', on_change=['move', 'partner', 'account', 'debit', 'credit', @@ -665,7 +665,7 @@ class Line(OSV): partner_obj = self.pool.get('partner.partner') journal_obj = self.pool.get('account.journal') account_obj = self.pool.get('account.account') - currency_obj = self.pool.get('account.currency') + currency_obj = self.pool.get('currency.currency') res = {} if (not vals.get('partner')) or vals.get('account'): return res @@ -1072,7 +1072,7 @@ class Line(OSV): def reconcile(self, cursor, user, ids, journal_id=False, date=False, account_id=False, context=None): move_obj = self.pool.get('account.move') - currency_obj = self.pool.get('account.currency') + currency_obj = self.pool.get('currency.currency') reconciliation_obj = self.pool.get('account.move.reconciliation') period_obj = self.pool.get('account.period') @@ -1335,7 +1335,7 @@ class ReconcileLines(Wizard): def _check_writeoff(self, cursor, user, data, context=None): line_obj = self.pool.get('account.move.line') - currency_obj = self.pool.get('account.currency') + currency_obj = self.pool.get('currency.currency') company = None amount = Decimal('0.0') diff --git a/tax.py b/tax.py index c94770ab0d..342ca24da7 100644 --- a/tax.py +++ b/tax.py @@ -56,7 +56,7 @@ class Code(OSV): def get_sum(self, cursor, user, ids, name, arg, context=None): res = {} move_line_obj = self.pool.get('account.move.line') - currency_obj = self.pool.get('account.currency') + currency_obj = self.pool.get('currency.currency') child_ids = self.search(cursor, user, [('parent', 'child_of', ids)], context=context)