Files
tryton/tests/scenario_reports.rst
T
Cédric Krier 80fc35e01d Add General Ledger per account and party
We define an internal AccountParty model which defines an unique ID for the
couple account and party based on the first move line created.
Then we define a General Ledger model based on this model.

issue7438
review314091002
2020-09-05 22:21:38 +02:00

212 lines
6.2 KiB
ReStructuredText

========================
Account Reports Scenario
========================
Imports::
>>> import datetime
>>> from dateutil.relativedelta import relativedelta
>>> from decimal import Decimal
>>> from proteus import Model, Wizard, Report
>>> 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()
Activate modules::
>>> config = activate_modules('account')
Create company::
>>> _ = create_company()
>>> company = get_company()
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']
>>> expense = accounts['expense']
>>> cash = accounts['cash']
Create parties::
>>> Party = Model.get('party.party')
>>> party = Party(name='Party')
>>> party.save()
Create a moves::
>>> Journal = Model.get('account.journal')
>>> Move = Model.get('account.move')
>>> journal_revenue, = Journal.find([
... ('code', '=', 'REV'),
... ])
>>> journal_cash, = Journal.find([
... ('code', '=', 'CASH'),
... ])
>>> move = Move()
>>> move.period = period
>>> move.journal = journal_revenue
>>> move.date = period.start_date
>>> line = move.lines.new()
>>> line.account = revenue
>>> line.credit = Decimal(10)
>>> line = move.lines.new()
>>> line.account = receivable
>>> line.debit = Decimal(10)
>>> line.party = party
>>> move.save()
>>> move = Move()
>>> move.period = period
>>> move.journal = journal_cash
>>> move.date = period.start_date
>>> line = move.lines.new()
>>> line.account = cash
>>> line.debit = Decimal(10)
>>> line = move.lines.new()
>>> line.account = receivable
>>> line.credit = Decimal(10)
>>> line.party = party
>>> move.save()
Print some reports::
>>> GeneralLedgerAccount = Model.get('account.general_ledger.account')
>>> GeneralLedgerAccountParty = Model.get(
... 'account.general_ledger.account.party')
>>> gl_accounts = GeneralLedgerAccount.find([])
>>> _ = [(l.balance, l.party_required) for gl in gl_accounts
... for l in gl.lines]
>>> general_ledger = Report('account.general_ledger', context={
... 'company': company.id,
... 'fiscalyear': fiscalyear.id,
... })
>>> _ = general_ledger.execute(gl_accounts)
>>> context = {
... 'company': company.id,
... 'fiscalyear': fiscalyear.id,
... }
>>> with config.set_context(context):
... gl_revenue, = GeneralLedgerAccount.find([
... ('account', '=', revenue.id),
... ])
... glp_receivable, = GeneralLedgerAccountParty.find([
... ('account', '=', receivable.id),
... ('party', '=', party.id),
... ])
>>> gl_revenue.start_balance
Decimal('0.00')
>>> gl_revenue.credit
Decimal('10.00')
>>> gl_revenue.debit
Decimal('0.00')
>>> gl_revenue.end_balance
Decimal('-10.00')
>>> glp_receivable.start_balance
Decimal('0.00')
>>> glp_receivable.credit
Decimal('10.00')
>>> glp_receivable.debit
Decimal('10.00')
>>> glp_receivable.end_balance
Decimal('0.00')
>>> context = {
... 'company': company.id,
... 'fiscalyear': fiscalyear.id,
... 'from_date': fiscalyear.periods[0].start_date,
... 'to_date': fiscalyear.periods[1].end_date,
... }
>>> with config.set_context(context):
... gl_revenue, = GeneralLedgerAccount.find([
... ('account', '=', revenue.id),
... ])
... glp_receivable, = GeneralLedgerAccountParty.find([
... ('account', '=', receivable.id),
... ('party', '=', party.id),
... ])
>>> gl_revenue.start_balance
Decimal('0.00')
>>> gl_revenue.credit
Decimal('10.00')
>>> gl_revenue.debit
Decimal('0.00')
>>> gl_revenue.end_balance
Decimal('-10.00')
>>> glp_receivable.start_balance
Decimal('0.00')
>>> glp_receivable.credit
Decimal('10.00')
>>> glp_receivable.debit
Decimal('10.00')
>>> glp_receivable.end_balance
Decimal('0.00')
>>> context = {
... 'company': company.id,
... 'fiscalyear': fiscalyear.id,
... 'start_period': fiscalyear.periods[1].id,
... }
>>> with config.set_context(context):
... gl_revenue, = GeneralLedgerAccount.find([
... ('account', '=', revenue.id),
... ])
>>> gl_revenue.start_balance
Decimal('-10.00')
>>> gl_revenue.credit
Decimal('0.00')
>>> gl_revenue.debit
Decimal('0.00')
>>> gl_revenue.end_balance
Decimal('-10.00')
>>> trial_balance = Report('account.trial_balance', context={
... 'company': company.id,
... 'fiscalyear': fiscalyear.id,
... })
>>> _ = trial_balance.execute(gl_accounts)
>>> AgedBalance = Model.get('account.aged_balance')
>>> context = {
... 'company': company.id,
... 'type': 'customer',
... 'date': today,
... 'term1': 30,
... 'term2': 60,
... 'term3': 90,
... 'unit': 'day',
... }
>>> with config.set_context(context):
... aged_balances = AgedBalance.find([])
>>> aged_balance = Report('account.aged_balance', context=context)
>>> _ = aged_balance.execute(aged_balances)
>>> print_general_journal = Wizard('account.move.print_general_journal')
>>> print_general_journal.execute('print_')
>>> with config.set_context(
... start_date=period.start_date,
... end_date=period.end_date):
... journal_cash = Journal(journal_cash.id)
>>> journal_cash.credit
Decimal('0.00')
>>> journal_cash.debit
Decimal('10.00')
>>> journal_cash.balance
Decimal('10.00')