Use string digits for currency digits
This commit is contained in:
+34
-7
@@ -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')
|
||||
|
||||
@@ -454,6 +454,7 @@
|
||||
<field name="credit"/>
|
||||
<field name="balance"/>
|
||||
<field name="currency"/>
|
||||
<field name="currency_digits" tree_invisible="1"/>
|
||||
</tree>
|
||||
]]>
|
||||
</field>
|
||||
@@ -604,6 +605,7 @@
|
||||
<tree string="Balance Sheet">
|
||||
<field name="name"/>
|
||||
<field name="amount"/>
|
||||
<field name="currency_digits" tree_invisible="1"/>
|
||||
</tree>
|
||||
]]>
|
||||
</field>
|
||||
@@ -659,6 +661,7 @@
|
||||
<tree string="Income Statement">
|
||||
<field name="name"/>
|
||||
<field name="amount"/>
|
||||
<field name="currency_digits" tree_invisible="1"/>
|
||||
</tree>
|
||||
]]>
|
||||
</field>
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user