changeset 5e943f95c348 in modules/account:default
details: https://hg.tryton.org/modules/account?cmd=changeset&node=5e943f95c348
description:
Add monetary field
issue10598
review338511002
diffstat:
account.py | 241 +++++++++++---------------------
journal.py | 32 ++--
move.py | 124 +++++-----------
party.py | 41 ++---
tax.py | 68 +++-----
view/account_balance_sheet_tree.xml | 4 +-
view/account_deferral_form.xml | 6 +-
view/account_deferral_tree.xml | 6 +-
view/account_income_statement_tree.xml | 4 +-
view/account_list_balance_sheet.xml | 8 +-
view/account_tree2.xml | 8 +-
view/aged_balance_list.xml | 10 +-
view/general_ledger_account_list.xml | 8 +-
view/general_ledger_line_list.xml | 6 +-
view/move_line_form.xml | 4 +-
view/move_line_form_move.xml | 6 +-
view/move_line_split_start_form.xml | 2 +-
view/move_line_split_term_list.xml | 2 +-
view/move_line_tree.xml | 4 +-
view/move_line_tree_move.xml | 4 +-
view/tax_code_tree2.xml | 2 +-
21 files changed, 233 insertions(+), 357 deletions(-)
diffs (1220 lines):
diff -r b8e750aca405 -r 5e943f95c348 account.py
--- a/account.py Fri Aug 20 23:45:02 2021 +0200
+++ b/account.py Sat Aug 21 09:09:55 2021 +0200
@@ -24,6 +24,8 @@
from trytond.transaction import Transaction
from trytond.pool import Pool
+from trytond.modules.currency.fields import Monetary
+
from .common import PeriodMixin, ActivePeriodMixin
from .exceptions import SecondCurrencyError, ChartWarning
@@ -251,13 +253,11 @@
depends=['company'])
currency = fields.Function(fields.Many2One(
'currency.currency', 'Currency'), 'get_currency')
- currency_digits = fields.Function(fields.Integer('Currency Digits'),
- 'get_currency_digits')
- amount = fields.Function(fields.Numeric('Amount',
- digits=(16, Eval('currency_digits', 2)), depends=['currency_digits']),
+ amount = fields.Function(Monetary(
+ "Amount", currency='currency', digits='currency'),
'get_amount')
- amount_cmp = fields.Function(fields.Numeric('Amount',
- digits=(16, Eval('currency_digits', 2)), depends=['currency_digits']),
+ amount_cmp = fields.Function(Monetary(
+ "Amount", currency='currency', digits='currency'),
'get_amount_cmp')
company = fields.Many2One('company.company', 'Company', required=True,
@@ -289,9 +289,6 @@
def get_currency(self, name):
return self.company.currency.id
- def get_currency_digits(self, name):
- return self.company.currency.digits
-
@classmethod
def get_amount(cls, types, name):
pool = Pool()
@@ -337,8 +334,7 @@
])
for child in childs:
res[type_.id] += type_sum[child.id]
- exp = Decimal(str(10.0 ** -type_.currency_digits))
- res[type_.id] = res[type_.id].quantize(exp)
+ res[type_.id] = type_.currency.round(res[type_.id])
if type_.statement == 'balance' and type_.assets:
res[type_.id] = - res[type_.id]
return res
@@ -781,8 +777,6 @@
ondelete="RESTRICT")
currency = fields.Function(fields.Many2One('currency.currency',
'Currency'), 'get_currency')
- currency_digits = fields.Function(fields.Integer('Currency Digits'),
- 'get_currency_digits')
second_currency = fields.Many2One('currency.currency',
'Secondary Currency', help='Force all moves for this account \n'
'to have this secondary currency.', ondelete="RESTRICT",
@@ -794,8 +788,6 @@
'invisible': ~Eval('deferral', False),
},
depends=['currency', 'deferral'])
- second_currency_digits = fields.Function(fields.Integer(
- "Second Currency Digits"), 'get_second_currency_digits')
type = fields.Many2One(
'account.account.type', "Type", ondelete='RESTRICT',
states={
@@ -823,22 +815,22 @@
right = fields.Integer('Right', required=True, select=True)
childs = fields.One2Many(
'account.account', 'parent', 'Children')
- balance = fields.Function(fields.Numeric('Balance',
- digits=(16, Eval('currency_digits', 2)), depends=['currency_digits']),
+ balance = fields.Function(Monetary(
+ "Balance", currency='currency', digits='currency'),
'get_balance')
- credit = fields.Function(fields.Numeric('Credit',
- digits=(16, Eval('currency_digits', 2)), depends=['currency_digits']),
+ credit = fields.Function(Monetary(
+ "Credit", currency='currency', digits='currency'),
'get_credit_debit')
- debit = fields.Function(fields.Numeric('Debit',
- digits=(16, Eval('currency_digits', 2)), depends=['currency_digits']),
+ debit = fields.Function(Monetary(
+ "Debit", currency='currency', digits='currency'),
'get_credit_debit')
- amount_second_currency = fields.Function(fields.Numeric(
+ amount_second_currency = fields.Function(Monetary(
"Amount Second Currency",
- digits=(16, Eval('second_currency_digits', 2)),
+ currency='second_currency', digits='second_currency',
states={
'invisible': ~Eval('second_currency'),
},
- depends=['second_currency_digits', 'second_currency']),
+ depends=['second_currency']),
'get_credit_debit')
note = fields.Text('Note')
deferrals = fields.One2Many(
@@ -917,15 +909,6 @@
def get_currency(self, name):
return self.company.currency.id
- def get_currency_digits(self, name):
- return self.company.currency.digits
-
- def get_second_currency_digits(self, name):
- if self.second_currency:
- return self.second_currency.digits
- else:
- return 2
-
@classmethod
def get_balance(cls, accounts, name):
pool = Pool()
@@ -956,8 +939,7 @@
# SQLite uses float for SUM
if not isinstance(balances[account.id], Decimal):
balances[account.id] = Decimal(str(balances[account.id]))
- exp = Decimal(str(10.0 ** -account.currency_digits))
- balances[account.id] = balances[account.id].quantize(exp)
+ balances[account.id] = account.currency.round(balances[account.id])
fiscalyears = FiscalYear.browse(fiscalyear_ids)
@@ -1008,12 +990,13 @@
result[name][account_id] = row[i]
for account in accounts:
for name in names:
- if name == 'amount_second_currency':
- exp = Decimal(str(10.0 ** -account.second_currency_digits))
+ if (name == 'amount_second_currency'
+ and account.second_currency):
+ currency = account.second_currency
else:
- exp = Decimal(str(10.0 ** -account.currency_digits))
- result[name][account.id] = (
- result[name][account.id].quantize(exp))
+ currency = account.currency
+ result[name][account.id] = currency.round(
+ result[name][account.id])
cumulate_names = []
if Transaction().context.get('cumulate'):
@@ -1289,33 +1272,28 @@
debit_type = fields.Many2One('account.account.type', "Debit Type")
closed = fields.Boolean("Closed")
- balance = fields.Function(fields.Numeric(
- "Balance", digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits']),
+ balance = fields.Function(Monetary(
+ "Balance", currency='currency', digits='currency'),
'get_balance')
- credit = fields.Function(fields.Numeric(
- "Credit", digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits']),
+ credit = fields.Function(Monetary(
+ "Credit", currency='currency', digits='currency'),
'get_credit_debit')
- debit = fields.Function(fields.Numeric(
- "Debit", digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits']),
+ debit = fields.Function(Monetary(
+ "Debit", currency='currency', digits='currency'),
'get_credit_debit')
- amount_second_currency = fields.Function(fields.Numeric(
+ amount_second_currency = fields.Function(Monetary(
"Amount Second Currency",
- digits=(16, Eval('second_currency_digits', 2)),
+ currency='second_currency', digits='second_currency',
states={
'invisible': ~Eval('second_currency'),
},
- depends=['second_currency_digits', 'second_currency']),
+ depends=['second_currency']),
'get_credit_debit')
second_currency = fields.Many2One(
'currency.currency', "Secondary Currency")
- currency_digits = fields.Function(
- fields.Integer("Currency Digits"), 'get_currency_digits')
- second_currency_digits = fields.Function(fields.Integer(
- "Second Currency Digits"), 'get_second_currency_digits')
+ currency = fields.Function(fields.Many2One(
+ 'currency.currency', "Currency"), 'get_currency')
@classmethod
def table_query(cls):
@@ -1391,8 +1369,7 @@
# SQLite uses float for SUM
if not isinstance(balances[record.id], Decimal):
balances[record.id] = Decimal(str(balances[record.id]))
- exp = Decimal(str(10.0 ** -record.currency_digits))
- balances[record.id] = balances[record.id].quantize(exp)
+ balances[record.id] = record.currency.round(balances[record.id])
fiscalyears = FiscalYear.browse(fiscalyear_ids)
@@ -1450,12 +1427,12 @@
result[name][id_] = row[i]
for record in records:
for name in names:
- if name == 'amount_second_currency':
- exp = Decimal(str(10.0 ** -record.second_currency_digits))
+ if name == 'amount_second_currency' and record.second_currency:
+ currency = record.second_currency
else:
- exp = Decimal(str(10.0 ** -record.currency_digits))
- result[name][record.id] = (
- result[name][record.id].quantize(exp))
+ currency = record.currency
+ result[name][record.id] = currency.round(
+ result[name][record.id])
cumulate_names = []
if Transaction().context.get('cumulate'):
@@ -1470,11 +1447,8 @@
else:
return result
- def get_currency_digits(self, name):
- return self.company.currency.digits
-
- def get_second_currency_digits(self, name):
- return self.account.second_currency_digits
+ def get_currency(self, name):
+ return self.company.currency.id
class AccountDeferral(ModelSQL, ModelView):
@@ -1488,28 +1462,24 @@
select=True)
fiscalyear = fields.Many2One('account.fiscalyear', 'Fiscal Year',
required=True, select=True)
- debit = fields.Numeric('Debit', digits=(16, Eval('currency_digits', 2)),
- required=True, depends=['currency_digits'])
- credit = fields.Numeric('Credit', digits=(16, Eval('currency_digits', 2)),
- required=True, depends=['currency_digits'])
- balance = fields.Function(fields.Numeric('Balance',
- digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits']), 'get_balance')
+ debit = Monetary(
+ "Debit", currency='currency', digits='currency', required=True)
+ credit = Monetary(
+ "Credit", currency='currency', digits='currency', required=True)
+ balance = fields.Function(Monetary(
+ "Balance", currency='currency', digits='currency'),
+ 'get_balance')
currency = fields.Function(fields.Many2One(
'currency.currency', "Currency"), 'get_currency')
- currency_digits = fields.Function(fields.Integer('Currency Digits'),
- 'get_currency_digits')
- amount_second_currency = fields.Numeric(
+ amount_second_currency = Monetary(
"Amount Second Currency",
- digits=(16, Eval('second_currency_digits', 2)),
+ currency='second_currency', digits='second_currency', required=True,
states={
'invisible': ~Eval('second_currency'),
},
- required=True, depends=['second_currency_digits', 'second_currency'])
+ depends=['second_currency'])
second_currency = fields.Function(fields.Many2One(
'currency.currency', "Second Currency"), 'get_second_currency')
- second_currency_digits = fields.Function(fields.Integer(
- "Second Currency Digits"), 'get_second_currency_digits')
@classmethod
def __setup__(cls):
@@ -1530,16 +1500,10 @@
def get_currency(self, name):
return self.account.currency.id
- def get_currency_digits(self, name):
- return self.account.currency_digits
-
def get_second_currency(self, name):
if self.account.second_currency:
return self.account.second_currency.id
- def get_second_currency_digits(self, name):
- return self.account.second_currency_digits
-
def get_rec_name(self, name):
return '%s - %s' % (self.account.rec_name, self.fiscalyear.rec_name)
@@ -1611,42 +1575,32 @@
account = fields.Many2One('account.account', "Account")
company = fields.Many2One('company.company', 'Company')
- start_debit = fields.Function(fields.Numeric('Start Debit',
- digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits']),
+ start_debit = fields.Function(Monetary(
+ "Start Debit", currency='currency', digits='currency'),
'get_account', searcher='search_account')
- debit = fields.Function(fields.Numeric('Debit',
- digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits']),
+ debit = fields.Function(Monetary(
+ "Debit", currency='currency', digits='currency'),
'get_debit_credit', searcher='search_debit_credit')
- end_debit = fields.Function(fields.Numeric('End Debit',
- digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits']),
+ end_debit = fields.Function(Monetary(
+ "End Debit", currency='currency', digits='currency'),
'get_account', searcher='search_account')
- start_credit = fields.Function(fields.Numeric('Start Credit',
- digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits']),
+ start_credit = fields.Function(Monetary(
+ "Start Credit", currency='currency', digits='currency'),
'get_account', searcher='search_account')
- credit = fields.Function(fields.Numeric('Credit',
- digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits']),
+ credit = fields.Function(Monetary(
+ "Credit", currency='currency', digits='currency'),
'get_debit_credit', searcher='search_debit_credit')
- end_credit = fields.Function(fields.Numeric('End Credit',
- digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits']),
+ end_credit = fields.Function(Monetary(
+ "End Credit", currency='currency', digits='currency'),
'get_account', searcher='search_account')
- start_balance = fields.Function(fields.Numeric('Start Balance',
- digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits']),
+ start_balance = fields.Function(Monetary(
+ "Start Balance", currency='currency', digits='currency'),
'get_account', searcher='search_account')
- end_balance = fields.Function(fields.Numeric('End Balance',
- digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits']),
+ end_balance = fields.Function(Monetary(
+ "End Balance", currency='currency', digits='currency'),
'get_account', searcher='search_account')
currency = fields.Function(fields.Many2One(
'currency.currency', 'Currency'), 'get_currency')
- currency_digits = fields.Function(fields.Integer('Currency Digits'),
- 'get_currency_digits')
@classmethod
def __setup__(cls):
@@ -1810,9 +1764,6 @@
def get_currency(self, name):
return self.company.currency.id
- def get_currency_digits(self, name):
- return self.company.currency.digits
-
def get_rec_name(self, name):
return self.account.rec_name
@@ -2001,19 +1952,14 @@
'account.general_ledger.account.party', "Account Party"),
'get_account_party')
company = fields.Many2One('company.company', 'Company')
- debit = fields.Numeric('Debit',
- digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits'])
- credit = fields.Numeric('Credit',
- digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits'])
- internal_balance = fields.Numeric("Internal Balance",
- digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits'])
- balance = fields.Function(
- fields.Numeric("Balance",
- digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits']),
+ debit = Monetary(
+ "Debit", currency='currency', digits='currency')
+ credit = Monetary(
+ "Credit", currency='currency', digits='currency')
+ internal_balance = Monetary(
+ "Internal Balance", currency='currency', digits='currency')
+ balance = fields.Function(Monetary(
+ "Balance", currency='currency', digits='currency'),
'get_balance')
origin = fields.Reference('Origin', selection='get_origin')
description = fields.Char('Description')
@@ -2027,8 +1973,6 @@
state_string = state.translated('state')
currency = fields.Function(fields.Many2One(
'currency.currency', "Currency"), 'get_currency')
- currency_digits = fields.Function(fields.Integer('Currency Digits'),
- 'get_currency_digits')
@classmethod
def __setup__(cls):
@@ -2088,9 +2032,6 @@
def get_currency(self, name):
return self.company.currency.id
- def get_currency_digits(self, name):
- return self.company.currency.digits
-
@classmethod
def get_origin(cls):
Line = Pool().get('account.move.line')
@@ -2474,25 +2415,18 @@
},
depends=['company'])
company = fields.Many2One('company.company', 'Company')
- term0 = fields.Numeric('Now',
- digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits'])
- term1 = fields.Numeric('First Term',
- digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits'])
- term2 = fields.Numeric('Second Term',
- digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits'])
- term3 = fields.Numeric('Third Term',
- digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits'])
- balance = fields.Numeric('Balance',
- digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits'])
+ term0 = Monetary(
+ "Now", currency='currency', digits='currency')
+ term1 = Monetary(
+ "First Term", currency='currency', digits='currency')
+ term2 = Monetary(
+ "Second Term", currency='currency', digits='currency')
+ term3 = Monetary(
+ "Third Term", currency='currency', digits='currency')
+ balance = Monetary(
+ "Balance", currency='currency', digits='currency')
currency = fields.Function(fields.Many2One(
'currency.currency', "Currency"), 'get_currency')
- currency_digits = fields.Function(fields.Integer('Currency Digits'),
- 'get_currency_digits')
@classmethod
def __setup__(cls):
@@ -2606,9 +2540,6 @@
def get_currency(self, name):
return self.company.currency.id
- def get_currency_digits(self, name):
- return self.company.currency.digits
-
class AgedBalanceReport(Report):
__name__ = 'account.aged_balance'
diff -r b8e750aca405 -r 5e943f95c348 journal.py
--- a/journal.py Fri Aug 20 23:45:02 2021 +0200
+++ b/journal.py Sat Aug 21 09:09:55 2021 +0200
@@ -16,6 +16,7 @@
from trytond.tools.multivalue import migrate_property
from trytond.modules.company.model import (
CompanyMultiValueMixin, CompanyValueMixin)
+from trytond.modules.currency.fields import Monetary
STATES = {
'readonly': Eval('state') == 'close',
@@ -50,17 +51,18 @@
}))
sequences = fields.One2Many(
'account.journal.sequence', 'journal', "Sequences")
- debit = fields.Function(fields.Numeric('Debit',
- digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits']), 'get_debit_credit_balance')
- credit = fields.Function(fields.Numeric('Credit',
- digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits']), 'get_debit_credit_balance')
- balance = fields.Function(fields.Numeric('Balance',
- digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits']), 'get_debit_credit_balance')
- currency_digits = fields.Function(fields.Integer('Currency Digits'),
- 'get_currency_digits')
+ debit = fields.Function(Monetary(
+ "Debit", currency='currency', digits='currency'),
+ 'get_debit_credit_balance')
+ credit = fields.Function(Monetary(
+ "Credit", currency='currency', digits='currency'),
+ 'get_debit_credit_balance')
+ balance = fields.Function(Monetary(
+ "Balance", currency='currency', digits='currency'),
+ 'get_debit_credit_balance')
+
+ currency = fields.Function(fields.Many2One(
+ 'currency.currency', "Currency"), 'get_currency')
@classmethod
def __setup__(cls):
@@ -86,16 +88,16 @@
]
@classmethod
- def get_currency_digits(cls, journals, name):
+ def get_currency(cls, journals, name):
pool = Pool()
Company = pool.get('company.company')
company_id = Transaction().context.get('company')
if company_id:
company = Company(company_id)
- digits = company.currency.digits
+ currency_id = company.currency.id
else:
- digits = 2
- return dict.fromkeys([j.id for j in journals], digits)
+ currency_id = None
+ return dict.fromkeys([j.id for j in journals], currency_id)
@classmethod
def get_debit_credit_balance(cls, journals, names):
diff -r b8e750aca405 -r 5e943f95c348 move.py
--- a/move.py Fri Aug 20 23:45:02 2021 +0200
+++ b/move.py Sat Aug 21 09:09:55 2021 +0200
@@ -25,6 +25,8 @@
from trytond.tools import reduce_ids, grouped_slice
from trytond.config import config
+from trytond.modules.currency.fields import Monetary
+
from .exceptions import (PostError, MoveDatesError, CancelWarning,
ReconciliationError, DeleteDelegatedWarning, GroupLineError,
SplitLineError, CancelDelegatedWarning)
@@ -612,14 +614,14 @@
}
_depends = ['move_state']
- debit = fields.Numeric('Debit', digits=(16, Eval('currency_digits', 2)),
- required=True, states=_states,
- depends=['currency_digits', 'credit', 'tax_lines', 'journal']
- + _depends)
- credit = fields.Numeric('Credit', digits=(16, Eval('currency_digits', 2)),
- required=True, states=_states,
- depends=['currency_digits', 'debit', 'tax_lines', 'journal']
- + _depends)
+ debit = Monetary(
+ "Debit", currency='currency', digits='currency', required=True,
+ states=_states,
+ depends=['credit', 'tax_lines', 'journal'] + _depends)
+ credit = Monetary(
+ "Credit", currency='currency', digits='currency', required=True,
+ states=_states,
+ depends=['debit', 'tax_lines', 'journal'] + _depends)
account = fields.Many2One('account.account', 'Account', required=True,
domain=[
('company', '=', Eval('company', -1)),
@@ -677,14 +679,15 @@
states=_states, depends=_depends),
'get_move_field', setter='set_move_field',
searcher='search_move_field')
- amount_second_currency = fields.Numeric('Amount Second Currency',
- digits=(16, Eval('second_currency_digits', 2)),
- help='The amount expressed in a second currency.',
+ amount_second_currency = Monetary(
+ "Amount Second Currency",
+ currency='second_currency', digits='second_currency',
states={
'required': Bool(Eval('second_currency')),
'readonly': _states['readonly'],
},
- depends=['second_currency_digits', 'second_currency'] + _depends)
+ depends=['second_currency'] + _depends,
+ help='The amount expressed in a second currency.')
second_currency = fields.Many2One('currency.currency', 'Second Currency',
help='The second currency.',
domain=[
@@ -732,18 +735,11 @@
'on_change_with_move_state', searcher='search_move_field')
currency = fields.Function(fields.Many2One(
'currency.currency', "Currency"), 'on_change_with_currency')
- currency_digits = fields.Function(fields.Integer('Currency Digits'),
- 'on_change_with_currency_digits')
- second_currency_digits = fields.Function(fields.Integer(
- 'Second Currency Digits'), 'on_change_with_second_currency_digits')
- amount = fields.Function(fields.Numeric('Amount',
- digits=(16, Eval('amount_currency_digits', 2)),
- depends=['amount_currency_digits']),
+ amount = fields.Function(Monetary(
+ "Amount", currency='amount_currency', digits='amount_currency'),
'get_amount')
amount_currency = fields.Function(fields.Many2One('currency.currency',
'Amount Currency'), 'get_amount_currency')
- amount_currency_digits = fields.Function(fields.Integer(
- 'Amount Currency Digits'), 'get_amount_currency')
del _states, _depends
@@ -847,10 +843,6 @@
return 'draft'
@staticmethod
- def default_currency_digits():
- return 2
-
- @staticmethod
def default_debit():
return Decimal(0)
@@ -863,20 +855,6 @@
if self.account:
return self.account.currency.id
- @fields.depends('account')
- def on_change_with_currency_digits(self, name=None):
- if self.account:
- return self.account.currency_digits
- else:
- return 2
-
- @fields.depends('second_currency')
- def on_change_with_second_currency_digits(self, name=None):
- if self.second_currency:
- return self.second_currency.digits
- else:
- return 2
-
@classmethod
def _get_origin(cls):
'Return list of Model names for origin Reference'
@@ -919,11 +897,8 @@
@fields.depends('account')
def on_change_account(self):
if self.account:
- self.currency_digits = self.account.currency_digits
if self.account.second_currency:
self.second_currency = self.account.second_currency
- self.second_currency_digits = (
- self.on_change_with_second_currency_digits())
if not self.account.party_required:
self.party = None
@@ -1020,10 +995,7 @@
currency = self.second_currency
else:
currency = self.account.currency
- if name == 'amount_currency':
- return currency.id
- elif name == 'amount_currency_digits':
- return currency.digits
+ return currency.id
def get_rec_name(self, name):
if self.debit > self.credit:
@@ -1555,10 +1527,11 @@
],
depends=['company'])
date = fields.Date('Date', required=True)
- amount = fields.Numeric('Amount', digits=(16, Eval('currency_digits', 2)),
- readonly=True, depends=['currency_digits'])
- currency_digits = fields.Function(fields.Integer('Currency Digits'),
- 'on_change_with_currency_digits')
+ amount = Monetary(
+ "Amount", currency='currency', digits='currency', readonly=True)
+ currency = fields.Function(fields.Many2One(
+ 'currency.currency', "Currency"),
+ 'on_change_with_currency')
description = fields.Char('Description')
@staticmethod
@@ -1567,9 +1540,9 @@
return Date.today()
@fields.depends('company')
- def on_change_with_currency_digits(self, name=None):
+ def on_change_with_currency(self, name=None):
if self.company:
- return self.company.currency.digits
+ return self.company.currency.id
class ReconcileLines(Wizard):
@@ -1765,7 +1738,7 @@
defaults['company'] = self.show.account.company.id
defaults['parties'] = [p.id for p in self.show.parties]
defaults['party'] = self.show.party.id if self.show.party else None
- defaults['currency_digits'] = self.show.account.company.currency.digits
+ defaults['currency'] = self.show.account.company.currency.id
defaults['lines'] = self._default_lines()
defaults['write_off_amount'] = Decimal(0)
defaults['date'] = Date.today()
@@ -1868,13 +1841,13 @@
}
_write_off_depends = ['write_off_amount']
- write_off_amount = fields.Function(fields.Numeric('Amount',
- digits=(16, Eval('currency_digits', 2)),
- states=_write_off_states,
- depends=_write_off_depends + ['currency_digits']),
+ write_off_amount = fields.Function(Monetary(
+ "Amount", currency='currency', digits='currency',
+ states=_write_off_states, depends=_write_off_depends),
'on_change_with_write_off_amount')
- currency_digits = fields.Function(fields.Integer('Currency Digits'),
- 'on_change_with_currency_digits')
+ currency = fields.Function(fields.Many2One(
+ 'currency.currency', "Currency"),
+ 'on_change_with_currency')
write_off = fields.Many2One(
'account.move.reconcile.write_off', "Write Off",
domain=[
@@ -1888,17 +1861,17 @@
'invisible': _write_off_states['invisible'],
}, depends=_write_off_depends)
- @fields.depends('lines', 'currency_digits')
+ @fields.depends('lines', 'currency')
def on_change_with_write_off_amount(self, name=None):
- digits = self.currency_digits or 0
- exp = Decimal(str(10.0 ** -digits))
amount = sum(((l.debit - l.credit) for l in self.lines), Decimal(0))
- return amount.quantize(exp)
+ if self.currency:
+ amount = self.currency.round(amount)
+ return amount
@fields.depends('company')
- def on_change_with_currency_digits(self, name=None):
+ def on_change_with_currency(self, name=None):
if self.company:
- return self.company.currency.digits
+ return self.company.currency.id
class CancelMoves(Wizard):
@@ -2208,7 +2181,6 @@
self.get_account(self.records)
currency = self.get_currency(self.records)
values['currency'] = currency.id
- values['currency_digits'] = currency.digits
values['total_amount'] = self.get_total_amount(self.records)
return values
@@ -2383,8 +2355,8 @@
},
depends=['frequency'],
help="The length of each period, in months.")
- amount = fields.Numeric(
- "Amount", digits=(16, Eval('currency_digits', 2)),
+ amount = Monetary(
+ "Amount", currency='currency', digits='currency',
states={
'required': ~Eval('number'),
'invisible': Bool(Eval('number')),
@@ -2400,7 +2372,7 @@
('amount', '<', 0),
]),
[])],
- depends=['currency_digits', 'number', 'total_amount'])
+ depends=['number', 'total_amount'])
number = fields.Integer(
"Number",
domain=[
@@ -2414,7 +2386,6 @@
total_amount = fields.Numeric("Total Amount", readonly=True)
currency = fields.Many2One('currency.currency', "Currency", readonly=True)
- currency_digits = fields.Integer("Currency Digits", readonly=True)
@classmethod
def default_frequency(cls):
@@ -2452,18 +2423,9 @@
"Split Lines"
__name__ = 'account.move.line.split.term'
date = fields.Date("Date", required=True)
- amount = fields.Numeric(
- "Amount", digits=(16, Eval('currency_digits', 2)), required=True,
- depends=['currency_digits'])
+ amount = Monetary(
+ "Amount", currency='currency', digits='currency', required=True)
currency = fields.Many2One('currency.currency', "Currency", required=True)
- currency_digits = fields.Function(
- fields.Integer("Currency Digits", readonly=True),
- 'on_change_with_currency_digits')
-
- @fields.depends('currency')
- def on_change_with_currency_digits(self, name=None):
- if self.currency:
- return self.currency.digits
class GeneralJournal(Report):
diff -r b8e750aca405 -r 5e943f95c348 party.py
--- a/party.py Fri Aug 20 23:45:02 2021 +0200
+++ b/party.py Sat Aug 21 09:09:55 2021 +0200
@@ -17,6 +17,7 @@
from trytond.modules.company.model import (
CompanyMultiValueMixin, CompanyValueMixin)
from trytond.modules.party.exceptions import EraseError
+from trytond.modules.currency.fields import Monetary
from .exceptions import AccountMissing
@@ -68,24 +69,20 @@
states={
'invisible': ~Eval('context', {}).get('company'),
}, help='Apply this rule on taxes when party is supplier.'))
- currency_digits = fields.Function(fields.Integer('Currency Digits'),
- 'get_currency_digits')
- receivable = fields.Function(fields.Numeric('Receivable',
- digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits']),
- 'get_receivable_payable', searcher='search_receivable_payable')
- payable = fields.Function(fields.Numeric('Payable',
- digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits']),
- 'get_receivable_payable', searcher='search_receivable_payable')
- receivable_today = fields.Function(fields.Numeric('Receivable Today',
- digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits']),
- 'get_receivable_payable', searcher='search_receivable_payable')
- payable_today = fields.Function(fields.Numeric('Payable Today',
- digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits']),
- 'get_receivable_payable', searcher='search_receivable_payable')
+ currency = fields.Function(fields.Many2One(
+ 'currency.currency', "Currency"), 'get_currency')
+ receivable = fields.Function(Monetary(
+ "Receivable", currency='currency', digits='currency'),
+ 'get_receivable_payable', searcher='search_receivable_payable')
+ payable = fields.Function(Monetary(
+ "Payable", currency='currency', digits='currency'),
+ 'get_receivable_payable', searcher='search_receivable_payable')
+ receivable_today = fields.Function(Monetary(
+ "Receivable Today", currency='currency', digits='currency'),
+ 'get_receivable_payable', searcher='search_receivable_payable')
+ payable_today = fields.Function(Monetary(
+ "Payable Today", currency='currency', digits='currency'),
+ 'get_receivable_payable', searcher='search_receivable_payable')
@classmethod
def multivalue_model(cls, field):
@@ -112,17 +109,13 @@
def default_supplier_tax_rule(cls, **pattern):
return cls._default_tax_rule('supplier', **pattern)
- @classmethod
- def get_currency_digits(cls, parties, name):
+ def get_currency(self, name):
pool = Pool()
Company = pool.get('company.company')
company_id = Transaction().context.get('company')
if company_id:
company = Company(company_id)
- digits = company.currency.digits
- else:
- digits = 2
- return {p.id: digits for p in parties}
+ return company.currency.id
@classmethod
def get_receivable_payable(cls, parties, names):
diff -r b8e750aca405 -r 5e943f95c348 tax.py
--- a/tax.py Fri Aug 20 23:45:02 2021 +0200
+++ b/tax.py Sat Aug 21 09:09:55 2021 +0200
@@ -21,6 +21,8 @@
from trytond.tools import cursor_dict, lstrip_wildcard
from trytond.pool import Pool
+from trytond.modules.currency.fields import Monetary
+
from .common import PeriodMixin, ActivePeriodMixin
KINDS = [
@@ -137,11 +139,8 @@
childs = fields.One2Many('account.tax.code', 'parent', 'Children')
currency = fields.Function(fields.Many2One('currency.currency',
'Currency'), 'on_change_with_currency')
- currency_digits = fields.Function(fields.Integer('Currency Digits'),
- 'on_change_with_currency_digits')
- amount = fields.Function(fields.Numeric(
- "Amount", digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits']),
+ amount = fields.Function(Monetary(
+ "Amount", currency='currency', digits='currency'),
'get_amount')
template = fields.Many2One('account.tax.code.template', 'Template')
template_override = fields.Boolean('Override Template',
@@ -176,12 +175,6 @@
if self.company:
return self.company.currency.id
- @fields.depends('currency')
- def on_change_with_currency_digits(self, name=None):
- if self.currency:
- return self.currency.digits
- return 2
-
@classmethod
def get_amount(cls, codes, name):
result = {}
@@ -191,9 +184,8 @@
('parent', 'child_of', [c.id for c in codes]),
])
for code in childs:
- exp = Decimal(str(10.0 ** -code.currency_digits))
- result[code.id] = sum(
- (l.value for l in code.lines), Decimal(0)).quantize(exp)
+ result[code.id] = code.currency.round(
+ sum((l.value for l in code.lines), Decimal(0)))
parents[code.id] = code.parent.id if code.parent else None
ids = set(map(int, childs))
@@ -760,25 +752,22 @@
},
depends=['template'])
- invoice_base_amount = fields.Function(fields.Numeric(
- "Invoice Base Amount", digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits']),
+ invoice_base_amount = fields.Function(Monetary(
+ "Invoice Base Amount", currency='currency', digits='currency'),
'get_amount')
- invoice_tax_amount = fields.Function(fields.Numeric(
- "Invoice Tax Amount", digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits']),
+ invoice_tax_amount = fields.Function(Monetary(
+ "Invoice Tax Amount", currency='currency', digits='currency'),
'get_amount')
- credit_base_amount = fields.Function(fields.Numeric(
- "Credit Base Amount", digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits']),
+ credit_base_amount = fields.Function(Monetary(
+ "Credit Base Amount", currency='currency', digits='currency'),
'get_amount')
- credit_tax_amount = fields.Function(fields.Numeric(
- "Credit Tax Amount", digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits']),
+ credit_tax_amount = fields.Function(Monetary(
+ "Credit Tax Amount", currency='currency', digits='currency'),
'get_amount')
- currency_digits = fields.Function(fields.Integer("Currency Digits"),
- 'on_change_with_currency_digits')
+ currency = fields.Function(fields.Many2One(
+ 'currency.currency', "Currency"),
+ 'on_change_with_currency')
del _states
@@ -897,10 +886,9 @@
return [('move_line.move.period', 'in', periods)]
@fields.depends('company')
- def on_change_with_currency_digits(self, name=None):
+ def on_change_with_currency(self, name=None):
if self.company:
- return self.company.currency.digits
- return 2
+ return self.company.currency.id
@classmethod
def copy(cls, taxes, default=None):
@@ -1199,10 +1187,11 @@
class TaxLine(ModelSQL, ModelView):
'Tax Line'
__name__ = 'account.tax.line'
- currency_digits = fields.Function(fields.Integer('Currency Digits'),
- 'on_change_with_currency_digits')
- amount = fields.Numeric('Amount', digits=(16, Eval('currency_digits', 2)),
- required=True, depends=['currency_digits'])
+ currency = fields.Function(fields.Many2One(
+ 'currency.currency', "Currency"),
+ 'on_change_with_currency')
+ amount = Monetary(
+ "Amount", currency='currency', digits='currency', required=True)
type = fields.Selection([
('tax', "Tax"),
('base', "Base"),
@@ -1264,11 +1253,10 @@
& (table.code.in_(
[invoice_base_code, credit_note_base_code]))))
- @fields.depends('move_line', '_parent_move_line.currency_digits')
- def on_change_with_currency_digits(self, name=None):
- if self.move_line:
- return self.move_line.currency_digits
- return 2
+ @fields.depends('move_line', '_parent_move_line.currency')
+ def on_change_with_currency(self, name=None):
+ if self.move_line and self.move_line.currency:
+ return self.move_line.currency.id
@fields.depends('_parent_move_line.account', 'move_line')
def on_change_with_company(self, name=None):
diff -r b8e750aca405 -r 5e943f95c348 view/account_balance_sheet_tree.xml
--- a/view/account_balance_sheet_tree.xml Fri Aug 20 23:45:02 2021 +0200
+++ b/view/account_balance_sheet_tree.xml Sat Aug 21 09:09:55 2021 +0200
@@ -3,6 +3,6 @@
this repository contains the full copyright notices and license terms. -->
<tree keyword_open="1">
<field name="name" expand="1"/>
- <field name="amount" symbol="currency"/>
- <field name="amount_cmp" string="Comparison" symbol="currency"/>
+ <field name="amount"/>
+ <field name="amount_cmp" string="Comparison"/>
</tree>
diff -r b8e750aca405 -r 5e943f95c348 view/account_deferral_form.xml
--- a/view/account_deferral_form.xml Fri Aug 20 23:45:02 2021 +0200
+++ b/view/account_deferral_form.xml Sat Aug 21 09:09:55 2021 +0200
@@ -9,11 +9,11 @@
<field name="fiscalyear"/>
<newline/>
<label name="debit"/>
- <field name="debit" symbol="currency"/>
+ <field name="debit"/>
<label name="credit"/>
- <field name="credit" symbol="currency"/>
+ <field name="credit"/>
<label name="amount_second_currency"/>
- <field name="amount_second_currency" symbol="second_currency"/>
+ <field name="amount_second_currency"/>
<label name="second_currency"/>
<field name="second_currency"/>
</form>
diff -r b8e750aca405 -r 5e943f95c348 view/account_deferral_tree.xml
--- a/view/account_deferral_tree.xml Fri Aug 20 23:45:02 2021 +0200
+++ b/view/account_deferral_tree.xml Sat Aug 21 09:09:55 2021 +0200
@@ -4,7 +4,7 @@
<tree>
<field name="account"/>
<field name="fiscalyear"/>
- <field name="debit" symbol="currency"/>
- <field name="credit" symbol="currency"/>
- <field name="amount_second_currency" symbol="second_currency"/>
+ <field name="debit"/>
+ <field name="credit"/>
+ <field name="amount_second_currency"/>
</tree>
diff -r b8e750aca405 -r 5e943f95c348 view/account_income_statement_tree.xml
--- a/view/account_income_statement_tree.xml Fri Aug 20 23:45:02 2021 +0200
+++ b/view/account_income_statement_tree.xml Sat Aug 21 09:09:55 2021 +0200
@@ -3,6 +3,6 @@
this repository contains the full copyright notices and license terms. -->
<tree keyword_open="1">
<field name="name" expand="1"/>
- <field name="amount" symbol="currency"/>
- <field name="amount_cmp" string="Comparison" symbol="currency"/>
+ <field name="amount"/>
+ <field name="amount_cmp" string="Comparison"/>
</tree>
diff -r b8e750aca405 -r 5e943f95c348 view/account_list_balance_sheet.xml
--- a/view/account_list_balance_sheet.xml Fri Aug 20 23:45:02 2021 +0200
+++ b/view/account_list_balance_sheet.xml Sat Aug 21 09:09:55 2021 +0200
@@ -4,8 +4,8 @@
<tree keyword_open="1">
<field name="code"/>
<field name="name" expand="1"/>
- <field name="debit" symbol="currency"/>
- <field name="credit" symbol="currency"/>
- <field name="balance" symbol="currency"/>
- <field name="amount_second_currency" symbol="second_currency"/>
+ <field name="debit"/>
+ <field name="credit"/>
+ <field name="balance"/>
+ <field name="amount_second_currency"/>
</tree>
diff -r b8e750aca405 -r 5e943f95c348 view/account_tree2.xml
--- a/view/account_tree2.xml Fri Aug 20 23:45:02 2021 +0200
+++ b/view/account_tree2.xml Sat Aug 21 09:09:55 2021 +0200
@@ -4,8 +4,8 @@
<tree keyword_open="1">
<field name="name" expand="2"/>
<field name="code"/>
- <field name="debit" symbol="currency"/>
- <field name="credit" symbol="currency"/>
- <field name="balance" symbol="currency"/>
- <field name="amount_second_currency" symbol="second_currency"/>
+ <field name="debit"/>
+ <field name="credit"/>
+ <field name="balance"/>
+ <field name="amount_second_currency"/>
</tree>
diff -r b8e750aca405 -r 5e943f95c348 view/aged_balance_list.xml
--- a/view/aged_balance_list.xml Fri Aug 20 23:45:02 2021 +0200
+++ b/view/aged_balance_list.xml Sat Aug 21 09:09:55 2021 +0200
@@ -3,9 +3,9 @@
this repository contains the full copyright notices and license terms. -->
<tree>
<field name="party" expand="2"/>
- <field name="term0" expand="1" symbol="currency"/>
- <field name="term1" expand="1" symbol="currency"/>
- <field name="term2" expand="1" symbol="currency"/>
- <field name="term3" expand="1" symbol="currency"/>
- <field name="balance" expand="1" symbol="currency"/>
+ <field name="term0" expand="1"/>
+ <field name="term1" expand="1"/>
+ <field name="term2" expand="1"/>
+ <field name="term3" expand="1"/>
+ <field name="balance" expand="1"/>
</tree>
diff -r b8e750aca405 -r 5e943f95c348 view/general_ledger_account_list.xml
--- a/view/general_ledger_account_list.xml Fri Aug 20 23:45:02 2021 +0200
+++ b/view/general_ledger_account_list.xml Sat Aug 21 09:09:55 2021 +0200
@@ -3,8 +3,8 @@
this repository contains the full copyright notices and license terms. -->
<tree keyword_open="1">
<field name="account" expand="1"/>
- <field name="start_balance" sum="Start Balance" symbol="currency"/>
- <field name="debit" sum="Debit" symbol="currency"/>
- <field name="credit" sum="Credit" symbol="currency"/>
- <field name="end_balance" sum="End Balance" symbol="currency"/>
+ <field name="start_balance" sum="Start Balance"/>
+ <field name="debit" sum="Debit"/>
+ <field name="credit" sum="Credit"/>
+ <field name="end_balance" sum="End Balance"/>
</tree>
diff -r b8e750aca405 -r 5e943f95c348 view/general_ledger_line_list.xml
--- a/view/general_ledger_line_list.xml Fri Aug 20 23:45:02 2021 +0200
+++ b/view/general_ledger_line_list.xml Sat Aug 21 09:09:55 2021 +0200
@@ -11,7 +11,7 @@
<field name="origin"/>
<field name="reconciliation"/>
<field name="state"/>
- <field name="debit" sum="Debit" symbol="currency"/>
- <field name="credit" sum="Credit" symbol="currency"/>
- <field name="balance" symbol="currency"/>
+ <field name="debit" sum="Debit"/>
+ <field name="credit" sum="Credit"/>
+ <field name="balance"/>
</tree>
diff -r b8e750aca405 -r 5e943f95c348 view/move_line_form.xml
--- a/view/move_line_form.xml Fri Aug 20 23:45:02 2021 +0200
+++ b/view/move_line_form.xml Sat Aug 21 09:09:55 2021 +0200
@@ -17,9 +17,9 @@
<newline/>
<label name="debit"/>
- <field name="debit" symbol="currency"/>
+ <field name="debit"/>
<label name="credit"/>
- <field name="credit" symbol="currency"/>
+ <field name="credit"/>
<label name="move_origin"/>
<field name="move_origin"/>
<label name="origin"/>
diff -r b8e750aca405 -r 5e943f95c348 view/move_line_form_move.xml
--- a/view/move_line_form_move.xml Fri Aug 20 23:45:02 2021 +0200
+++ b/view/move_line_form_move.xml Sat Aug 21 09:09:55 2021 +0200
@@ -6,9 +6,9 @@
<field name="account"/>
<newline/>
<label name="debit"/>
- <field name="debit" symbol="currency"/>
+ <field name="debit"/>
<label name="credit"/>
- <field name="credit" symbol="currency"/>
+ <field name="credit"/>
<label name="origin"/>
<field name="origin" colspan="3"/>
<label name="description"/>
@@ -23,7 +23,7 @@
<label name="reconciliation"/>
<field name="reconciliation"/>
<label name="amount_second_currency"/>
- <field name="amount_second_currency"/>
+ <field name="amount_second_currency" symbol=""/>
<label name="second_currency"/>
<field name="second_currency"/>
</page>
diff -r b8e750aca405 -r 5e943f95c348 view/move_line_split_start_form.xml
--- a/view/move_line_split_start_form.xml Fri Aug 20 23:45:02 2021 +0200
+++ b/view/move_line_split_start_form.xml Sat Aug 21 09:09:55 2021 +0200
@@ -14,7 +14,7 @@
</group>
<label name="amount"/>
- <field name="amount" symbol="currency"/>
+ <field name="amount"/>
<label name="number"/>
<field name="number"/>
diff -r b8e750aca405 -r 5e943f95c348 view/move_line_split_term_list.xml
--- a/view/move_line_split_term_list.xml Fri Aug 20 23:45:02 2021 +0200
+++ b/view/move_line_split_term_list.xml Sat Aug 21 09:09:55 2021 +0200
@@ -3,5 +3,5 @@
this repository contains the full copyright notices and license terms. -->
<tree editable="1">
<field name="date"/>
- <field name="amount" expand="1" symbol="currency"/>
+ <field name="amount" expand="1"/>
</tree>
diff -r b8e750aca405 -r 5e943f95c348 view/move_line_tree.xml
--- a/view/move_line_tree.xml Fri Aug 20 23:45:02 2021 +0200
+++ b/view/move_line_tree.xml Sat Aug 21 09:09:55 2021 +0200
@@ -7,8 +7,8 @@
<field name="date"/>
<field name="account" expand="1"/>
<field name="party" expand="1"/>
- <field name="debit" sum="Debit" symbol="currency"/>
- <field name="credit" sum="Credit" symbol="currency"/>
+ <field name="debit" sum="Debit"/>
+ <field name="credit" sum="Credit"/>
<field name="tax_lines"/>
<field name="description" expand="1"/>
<field name="move_description" expand="1"/>
diff -r b8e750aca405 -r 5e943f95c348 view/move_line_tree_move.xml
--- a/view/move_line_tree_move.xml Fri Aug 20 23:45:02 2021 +0200
+++ b/view/move_line_tree_move.xml Sat Aug 21 09:09:55 2021 +0200
@@ -5,8 +5,8 @@
<field name="move"/>
<field name="account" expand="1"/>
<field name="party" expand="1"/>
- <field name="debit" sum="Debit" symbol="currency"/>
- <field name="credit" sum="Credit" symbol="currency"/>
+ <field name="debit" sum="Debit"/>
+ <field name="credit" sum="Credit"/>
<field name="tax_lines"/>
<field name="description" expand="1"/>
<field name="reconciliation"/>
diff -r b8e750aca405 -r 5e943f95c348 view/tax_code_tree2.xml
--- a/view/tax_code_tree2.xml Fri Aug 20 23:45:02 2021 +0200
+++ b/view/tax_code_tree2.xml Sat Aug 21 09:09:55 2021 +0200
@@ -4,5 +4,5 @@
<tree keyword_open="1">
<field name="code"/>
<field name="name" expand="1"/>
- <field name="amount" symbol="currency"/>
+ <field name="amount"/>
</tree>