changeset 8c5ca4821be8 in modules/account_payment:default
details:
https://hg.tryton.org/modules/account_payment?cmd=changeset;node=8c5ca4821be8
description:
Allow scheduling payments on their line maturity dates
issue9073
review271051002
diffstat:
CHANGELOG | 2 +
account.py | 20 ++---
tests/scenario_account_payment_planning.rst | 97 +++++++++++++++++++++++++++++
tests/test_account_payment.py | 5 +
4 files changed, 113 insertions(+), 11 deletions(-)
diffs (167 lines):
diff -r 10dd7dce06ff -r 8c5ca4821be8 CHANGELOG
--- a/CHANGELOG Sun Mar 01 16:12:38 2020 +0100
+++ b/CHANGELOG Tue Mar 17 10:08:41 2020 +0100
@@ -1,3 +1,5 @@
+* Allow scheduling payments on their line maturity dates
+
Version 5.4.0 - 2019-11-04
* Bug fixes (see mercurial logs for details)
diff -r 10dd7dce06ff -r 8c5ca4821be8 account.py
--- a/account.py Sun Mar 01 16:12:38 2020 +0100
+++ b/account.py Tue Mar 17 10:08:41 2020 +0100
@@ -184,14 +184,9 @@
"Pay Line"
__name__ = 'account.move.line.pay.start'
date = fields.Date(
- "Date", required=True,
- help="When the payments are scheduled to happen.")
-
- @classmethod
- def default_date(cls):
- pool = Pool()
- Date = pool.get('ir.date')
- return Date.today()
+ "Date",
+ help="When the payments are scheduled to happen.\n"
+ "Leave empty to use the lines' maturity dates.")
class PayLineAskJournal(ModelView):
@@ -339,16 +334,19 @@
else:
kind = 'payable'
journal = journals[self._get_journal_key(line)]
-
- return Payment(
+ payment = Payment(
company=line.move.company,
journal=journal,
party=line.party,
kind=kind,
amount=line.payment_amount,
line=line,
- date=self.start.date,
)
+ date = self.start.date or line.maturity_date
+ # Use default value when empty
+ if date:
+ payment.date = date
+ return payment
def do_pay(self, action):
pool = Pool()
diff -r 10dd7dce06ff -r 8c5ca4821be8 tests/scenario_account_payment_planning.rst
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/scenario_account_payment_planning.rst Tue Mar 17 10:08:41
2020 +0100
@@ -0,0 +1,97 @@
+=========================
+Payment Planning Scenario
+=========================
+
+Imports::
+
+ >>> import datetime
+ >>> from decimal import Decimal
+ >>> from proteus import Model, Wizard
+ >>> from trytond.tests.tools import activate_modules
+ >>> from trytond.modules.company.tests.tools import create_company, \
+ ... get_company
+ >>> from trytond.modules.account.tests.tools import create_fiscalyear, \
+ ... create_chart, get_accounts
+ >>> today = datetime.date.today()
+ >>> tomorrow = today + datetime.timedelta(days=1)
+ >>> next_week = today + datetime.timedelta(weeks=1)
+
+Install account_payment::
+
+ >>> config = activate_modules('account_payment')
+
+Create company::
+
+ >>> _ = create_company()
+ >>> company = get_company()
+
+Create fiscal year::
+
+ >>> fiscalyear = create_fiscalyear(company)
+ >>> fiscalyear.click('create_period')
+
+Create chart of accounts::
+
+ >>> _ = create_chart(company)
+ >>> accounts = get_accounts(company)
+ >>> payable = accounts['payable']
+
+ >>> Journal = Model.get('account.journal')
+ >>> expense, = Journal.find([('code', '=', 'EXP')])
+
+Create payment journal::
+
+ >>> PaymentJournal = Model.get('account.payment.journal')
+ >>> payment_journal = PaymentJournal(name='Manual',
+ ... process_method='manual')
+ >>> payment_journal.save()
+
+Create parties::
+
+ >>> Party = Model.get('party.party')
+ >>> supplier = Party(name='Supplier')
+ >>> supplier.save()
+
+Create payable move::
+
+ >>> Move = Model.get('account.move')
+ >>> move = Move()
+ >>> move.journal = expense
+ >>> line = move.lines.new(account=payable, party=supplier,
+ ... credit=Decimal('50.00'), maturity_date=next_week)
+ >>> line = move.lines.new(account=expense, debit=Decimal('50.00'))
+ >>> move.click('post')
+
+Paying the line without date uses the maturity date::
+
+ >>> Payment = Model.get('account.payment')
+ >>> line, = [l for l in move.lines if l.account == payable]
+ >>> pay_line = Wizard('account.move.line.pay', [line])
+ >>> pay_line.execute('next_')
+ >>> pay_line.execute('next_')
+ >>> payment, = Payment.find()
+ >>> payment.date == next_week
+ True
+
+The date on the payment wizard is used for payment date::
+
+ >>> payment.delete()
+ >>> pay_line = Wizard('account.move.line.pay', [line])
+ >>> pay_line.form.date = tomorrow
+ >>> pay_line.execute('next_')
+ >>> pay_line.execute('next_')
+ >>> payment, = Payment.find()
+ >>> payment.date == tomorrow
+ True
+
+If the line does not have any maturity date it is scheduled for today::
+
+ >>> payment.delete()
+ >>> line.maturity_date = None
+ >>> line.save()
+ >>> pay_line = Wizard('account.move.line.pay', [line])
+ >>> pay_line.execute('next_')
+ >>> pay_line.execute('next_')
+ >>> payment, = line.payments
+ >>> payment.date == today
+ True
diff -r 10dd7dce06ff -r 8c5ca4821be8 tests/test_account_payment.py
--- a/tests/test_account_payment.py Sun Mar 01 16:12:38 2020 +0100
+++ b/tests/test_account_payment.py Tue Mar 17 10:08:41 2020 +0100
@@ -26,4 +26,9 @@
tearDown=doctest_teardown, encoding='utf-8',
checker=doctest_checker,
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
+ suite.addTests(doctest.DocFileSuite(
+ 'scenario_account_payment_planning.rst',
+ tearDown=doctest_teardown, encoding='utf-8',
+ checker=doctest_checker,
+ optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
return suite