diff --git a/account.py b/account.py
index 24ded0dc31..470c389b2b 100644
--- a/account.py
+++ b/account.py
@@ -23,8 +23,10 @@ class Type(OSV):
childs = fields.One2Many('account.account.type', 'parent', 'Childs')
sequence = fields.Integer('Sequence', required=True,
help='Use to order the account type')
- #TODO fix digits depend of the currency
- amount = fields.Function('get_amount', digits=(16, 2), string='Amount')
+ currency_digits = fields.Function('get_currency_digits', type='integer',
+ string='Currency Digits')
+ amount = fields.Function('get_amount', digits="(16, currency_digits)",
+ string='Amount')
balance_sheet = fields.Boolean('Balance Sheet', states={
'invisible': "parent",
})
@@ -49,6 +51,21 @@ class Type(OSV):
def default_display_balance(self, cursor, user, context=None):
return 'debit-credit'
+ def get_currency_digits(self, cursor, user, ids, name, arg, context=None):
+ company_obj = self.pool.get('company.company')
+ if context is None:
+ context = {}
+ res = {}
+ if not context.get('company'):
+ for type_id in ids:
+ res[type_id] = 2
+ return res
+ company = company_obj.browse(cursor, user, context['company'],
+ context=context)
+ for type_id in ids:
+ res[type_id] = company.currency.digits
+ return res
+
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')
@@ -274,6 +291,8 @@ class Account(OSV):
company = fields.Many2One('company.company', 'Company', required=True)
currency = fields.Function('get_currency', type='many2one',
relation='currency.currency', string='Currency')
+ currency_digits = fields.Function('get_currency_digits', type='integer',
+ string='Currency Digits')
second_currency = fields.Many2One('currency.currency', 'Secondary currency',
help='Force all moves for this account \n' \
'to have this secondary currency.')
@@ -287,10 +306,12 @@ class Account(OSV):
left = fields.Integer('Left', required=True)
right = fields.Integer('Right', required=True)
childs = fields.One2Many('account.account', 'parent', 'Childs')
- #TODO fix digits depend of the currency
- balance = fields.Function('get_balance', digits=(16, 2), string='Balance')
- credit = fields.Function('get_credit_debit', digits=(16, 2), string='Credit')
- debit = fields.Function('get_credit_debit', digits=(16, 2), string='Debit')
+ balance = fields.Function('get_balance', digits="(16, currency_digits)",
+ string='Balance')
+ credit = fields.Function('get_credit_debit', digits="(16, currency_digits)",
+ string='Credit')
+ debit = fields.Function('get_credit_debit', digits="(16, currency_digits)",
+ string='Debit')
reconcile = fields.Boolean('Reconcile',
help='Check if the account can be used \n' \
'for reconciliation.',
@@ -360,7 +381,7 @@ class Account(OSV):
def get_currency(self, cursor, user, ids, name, arg, context=None):
currency_obj = self.pool.get('currency.currency')
res = {}
- for account in self.browse(cursor,user, ids, context=context):
+ for account in self.browse(cursor, user, ids, context=context):
res[account.id] = account.company.currency.id
currency_names = {}
for currency_id, currency_name in currency_obj.name_get(cursor, user,
@@ -374,6 +395,12 @@ class Account(OSV):
res[i] = False
return res
+ def get_currency_digits(self, cursor, user, ids, name, arg, context=None):
+ res = {}
+ for account in self.browse(cursor, user, ids, context=context):
+ res[account.id] = account.company.currency.digits
+ return res
+
def get_balance(self, cursor, user, ids, name, arg, context=None):
res = {}
company_obj = self.pool.get('company.company')
diff --git a/account.xml b/account.xml
index ad61af4970..5c24268726 100644
--- a/account.xml
+++ b/account.xml
@@ -454,6 +454,7 @@
+
]]>
@@ -604,6 +605,7 @@
+
]]>
@@ -659,6 +661,7 @@
+
]]>
diff --git a/tax.py b/tax.py
index ae480992bc..8ac7e29ebc 100644
--- a/tax.py
+++ b/tax.py
@@ -120,7 +120,10 @@ class Code(OSV):
domain="[('company', '=', company)]")
childs = fields.One2Many('account.tax.code', 'parent', 'Childs',
domain="[('company', '=', company)]")
- sum = fields.Function('get_sum', digits=(16, 2), string='Sum')
+ currency_digits = fields.Function('get_currency_digits', type='integer',
+ string='Currency Digits', on_change_with=['company'])
+ sum = fields.Function('get_sum', digits="(16, currency_digits)",
+ string='Sum')
def __init__(self):
super(Code, self).__init__()
@@ -138,6 +141,21 @@ class Code(OSV):
context = {}
return context.get('company', False)
+ def on_change_with_currency_digits(self, cursor, user, ids, vals,
+ context=None):
+ company_obj = self.pool.get('company.company')
+ if vals.get('company'):
+ company = company_obj.browse(cursor, user, vals['company'],
+ context=context)
+ return company.currency.digits
+ return 2
+
+ def get_currency_digits(self, cursor, user, ids, name, arg, context=None):
+ res = {}
+ for code in self.browse(cursor, user, ids, context=context):
+ res[code.id] = code.company.currency.digits
+ return res
+
def get_sum(self, cursor, user, ids, name, arg, context=None):
res = {}
move_line_obj = self.pool.get('account.move.line')
diff --git a/tax.xml b/tax.xml
index 7d525a55ca..5a18e877a0 100644
--- a/tax.xml
+++ b/tax.xml
@@ -128,6 +128,7 @@
+
]]>