Add monetary field
issue10598 review338511002
This commit is contained in:
+7
-9
@@ -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')
|
||||
|
||||
+14
-23
@@ -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:])]
|
||||
|
||||
@@ -7,11 +7,11 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="description" expand="1"/>
|
||||
<field name="party" expand="1"/>
|
||||
<field name="maturity_date"/>
|
||||
<field name="payment_amount" symbol="payment_currency"/>
|
||||
<field name="payment_amount"/>
|
||||
<field name="account" expand="1"/>
|
||||
<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"/>
|
||||
<button name="payment_block"/>
|
||||
<button name="payment_unblock"/>
|
||||
<button name="pay" tree_invisible="1"/>
|
||||
|
||||
@@ -12,8 +12,6 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="line" view_ids="account_payment.move_line_view_list"/>
|
||||
<label name="amount"/>
|
||||
<field name="amount"/>
|
||||
<label name="currency"/>
|
||||
<field name="currency"/>
|
||||
<label name="date"/>
|
||||
<field name="date"/>
|
||||
<notebook colspan="4">
|
||||
|
||||
@@ -5,7 +5,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="journal" expand="1"/>
|
||||
<field name="kind"/>
|
||||
<field name="party" expand="2"/>
|
||||
<field name="amount" symbol="currency"/>
|
||||
<field name="amount"/>
|
||||
<field name="date"/>
|
||||
<field name="state"/>
|
||||
<button name="draft"/>
|
||||
|
||||
Reference in New Issue
Block a user