Files
tryton/modules/account_dunning_letter/tests/scenario_account_dunning_letter.rst
T

188 lines
5.4 KiB
ReStructuredText
Raw Normal View History

2015-01-20 18:49:53 +01:00
========================
Account Dunning Scenario
========================
Imports::
>>> import datetime as dt
2015-01-20 18:49:53 +01:00
>>> from decimal import Decimal
2024-01-14 19:21:56 +01:00
>>> 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, get_company
2017-08-02 19:38:14 +02:00
>>> from trytond.tests.tools import activate_modules, set_user
2015-01-20 18:49:53 +01:00
Activate modules::
2015-01-20 18:49:53 +01:00
>>> config = activate_modules('account_dunning_letter')
2015-01-20 18:49:53 +01:00
Create company::
>>> _ = create_company()
>>> company = get_company()
Reload the context::
>>> User = Model.get('res.user')
>>> Group = Model.get('res.group')
>>> config._context = User.get_preferences(True, config.context)
Create account admin user::
>>> account_admin_user = User()
>>> account_admin_user.name = 'Account Admin'
>>> account_admin_user.login = 'account_admin'
>>> account_admin_group, = Group.find([
... ('name', '=', 'Account Administration'),
... ])
>>> account_admin_user.groups.append(account_admin_group)
>>> account_admin_user.save()
Create account user::
>>> account_user = User()
>>> account_user.name = 'Account'
>>> account_user.login = 'account'
>>> account_group, = Group.find([
... ('name', '=', 'Account'),
... ])
>>> account_user.groups.append(account_group)
>>> account_user.save()
Create dunning user::
>>> dunning_user = User()
>>> dunning_user.name = 'Dunning'
>>> dunning_user.login = 'dunning'
>>> dunning_group, = Group.find([('name', '=', 'Dunning')])
>>> dunning_user.groups.append(dunning_group)
>>> dunning_user.save()
Create fiscal year::
>>> fiscalyear = create_fiscalyear(company)
>>> fiscalyear.click('create_period')
>>> period = fiscalyear.periods[0]
Create chart of accounts::
>>> _ = create_chart(company)
>>> accounts = get_accounts(company)
>>> receivable = accounts['receivable']
>>> revenue = accounts['revenue']
>>> cash = accounts['cash']
Create dunning procedure::
2017-08-02 19:38:14 +02:00
>>> set_user(account_admin_user)
2015-01-20 18:49:53 +01:00
>>> Procedure = Model.get('account.dunning.procedure')
>>> procedure = Procedure(name='Procedure')
>>> level = procedure.levels.new()
>>> level.sequence = 1
>>> level.overdue = dt.timedelta(5)
>>> level.print_on_letter = True
2015-01-20 18:49:53 +01:00
>>> procedure.save()
Create parties::
>>> Party = Model.get('party.party')
>>> customer = Party(name='Customer')
>>> customer.dunning_procedure = procedure
>>> customer.save()
Create some moves::
2017-08-02 19:38:14 +02:00
>>> set_user(account_user)
2015-01-20 18:49:53 +01:00
>>> Journal = Model.get('account.journal')
>>> Move = Model.get('account.move')
>>> journal_revenue, = Journal.find([
... ('code', '=', 'REV'),
... ])
>>> journal_cash, = Journal.find([
... ('code', '=', 'CASH'),
... ])
Create reconciled moves::
2015-01-20 18:49:53 +01:00
>>> move = Move()
>>> move.period = period
>>> move.journal = journal_revenue
>>> move.date = period.start_date
>>> line = move.lines.new()
>>> line.account = revenue
>>> line.credit = Decimal(100)
>>> line = move.lines.new()
>>> line.account = receivable
>>> line.debit = Decimal(100)
>>> line.party = customer
>>> line.maturity_date = period.start_date
>>> move.save()
>>> reconcile1, = [l for l in move.lines if l.account == receivable]
>>> move = Move()
>>> move.period = period
>>> move.journal = journal_cash
>>> move.date = period.start_date
>>> line = move.lines.new()
>>> line.account = cash
>>> line.debit = Decimal(100)
>>> line = move.lines.new()
>>> line.account = receivable
>>> line.credit = Decimal(100)
>>> line.party = customer
>>> move.save()
>>> reconcile2, = [l for l in move.lines if l.account == receivable]
>>> reconcile_lines = Wizard('account.move.reconcile_lines',
... [reconcile1, reconcile2])
Create due move of 100::
2015-01-20 18:49:53 +01:00
>>> move = Move()
>>> move.period = period
>>> move.journal = journal_revenue
>>> move.date = period.start_date
>>> line = move.lines.new()
>>> line.account = revenue
>>> line.credit = Decimal(100)
>>> line = move.lines.new()
>>> line.account = receivable
>>> line.debit = Decimal(100)
>>> line.party = customer
>>> line.maturity_date = period.start_date
>>> move.save()
>>> dunning_line, = [l for l in move.lines if l.account == receivable]
Add partial payment of 50::
>>> move = Move()
>>> move.period = period
>>> move.journal = journal_cash
>>> move.date = period.start_date
>>> line = move.lines.new()
>>> line.account = cash
>>> line.debit = Decimal(50)
>>> line = move.lines.new()
>>> line.account = receivable
>>> line.credit = Decimal(50)
>>> line.party = customer
>>> move.save()
2015-01-20 18:49:53 +01:00
Create dunnings::
2017-08-02 19:38:14 +02:00
>>> set_user(dunning_user)
2015-01-20 18:49:53 +01:00
>>> Dunning = Model.get('account.dunning')
>>> create_dunning = Wizard('account.dunning.create')
>>> create_dunning.form.date = period.start_date + dt.timedelta(days=5)
2015-01-20 18:49:53 +01:00
>>> create_dunning.execute('create_')
>>> dunning, = Dunning.find([])
Process dunning::
>>> process_dunning = Wizard('account.dunning.process',
... [dunning])
>>> process_dunning.execute('process')
>>> dunning.reload()
>>> dunning.state
2018-08-31 14:48:27 +02:00
'waiting'
2019-03-08 18:51:48 +01:00
>>> (_, _, _, _), = process_dunning.actions