first commit
This commit is contained in:
2
modules/account_payment_clearing/tests/__init__.py
Normal file
2
modules/account_payment_clearing/tests/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,109 @@
|
||||
==================================
|
||||
Negative Payment Clearing Scenario
|
||||
==================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime as dt
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model, Wizard
|
||||
>>> from trytond.modules.account.tests.tools import (
|
||||
... create_chart, create_fiscalyear, get_accounts)
|
||||
>>> from trytond.modules.company.tests.tools import create_company
|
||||
>>> from trytond.tests.tools import activate_modules
|
||||
|
||||
>>> today = dt.date.today()
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules(
|
||||
... 'account_payment_clearing', create_company, create_chart)
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = create_fiscalyear()
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
>>> receivable = accounts['receivable']
|
||||
>>> payable = accounts['payable']
|
||||
>>> cash = accounts['cash']
|
||||
>>> expense = accounts['expense']
|
||||
|
||||
>>> Account = Model.get('account.account')
|
||||
>>> bank_clearing = Account(parent=payable.parent)
|
||||
>>> bank_clearing.name = 'Bank Clearing'
|
||||
>>> bank_clearing.type = payable.type
|
||||
>>> bank_clearing.reconcile = True
|
||||
>>> bank_clearing.deferral = True
|
||||
>>> bank_clearing.save()
|
||||
|
||||
>>> Journal = Model.get('account.journal')
|
||||
>>> expense_journal, = Journal.find([('code', '=', 'EXP')])
|
||||
|
||||
Create payment journal::
|
||||
|
||||
>>> PaymentJournal = Model.get('account.payment.journal')
|
||||
>>> payment_journal = PaymentJournal(name='Manual',
|
||||
... process_method='manual', clearing_journal=expense_journal,
|
||||
... clearing_account=bank_clearing)
|
||||
>>> 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_journal
|
||||
>>> line = move.lines.new(
|
||||
... account=payable, party=supplier, maturity_date=today,
|
||||
... debit=Decimal('-50.00'))
|
||||
>>> line = move.lines.new(account=expense, credit=Decimal('-50.00'))
|
||||
>>> move.click('post')
|
||||
>>> payable.reload()
|
||||
>>> payable.balance
|
||||
Decimal('-50.00')
|
||||
|
||||
Pay the line::
|
||||
|
||||
>>> 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.form.journal = payment_journal
|
||||
>>> pay_line.execute('next_')
|
||||
>>> payment, = Payment.find([('state', '=', 'draft')])
|
||||
>>> payment.amount
|
||||
Decimal('50.00')
|
||||
>>> payment.click('submit')
|
||||
>>> payment.click('approve')
|
||||
>>> payment.state
|
||||
'approved'
|
||||
>>> process_payment = payment.click('process_wizard')
|
||||
>>> payment.state
|
||||
'processing'
|
||||
|
||||
Succeed payment::
|
||||
|
||||
>>> succeed = payment.click('succeed_wizard')
|
||||
>>> succeed.execute('succeed')
|
||||
>>> payment.state
|
||||
'succeeded'
|
||||
>>> payment.clearing_move.state
|
||||
'draft'
|
||||
>>> payable.reload()
|
||||
>>> payable.balance
|
||||
Decimal('0.00')
|
||||
>>> bank_clearing.reload()
|
||||
>>> bank_clearing.balance
|
||||
Decimal('-50.00')
|
||||
>>> bool(payment.line.reconciliation)
|
||||
True
|
||||
@@ -0,0 +1,476 @@
|
||||
=========================
|
||||
Payment Clearing Scenario
|
||||
=========================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime as dt
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model, Wizard
|
||||
>>> from trytond.modules.account.tests.tools import (
|
||||
... create_chart, create_fiscalyear, get_accounts)
|
||||
>>> from trytond.modules.account_invoice.tests.tools import (
|
||||
... set_fiscalyear_invoice_sequences)
|
||||
>>> from trytond.modules.company.tests.tools import create_company, get_company
|
||||
>>> from trytond.modules.currency.tests.tools import get_currency
|
||||
>>> from trytond.tests.tools import activate_modules, assertEqual
|
||||
|
||||
>>> today = dt.date.today()
|
||||
>>> yesterday = today - dt.timedelta(days=1)
|
||||
>>> first = today + dt.timedelta(days=1)
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules(
|
||||
... ['account_payment_clearing', 'account_statement'],
|
||||
... create_company, create_chart)
|
||||
|
||||
Get company::
|
||||
|
||||
>>> company = get_company()
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = set_fiscalyear_invoice_sequences(
|
||||
... create_fiscalyear(today=(yesterday, first)))
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
>>> receivable = accounts['receivable']
|
||||
>>> revenue = accounts['revenue']
|
||||
>>> expense = accounts['expense']
|
||||
>>> payable = accounts['payable']
|
||||
>>> cash = accounts['cash']
|
||||
|
||||
>>> Account = Model.get('account.account')
|
||||
>>> bank_clearing = Account(parent=payable.parent)
|
||||
>>> bank_clearing.name = 'Bank Clearing'
|
||||
>>> bank_clearing.type = payable.type
|
||||
>>> bank_clearing.reconcile = True
|
||||
>>> bank_clearing.deferral = True
|
||||
>>> bank_clearing.save()
|
||||
|
||||
>>> Journal = Model.get('account.journal')
|
||||
>>> expense_journal, = Journal.find([('code', '=', 'EXP')])
|
||||
>>> revenue_journal, = Journal.find([('code', '=', 'REV')])
|
||||
|
||||
Create payment journal::
|
||||
|
||||
>>> PaymentJournal = Model.get('account.payment.journal')
|
||||
>>> payment_journal = PaymentJournal(name='Manual',
|
||||
... process_method='manual',
|
||||
... clearing_journal=expense_journal,
|
||||
... clearing_account=bank_clearing,
|
||||
... clearing_posting_delay=dt.timedelta(1))
|
||||
>>> payment_journal.save()
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> supplier = Party(name='Supplier')
|
||||
>>> supplier.save()
|
||||
>>> customer = Party(name='Customer')
|
||||
>>> customer.save()
|
||||
|
||||
Create payable move::
|
||||
|
||||
>>> Move = Model.get('account.move')
|
||||
>>> move = Move()
|
||||
>>> move.journal = expense_journal
|
||||
>>> line = move.lines.new(
|
||||
... account=payable, party=supplier, maturity_date=today,
|
||||
... credit=Decimal('50.00'))
|
||||
>>> line = move.lines.new(account=expense, debit=Decimal('50.00'))
|
||||
>>> move.click('post')
|
||||
>>> payable.reload()
|
||||
>>> payable.balance
|
||||
Decimal('-50.00')
|
||||
|
||||
Partially pay the line::
|
||||
|
||||
>>> 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.form.journal = payment_journal
|
||||
>>> pay_line.execute('next_')
|
||||
>>> payment, = Payment.find()
|
||||
>>> payment.amount = Decimal('30.0')
|
||||
>>> payment.click('submit')
|
||||
>>> payment.click('approve')
|
||||
>>> payment.state
|
||||
'approved'
|
||||
>>> process_payment = payment.click('process_wizard')
|
||||
>>> payment.state
|
||||
'processing'
|
||||
|
||||
Succeed payment::
|
||||
|
||||
>>> succeed = payment.click('succeed_wizard')
|
||||
>>> succeed.form.date = first
|
||||
>>> succeed.execute('succeed')
|
||||
>>> payment.state
|
||||
'succeeded'
|
||||
>>> assertEqual(payment.clearing_move.date, first)
|
||||
>>> payment.clearing_move.state
|
||||
'draft'
|
||||
>>> bool(payment.clearing_reconciled)
|
||||
False
|
||||
>>> payable.reload()
|
||||
>>> payable.balance
|
||||
Decimal('-20.00')
|
||||
>>> bank_clearing.reload()
|
||||
>>> bank_clearing.balance
|
||||
Decimal('-30.00')
|
||||
>>> payment.line.reconciliation
|
||||
|
||||
Fail payment::
|
||||
|
||||
>>> payment.click('fail')
|
||||
>>> payment.state
|
||||
'failed'
|
||||
>>> payment.clearing_move
|
||||
>>> bool(payment.clearing_reconciled)
|
||||
False
|
||||
>>> payment.line.reconciliation
|
||||
>>> payable.reload()
|
||||
>>> payable.balance
|
||||
Decimal('-50.00')
|
||||
>>> bank_clearing.reload()
|
||||
>>> bank_clearing.balance
|
||||
Decimal('0.00')
|
||||
|
||||
Pay the line::
|
||||
|
||||
>>> 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.form.journal = payment_journal
|
||||
>>> pay_line.execute('next_')
|
||||
>>> payment, = Payment.find([('state', '=', 'draft')])
|
||||
>>> payment.amount
|
||||
Decimal('50.00')
|
||||
>>> payment.click('submit')
|
||||
>>> payment.click('approve')
|
||||
>>> payment.state
|
||||
'approved'
|
||||
>>> process_payment = payment.click('process_wizard')
|
||||
>>> payment.state
|
||||
'processing'
|
||||
|
||||
Succeed payment::
|
||||
|
||||
>>> succeed = payment.click('succeed_wizard')
|
||||
>>> succeed.execute('succeed')
|
||||
>>> payment.state
|
||||
'succeeded'
|
||||
>>> payment.clearing_move.state
|
||||
'draft'
|
||||
>>> payable.reload()
|
||||
>>> payable.balance
|
||||
Decimal('0.00')
|
||||
>>> bank_clearing.reload()
|
||||
>>> bank_clearing.balance
|
||||
Decimal('-50.00')
|
||||
>>> bool(payment.line.reconciliation)
|
||||
True
|
||||
|
||||
Fail payment::
|
||||
|
||||
>>> payment.click('fail')
|
||||
>>> payment.state
|
||||
'failed'
|
||||
>>> payment.clearing_move
|
||||
>>> payment.line.reconciliation
|
||||
|
||||
Succeed payment and post clearing::
|
||||
|
||||
>>> succeed = payment.click('succeed_wizard')
|
||||
>>> succeed.form.date = yesterday
|
||||
>>> succeed.execute('succeed')
|
||||
>>> payment.state
|
||||
'succeeded'
|
||||
|
||||
>>> Cron = Model.get('ir.cron')
|
||||
>>> Company = Model.get('company.company')
|
||||
>>> cron_post_clearing_moves, = Cron.find([
|
||||
... ('method', '=',
|
||||
... 'account.payment.journal|cron_post_clearing_moves'),
|
||||
... ])
|
||||
>>> cron_post_clearing_moves.companies.append(Company(company.id))
|
||||
>>> cron_post_clearing_moves.click('run_once')
|
||||
|
||||
>>> payment.reload()
|
||||
>>> clearing_move = payment.clearing_move
|
||||
>>> clearing_move.state
|
||||
'posted'
|
||||
|
||||
Fail payment with posted clearing::
|
||||
|
||||
>>> payment.click('fail')
|
||||
>>> payment.state
|
||||
'failed'
|
||||
>>> payment.clearing_move
|
||||
>>> bool(payment.clearing_reconciled)
|
||||
False
|
||||
>>> payment.line.reconciliation
|
||||
>>> clearing_move.reload()
|
||||
>>> line, = [l for l in clearing_move.lines
|
||||
... if l.account == payment.line.account]
|
||||
>>> bool(line.reconciliation)
|
||||
True
|
||||
|
||||
Succeed payment to use on statement::
|
||||
|
||||
>>> succeed = payment.click('succeed_wizard')
|
||||
>>> succeed.execute('succeed')
|
||||
>>> payment.state
|
||||
'succeeded'
|
||||
|
||||
Create statement::
|
||||
|
||||
>>> StatementJournal = Model.get('account.statement.journal')
|
||||
>>> Statement = Model.get('account.statement')
|
||||
|
||||
>>> account_journal, = Journal.find([('code', '=', 'STA')], limit=1)
|
||||
>>> statement_journal = StatementJournal(name='Test',
|
||||
... journal=account_journal,
|
||||
... account=cash,
|
||||
... )
|
||||
>>> statement_journal.save()
|
||||
|
||||
>>> statement = Statement(name='test',
|
||||
... journal=statement_journal,
|
||||
... start_balance=Decimal('0.00'),
|
||||
... end_balance=Decimal('-50.00'),
|
||||
... )
|
||||
|
||||
Create a line for the payment::
|
||||
|
||||
>>> line = statement.lines.new(date=today)
|
||||
>>> line.amount = Decimal('-50.00')
|
||||
>>> line.related_to = payment
|
||||
>>> assertEqual(line.party, supplier)
|
||||
>>> assertEqual(line.account, bank_clearing)
|
||||
|
||||
Remove the party must remove payment::
|
||||
|
||||
>>> line.party = None
|
||||
>>> line.related_to
|
||||
|
||||
>>> line.related_to = payment
|
||||
|
||||
Change account must remove payment::
|
||||
|
||||
>>> line.account = receivable
|
||||
>>> line.related_to
|
||||
|
||||
>>> line.account = None
|
||||
>>> line.related_to = payment
|
||||
|
||||
Validate statement::
|
||||
|
||||
>>> statement.click('validate_statement')
|
||||
>>> statement.state
|
||||
'validated'
|
||||
>>> line, = statement.lines
|
||||
>>> move_line, = [l for l in line.move.lines
|
||||
... if l.account == bank_clearing]
|
||||
>>> bool(move_line.reconciliation)
|
||||
True
|
||||
>>> bank_clearing.reload()
|
||||
>>> bank_clearing.balance
|
||||
Decimal('0.00')
|
||||
>>> payment.reload()
|
||||
>>> bool(payment.clearing_reconciled)
|
||||
True
|
||||
>>> bool(payment.group.clearing_reconciled)
|
||||
True
|
||||
|
||||
Unreconcile payment clearing to allow reimbursement::
|
||||
|
||||
>>> move_line.reconciliation.delete()
|
||||
>>> payment.reload()
|
||||
>>> bool(payment.clearing_reconciled)
|
||||
False
|
||||
>>> bool(payment.group.clearing_reconciled)
|
||||
False
|
||||
|
||||
Create a statement that reimburse the payment group::
|
||||
|
||||
>>> statement = Statement(name='test',
|
||||
... journal=statement_journal,
|
||||
... start_balance=Decimal('-50.00'),
|
||||
... end_balance=Decimal('0.00'),
|
||||
... )
|
||||
>>> line = statement.lines.new(date=today)
|
||||
>>> line.related_to = payment.group
|
||||
>>> assertEqual(line.account, bank_clearing)
|
||||
>>> line.amount = Decimal('50.00')
|
||||
|
||||
>>> statement.click('validate_statement')
|
||||
>>> statement.state
|
||||
'validated'
|
||||
|
||||
Payment must be failed::
|
||||
|
||||
>>> payment.reload()
|
||||
>>> payment.state
|
||||
'failed'
|
||||
|
||||
|
||||
Payment in a foreign currency
|
||||
-----------------------------
|
||||
|
||||
Create a payment journal in Euro::
|
||||
|
||||
>>> euro = get_currency('EUR')
|
||||
>>> euro_payment_journal = PaymentJournal(
|
||||
... name='Euro Payments', process_method='manual', currency=euro,
|
||||
... clearing_journal=expense_journal, clearing_account=bank_clearing)
|
||||
>>> euro_payment_journal.save()
|
||||
|
||||
Create a payable move::
|
||||
|
||||
>>> move = Move()
|
||||
>>> move.journal = expense_journal
|
||||
>>> line = move.lines.new(
|
||||
... account=payable, party=supplier, maturity_date=today,
|
||||
... credit=Decimal('20.00'),
|
||||
... amount_second_currency=Decimal('-40.00'), second_currency=euro)
|
||||
>>> line = move.lines.new(
|
||||
... account=expense, debit=Decimal('20.00'),
|
||||
... amount_second_currency=Decimal('40.00'), second_currency=euro)
|
||||
>>> move.click('post')
|
||||
|
||||
Pay the line::
|
||||
|
||||
>>> 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.form.journal = euro_payment_journal
|
||||
>>> pay_line.execute('next_')
|
||||
>>> payment, = Payment.find([('state', '=', 'draft')])
|
||||
>>> payment.amount
|
||||
Decimal('40.00')
|
||||
>>> payment.click('submit')
|
||||
>>> payment.click('approve')
|
||||
>>> process_payment = payment.click('process_wizard')
|
||||
>>> payment.state
|
||||
'processing'
|
||||
|
||||
Succeed payment::
|
||||
|
||||
>>> succeed = payment.click('succeed_wizard')
|
||||
>>> succeed.execute('succeed')
|
||||
>>> debit_line, = [l for l in payment.clearing_move.lines if l.debit > 0]
|
||||
>>> debit_line.debit
|
||||
Decimal('20.00')
|
||||
>>> debit_line.amount_second_currency
|
||||
Decimal('40.00')
|
||||
|
||||
Create receivable move::
|
||||
|
||||
>>> move = Move()
|
||||
>>> move.journal = revenue_journal
|
||||
>>> line = move.lines.new(
|
||||
... account=receivable, party=customer, maturity_date=today,
|
||||
... debit=Decimal('50.00'), second_currency=euro,
|
||||
... amount_second_currency=Decimal('100.0'))
|
||||
>>> line = move.lines.new(account=revenue, credit=Decimal('50.00'))
|
||||
>>> move.click('post')
|
||||
>>> receivable.reload()
|
||||
>>> receivable.balance
|
||||
Decimal('50.00')
|
||||
|
||||
Pay the line::
|
||||
|
||||
>>> Payment = Model.get('account.payment')
|
||||
>>> line, = [l for l in move.lines if l.account == receivable]
|
||||
>>> pay_line = Wizard('account.move.line.pay', [line])
|
||||
>>> pay_line.execute('next_')
|
||||
>>> pay_line.form.journal = euro_payment_journal
|
||||
>>> pay_line.execute('next_')
|
||||
>>> payment, = Payment.find([('state', '=', 'draft')])
|
||||
>>> payment.amount
|
||||
Decimal('100.0')
|
||||
>>> payment.click('submit')
|
||||
>>> process_payment = payment.click('process_wizard')
|
||||
>>> payment.state
|
||||
'processing'
|
||||
|
||||
Succeed payment::
|
||||
|
||||
>>> succeed = payment.click('succeed_wizard')
|
||||
>>> succeed.execute('succeed')
|
||||
>>> credit_line, = [l for l in payment.clearing_move.lines if l.credit > 0]
|
||||
>>> credit_line.credit
|
||||
Decimal('50.00')
|
||||
>>> credit_line.amount_second_currency
|
||||
Decimal('-100.0')
|
||||
|
||||
Validate Statement with processing payment
|
||||
--------------------------------------------
|
||||
|
||||
Create a payable move::
|
||||
|
||||
>>> move = Move()
|
||||
>>> move.journal = expense_journal
|
||||
>>> line = move.lines.new(
|
||||
... account=payable, party=supplier, maturity_date=today,
|
||||
... credit=Decimal('50.00'))
|
||||
>>> line = move.lines.new(account=expense, debit=Decimal('50.00'))
|
||||
>>> move.click('post')
|
||||
|
||||
Create a processing payment for the move::
|
||||
|
||||
>>> 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.form.journal = payment_journal
|
||||
>>> pay_line.execute('next_')
|
||||
>>> payment, = Payment.find([('line', '=', line.id)])
|
||||
>>> payment.click('submit')
|
||||
>>> payment.click('approve')
|
||||
>>> payment.state
|
||||
'approved'
|
||||
>>> process_payment = payment.click('process_wizard')
|
||||
>>> payment.state
|
||||
'processing'
|
||||
|
||||
Create statement for the payment::
|
||||
|
||||
>>> statement = Statement(name='test',
|
||||
... journal=statement_journal,
|
||||
... start_balance=Decimal('0.00'),
|
||||
... end_balance=Decimal('-50.00'))
|
||||
>>> line = statement.lines.new(date=yesterday)
|
||||
>>> line.amount = Decimal('-50.00')
|
||||
>>> line.related_to = payment
|
||||
>>> assertEqual(line.party, supplier)
|
||||
>>> assertEqual(line.account, bank_clearing)
|
||||
>>> statement.save()
|
||||
|
||||
Validate statement and check the payment is confirmed::
|
||||
|
||||
>>> statement.click('validate_statement')
|
||||
>>> statement.state
|
||||
'validated'
|
||||
>>> line, = statement.lines
|
||||
>>> move_line, = [l for l in line.move.lines
|
||||
... if l.account == bank_clearing]
|
||||
>>> bool(move_line.reconciliation)
|
||||
True
|
||||
>>> payment.reload()
|
||||
>>> payment.state
|
||||
'succeeded'
|
||||
>>> bool(payment.clearing_reconciled)
|
||||
True
|
||||
>>> debit_line, = [l for l in payment.clearing_move.lines if l.debit > 0]
|
||||
>>> debit_line.debit
|
||||
Decimal('50.00')
|
||||
>>> assertEqual(debit_line.date, yesterday)
|
||||
@@ -0,0 +1,169 @@
|
||||
======================================
|
||||
Payment Clearing Invoice Amount to Pay
|
||||
======================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model, Wizard
|
||||
>>> from trytond.modules.account.tests.tools import (
|
||||
... create_chart, create_fiscalyear, get_accounts)
|
||||
>>> from trytond.modules.account_invoice.tests.tools import (
|
||||
... set_fiscalyear_invoice_sequences)
|
||||
>>> from trytond.modules.company.tests.tools import create_company
|
||||
>>> from trytond.tests.tools import activate_modules
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules(
|
||||
... ['account_payment_clearing', 'account_invoice'],
|
||||
... create_company, create_chart)
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = set_fiscalyear_invoice_sequences(
|
||||
... create_fiscalyear())
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
>>> receivable = accounts['receivable']
|
||||
>>> revenue = accounts['revenue']
|
||||
>>> expense = accounts['expense']
|
||||
>>> payable = accounts['payable']
|
||||
>>> cash = accounts['cash']
|
||||
|
||||
>>> Account = Model.get('account.account')
|
||||
>>> bank_clearing = Account(parent=payable.parent)
|
||||
>>> bank_clearing.name = 'Bank Clearing'
|
||||
>>> bank_clearing.type = payable.type
|
||||
>>> bank_clearing.reconcile = True
|
||||
>>> bank_clearing.deferral = True
|
||||
>>> bank_clearing.save()
|
||||
|
||||
>>> Journal = Model.get('account.journal')
|
||||
>>> expense_journal, = Journal.find([('code', '=', 'EXP')])
|
||||
>>> revenue_journal, = Journal.find([('code', '=', 'REV')])
|
||||
|
||||
Create payment journal::
|
||||
|
||||
>>> PaymentJournal = Model.get('account.payment.journal')
|
||||
>>> payment_journal = PaymentJournal(name='No Clearing',
|
||||
... process_method='manual')
|
||||
>>> payment_journal.save()
|
||||
>>> clearing_journal = PaymentJournal(name='Clearing',
|
||||
... process_method='manual',
|
||||
... clearing_journal=expense_journal,
|
||||
... clearing_account=bank_clearing)
|
||||
>>> clearing_journal.save()
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> supplier = Party(name='Supplier')
|
||||
>>> supplier.save()
|
||||
>>> customer = Party(name='Customer')
|
||||
>>> customer.save()
|
||||
|
||||
Create and pay an invoice without clearing::
|
||||
|
||||
>>> Invoice = Model.get('account.invoice')
|
||||
>>> invoice = Invoice()
|
||||
>>> invoice.party = customer
|
||||
>>> line = invoice.lines.new()
|
||||
>>> line.account = revenue
|
||||
>>> line.quantity = 1
|
||||
>>> line.unit_price = Decimal('100')
|
||||
>>> invoice.save()
|
||||
>>> invoice.click('post')
|
||||
>>> invoice.amount_to_pay
|
||||
Decimal('100.00')
|
||||
|
||||
>>> paid_line, = [l for l in invoice.move.lines if l.account == receivable]
|
||||
>>> pay_line = Wizard('account.move.line.pay', [paid_line])
|
||||
>>> pay_line.execute('next_')
|
||||
>>> pay_line.form.journal = payment_journal
|
||||
>>> pay_line.execute('next_')
|
||||
|
||||
>>> Payment = Model.get('account.payment')
|
||||
>>> payment, = Payment.find()
|
||||
>>> payment.click('submit')
|
||||
>>> payment.state
|
||||
'submitted'
|
||||
>>> process_payment = payment.click('process_wizard')
|
||||
>>> succeed = payment.click('succeed_wizard')
|
||||
>>> succeed.execute('succeed')
|
||||
|
||||
>>> invoice.reload()
|
||||
>>> invoice.state
|
||||
'posted'
|
||||
>>> invoice.amount_to_pay
|
||||
Decimal('0.00')
|
||||
|
||||
Create an invoice and pay it::
|
||||
|
||||
>>> invoice1 = Invoice()
|
||||
>>> invoice1.party = customer
|
||||
>>> line = invoice1.lines.new()
|
||||
>>> line.account = revenue
|
||||
>>> line.quantity = 1
|
||||
>>> line.unit_price = Decimal('100')
|
||||
>>> invoice1.save()
|
||||
>>> invoice1.click('post')
|
||||
>>> invoice1.amount_to_pay
|
||||
Decimal('100.00')
|
||||
|
||||
>>> paid_line, = [l for l in invoice1.move.lines if l.account == receivable]
|
||||
>>> pay_line = Wizard('account.move.line.pay', [paid_line])
|
||||
>>> pay_line.execute('next_')
|
||||
>>> pay_line.form.journal = clearing_journal
|
||||
>>> pay_line.execute('next_')
|
||||
|
||||
>>> payment, = Payment.find([('state', '=', 'draft')])
|
||||
>>> payment.click('submit')
|
||||
>>> payment.state
|
||||
'submitted'
|
||||
>>> process_payment = payment.click('process_wizard')
|
||||
>>> succeed = payment.click('succeed_wizard')
|
||||
>>> succeed.execute('succeed')
|
||||
|
||||
>>> invoice1.reload()
|
||||
>>> invoice1.state
|
||||
'paid'
|
||||
>>> invoice1.amount_to_pay
|
||||
Decimal('0')
|
||||
|
||||
Unreconcile the payment line and check the amount to pay::
|
||||
|
||||
>>> other_line, = [l for l in paid_line.reconciliation.lines
|
||||
... if l != paid_line]
|
||||
>>> unreconcile = Wizard('account.move.unreconcile_lines', [paid_line])
|
||||
>>> invoice1.reload()
|
||||
>>> invoice1.state
|
||||
'posted'
|
||||
>>> invoice1.amount_to_pay
|
||||
Decimal('0.00')
|
||||
|
||||
Create a second invoice and reconcile its line to pay with the payment::
|
||||
|
||||
>>> invoice2 = Invoice()
|
||||
>>> invoice2.party = customer
|
||||
>>> line = invoice2.lines.new()
|
||||
>>> line.account = revenue
|
||||
>>> line.quantity = 1
|
||||
>>> line.unit_price = Decimal('100')
|
||||
>>> invoice2.save()
|
||||
>>> invoice2.click('post')
|
||||
|
||||
>>> inv2_line, = [l for l in invoice2.move.lines if l.account == receivable]
|
||||
>>> reconcile = Wizard(
|
||||
... 'account.move.reconcile_lines', [inv2_line, other_line])
|
||||
|
||||
>>> invoice1.reload()
|
||||
>>> invoice1.amount_to_pay
|
||||
Decimal('100.00')
|
||||
>>> invoice2.reload()
|
||||
>>> invoice2.amount_to_pay
|
||||
Decimal('0')
|
||||
@@ -0,0 +1,144 @@
|
||||
=====================================================
|
||||
Account Payment Clearing with Statement Rule Scenario
|
||||
=====================================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime as dt
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model
|
||||
>>> from trytond.modules.account.tests.tools import (
|
||||
... create_chart, create_fiscalyear, get_accounts)
|
||||
>>> from trytond.modules.account_invoice.tests.tools import (
|
||||
... set_fiscalyear_invoice_sequences)
|
||||
>>> from trytond.modules.company.tests.tools import create_company
|
||||
>>> from trytond.tests.tools import activate_modules, assertEqual
|
||||
|
||||
>>> today = dt.date.today()
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules(
|
||||
... ['account_payment_clearing',
|
||||
... 'account_statement', 'account_statement_rule'],
|
||||
... create_company, create_chart)
|
||||
|
||||
>>> Account = Model.get('account.account')
|
||||
>>> AccountJournal = Model.get('account.journal')
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> Payment = Model.get('account.payment')
|
||||
>>> PaymentJournal = Model.get('account.payment.journal')
|
||||
>>> Statement = Model.get('account.statement')
|
||||
>>> StatementJournal = Model.get('account.statement.journal')
|
||||
>>> StatementRule = Model.get('account.statement.rule')
|
||||
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = set_fiscalyear_invoice_sequences(
|
||||
... create_fiscalyear())
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
|
||||
>>> bank_clearing = Account(parent=accounts['payable'].parent)
|
||||
>>> bank_clearing.name = "Bank Clearing"
|
||||
>>> bank_clearing.type = accounts['payable'].type
|
||||
>>> bank_clearing.reconcile = True
|
||||
>>> bank_clearing.deferral = True
|
||||
>>> bank_clearing.save()
|
||||
|
||||
Create journals::
|
||||
|
||||
>>> expense_journal, = AccountJournal.find([('code', '=', 'EXP')])
|
||||
|
||||
>>> payment_journal = PaymentJournal(
|
||||
... name="Manual",
|
||||
... process_method='manual',
|
||||
... clearing_journal=expense_journal,
|
||||
... clearing_account=bank_clearing)
|
||||
>>> payment_journal.save()
|
||||
|
||||
>>> account_journal, = AccountJournal.find([('code', '=', 'STA')], limit=1)
|
||||
|
||||
>>> statement_journal = StatementJournal(
|
||||
... name="Statement",
|
||||
... journal=account_journal,
|
||||
... validation='amount',
|
||||
... account=accounts['cash'])
|
||||
>>> statement_journal.save()
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> customer = Party(name="Customer")
|
||||
>>> customer.save()
|
||||
|
||||
Create statement rules for payment and group::
|
||||
|
||||
>>> statement_rule = StatementRule(name="Rule Payment")
|
||||
>>> statement_rule.description = r"Payment: *(?P<payment>.*)"
|
||||
>>> statement_line = statement_rule.lines.new()
|
||||
>>> statement_line.amount = "pending"
|
||||
>>> statement_rule.save()
|
||||
|
||||
>>> statement_rule = StatementRule(name="Rule Payment Group")
|
||||
>>> statement_rule.description = r"Payment Group: *(?P<payment_group>.*)"
|
||||
>>> statement_line = statement_rule.lines.new()
|
||||
>>> statement_line.amount = "pending"
|
||||
>>> statement_rule.save()
|
||||
|
||||
Receive 2 payments::
|
||||
|
||||
>>> payment1 = Payment(kind='receivable')
|
||||
>>> payment1.journal = payment_journal
|
||||
>>> payment1.party = customer
|
||||
>>> payment1.amount = Decimal('100.00')
|
||||
>>> payment1.click('submit')
|
||||
>>> process1_payment = payment1.click('process_wizard')
|
||||
>>> payment1.state
|
||||
'processing'
|
||||
|
||||
>>> payment2 = Payment(kind='receivable')
|
||||
>>> payment2.journal = payment_journal
|
||||
>>> payment2.party = customer
|
||||
>>> payment2.amount = Decimal('200.00')
|
||||
>>> payment2.click('submit')
|
||||
>>> process2_payment = payment2.click('process_wizard')
|
||||
>>> payment2.state
|
||||
'processing'
|
||||
|
||||
Create a statement with payment and group as origins::
|
||||
|
||||
>>> statement = Statement(
|
||||
... name="001",
|
||||
... journal=statement_journal,
|
||||
... total_amount=Decimal('300.00'))
|
||||
>>> origin = statement.origins.new()
|
||||
>>> origin.date = today
|
||||
>>> origin.amount = Decimal('100.00')
|
||||
>>> origin.description = "Payment: %s" % payment1.rec_name
|
||||
>>> origin = statement.origins.new()
|
||||
>>> origin.date = today
|
||||
>>> origin.amount = Decimal('200.00')
|
||||
>>> origin.description = "Payment Group: %s" % payment2.group.rec_name
|
||||
>>> statement.click('apply_rules')
|
||||
>>> line1, line2 = statement.lines
|
||||
>>> assertEqual(line1.account, bank_clearing)
|
||||
>>> assertEqual(line1.related_to, payment1)
|
||||
>>> assertEqual(line1.account, bank_clearing)
|
||||
>>> assertEqual(line2.related_to, payment2.group)
|
||||
|
||||
Check payments are succeeded after validation::
|
||||
|
||||
>>> statement.click('validate_statement')
|
||||
>>> statement.state
|
||||
'validated'
|
||||
>>> payment1.reload()
|
||||
>>> payment1.state
|
||||
'succeeded'
|
||||
>>> payment2.reload()
|
||||
>>> payment2.state
|
||||
'succeeded'
|
||||
14
modules/account_payment_clearing/tests/test_module.py
Normal file
14
modules/account_payment_clearing/tests/test_module.py
Normal file
@@ -0,0 +1,14 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
from trytond.modules.company.tests import CompanyTestMixin
|
||||
from trytond.tests.test_tryton import ModuleTestCase
|
||||
|
||||
|
||||
class AccountPaymentTestCase(CompanyTestMixin, ModuleTestCase):
|
||||
'Test Account Payment module'
|
||||
module = 'account_payment_clearing'
|
||||
extras = ['account_statement', 'account_statement_rule']
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
8
modules/account_payment_clearing/tests/test_scenario.py
Normal file
8
modules/account_payment_clearing/tests/test_scenario.py
Normal file
@@ -0,0 +1,8 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
from trytond.tests.test_tryton import load_doc_tests
|
||||
|
||||
|
||||
def load_tests(*args, **kwargs):
|
||||
return load_doc_tests(__name__, __file__, *args, **kwargs)
|
||||
Reference in New Issue
Block a user