diff --git a/CHANGELOG b/CHANGELOG index 448abd4a70..65a10fd7b8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 --git a/account.py b/account.py index 75a30d7ccd..3a480b7cfb 100644 --- a/account.py +++ b/account.py @@ -184,14 +184,9 @@ class PayLineStart(ModelView): "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 @@ class PayLine(Wizard): 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 --git a/tests/scenario_account_payment_planning.rst b/tests/scenario_account_payment_planning.rst new file mode 100644 index 0000000000..4223da8864 --- /dev/null +++ b/tests/scenario_account_payment_planning.rst @@ -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 --git a/tests/test_account_payment.py b/tests/test_account_payment.py index b337e5f62e..71aa085648 100644 --- a/tests/test_account_payment.py +++ b/tests/test_account_payment.py @@ -26,4 +26,9 @@ def suite(): 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