diff --git a/account.py b/account.py
index 6610abe0a3..0a5e64812d 100644
--- a/account.py
+++ b/account.py
@@ -11,12 +11,13 @@ from trytond import backend
from trytond.i18n import gettext
from trytond.pool import Pool, PoolMeta
from trytond.model import ModelSQL, ModelView, fields
-from trytond.pyson import Eval, If, Bool, Id
+from trytond.pyson import Eval, Id
from trytond.wizard import (Wizard, StateView, StateAction, StateTransition,
Button)
from trytond.transaction import Transaction
from trytond.tools.multivalue import migrate_property
from trytond.modules.company.model import CompanyValueMixin
+from trytond.modules.currency.fields import Monetary
from .exceptions import BlockedWarning, GroupWarning
from .payment import KINDS
@@ -24,17 +25,14 @@ from .payment import KINDS
class MoveLine(metaclass=PoolMeta):
__name__ = 'account.move.line'
- payment_amount = fields.Function(fields.Numeric('Payment Amount',
- digits=(16,
- If(Bool(Eval('second_currency_digits')),
- Eval('second_currency_digits', 2),
- Eval('currency_digits', 2))),
+ payment_amount = fields.Function(Monetary(
+ "Payment Amount",
+ currency='payment_currency', digits='payment_currency',
states={
'invisible': ~Eval('payment_kind'),
},
- depends=['payment_kind', 'second_currency_digits',
- 'currency_digits']), 'get_payment_amount',
- searcher='search_payment_amount')
+ depends=['payment_kind']),
+ 'get_payment_amount', searcher='search_payment_amount')
payment_currency = fields.Function(fields.Many2One(
'currency.currency', "Payment Currency"),
'get_payment_currency')
diff --git a/payment.py b/payment.py
index 02b79bd42a..081342cc13 100644
--- a/payment.py
+++ b/payment.py
@@ -19,6 +19,8 @@ from trytond.wizard import Wizard, StateView, StateAction, Button
from trytond.pool import Pool
from trytond.modules.company.model import (
employee_field, set_employee, reset_employee)
+from trytond.modules.currency.fields import Monetary
+
from .exceptions import OverpayWarning
KINDS = [
@@ -75,22 +77,19 @@ class Group(ModelSQL, ModelView):
('company', '=', Eval('company', -1)),
],
depends=['company'])
- 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')
payment_count = fields.Function(fields.Integer(
"Payment Count",
help="The number of payments in the group."),
'get_payment_aggregated')
- payment_amount = fields.Function(fields.Numeric(
- "Payment Total Amount",
- digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits'],
+ payment_amount = fields.Function(Monetary(
+ "Payment Total Amount", currency='currency', digits='currency',
help="The sum of all payment amounts."),
'get_payment_aggregated')
- payment_amount_succeeded = fields.Function(fields.Numeric(
- "Payment Succeeded",
- digits=(16, Eval('currency_digits', 2)),
- depends=['currency_digits'],
+ payment_amount_succeeded = fields.Function(Monetary(
+ "Payment Succeeded", currency='currency', digits='currency',
help="The sum of the amounts of the successful payments."),
'get_payment_aggregated')
payment_complete = fields.Function(fields.Boolean(
@@ -225,9 +224,9 @@ class Group(ModelSQL, ModelView):
return []
@fields.depends('journal')
- def on_change_with_currency_digits(self, name=None):
+ def on_change_with_currency(self, name=None):
if self.journal:
- return self.journal.currency.digits
+ return self.journal.currency.id
_STATES = {
@@ -250,8 +249,6 @@ class Payment(Workflow, ModelSQL, ModelView):
currency = fields.Function(fields.Many2One('currency.currency',
'Currency'), 'on_change_with_currency',
searcher='search_currency')
- currency_digits = fields.Function(fields.Integer('Currency Digits'),
- 'on_change_with_currency_digits')
kind = fields.Selection(KINDS, 'Kind', required=True,
states=_STATES, depends=_DEPENDS)
party = fields.Many2One(
@@ -261,9 +258,9 @@ class Payment(Workflow, ModelSQL, ModelView):
},
depends=_DEPENDS + ['company'])
date = fields.Date('Date', required=True, states=_STATES, depends=_DEPENDS)
- amount = fields.Numeric('Amount', required=True,
- digits=(16, Eval('currency_digits', 2)), states=_STATES,
- depends=_DEPENDS + ['currency_digits'])
+ amount = Monetary(
+ "Amount", currency='currency', digits='currency', required=True,
+ states=_STATES, depends=_DEPENDS)
line = fields.Many2One('account.move.line', 'Line', ondelete='RESTRICT',
domain=[
('move.company', '=', Eval('company', -1)),
@@ -394,12 +391,6 @@ class Payment(Workflow, ModelSQL, ModelView):
if self.journal:
return self.journal.currency.id
- @fields.depends('journal')
- def on_change_with_currency_digits(self, name=None):
- if self.journal:
- return self.journal.currency.digits
- return 2
-
@classmethod
def search_currency(cls, name, clause):
return [('journal.' + clause[0],) + tuple(clause[1:])]
diff --git a/view/move_line_list.xml b/view/move_line_list.xml
index 46fa2f1c13..2751de9ccc 100644
--- a/view/move_line_list.xml
+++ b/view/move_line_list.xml
@@ -7,11 +7,11 @@ this repository contains the full copyright notices and license terms. -->
-
+
-
-
-
+
+
+
diff --git a/view/payment_form.xml b/view/payment_form.xml
index 552b6f5d9e..017ffe827c 100644
--- a/view/payment_form.xml
+++ b/view/payment_form.xml
@@ -12,8 +12,6 @@ this repository contains the full copyright notices and license terms. -->
-
-
diff --git a/view/payment_list.xml b/view/payment_list.xml
index 505c6f89b8..6641f0d2f1 100644
--- a/view/payment_list.xml
+++ b/view/payment_list.xml
@@ -5,7 +5,7 @@ this repository contains the full copyright notices and license terms. -->
-
+