first commit

This commit is contained in:
root
2026-03-14 09:42:12 +00:00
commit 0adbd20c2c
10991 changed files with 1646955 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
# 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 .test_module import create_chart, get_fiscalyear
__all__ = ['create_chart', 'get_fiscalyear']

View File

@@ -0,0 +1,150 @@
=======================
Account Active Scenario
=======================
Imports::
>>> from dateutil.relativedelta import relativedelta
>>> from proteus import Model
>>> 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
Activate modules::
>>> config = activate_modules('account', create_company, create_chart)
>>> Account = Model.get('account.account')
Create fiscal year::
>>> fiscalyear = create_fiscalyear()
>>> fiscalyear.click('create_period')
>>> period = fiscalyear.periods[1]
Get accounts::
>>> accounts = get_accounts()
>>> cash = accounts['cash']
Check active without start or end date::
>>> cash.active
True
>>> len(Account.find([('id', '=', cash.id)]))
1
>>> len(Account.find([('id', '=', cash.id), ('active', '=', True)]))
1
>>> len(Account.find([('id', '=', cash.id), ('active', 'in', [True])]))
1
>>> len(Account.find([('id', '=', cash.id), ('active', 'in', [True, False])]))
1
Check negative search::
>>> len(Account.find([('id', '=', cash.id), ('active', '=', False)]))
0
>>> len(Account.find([('id', '=', cash.id), ('active', 'in', [False])]))
0
Check active with a start date::
>>> cash.start_date = period.start_date
>>> cash.save()
>>> with config.set_context(date=period.start_date):
... Account(cash.id).active
... len(Account.find([('id', '=', cash.id)]))
True
1
>>> with config.set_context(date=period.end_date):
... Account(cash.id).active
... len(Account.find([('id', '=', cash.id)]))
True
1
>>> with config.set_context(date=fiscalyear.start_date):
... Account(cash.id).active
... len(Account.find([('id', '=', cash.id)]))
True
1
>>> with config.set_context(date=fiscalyear.start_date - relativedelta(days=1)):
... Account(cash.id).active
... len(Account.find([('id', '=', cash.id)]))
False
0
>>> with config.set_context(date=fiscalyear.end_date - relativedelta(days=1)):
... Account(cash.id).active
... len(Account.find([('id', '=', cash.id)]))
True
1
Check active with an end date::
>>> cash.start_date = None
>>> cash.end_date = period.end_date
>>> cash.save()
>>> with config.set_context(date=period.start_date):
... Account(cash.id).active
... len(Account.find([('id', '=', cash.id)]))
True
1
>>> with config.set_context(date=period.end_date):
... Account(cash.id).active
... len(Account.find([('id', '=', cash.id)]))
True
1
>>> with config.set_context(date=fiscalyear.end_date):
... Account(cash.id).active
... len(Account.find([('id', '=', cash.id)]))
True
1
>>> with config.set_context(date=fiscalyear.start_date - relativedelta(days=1)):
... Account(cash.id).active
... len(Account.find([('id', '=', cash.id)]))
True
1
>>> with config.set_context(date=fiscalyear.end_date + relativedelta(days=1)):
... Account(cash.id).active
... len(Account.find([('id', '=', cash.id)]))
False
0
Check active with start and end date::
>>> cash.start_date = period.start_date
>>> cash.end_date = period.end_date
>>> cash.save()
>>> with config.set_context(date=period.start_date):
... Account(cash.id).active
... len(Account.find([('id', '=', cash.id)]))
True
1
>>> with config.set_context(date=period.end_date):
... Account(cash.id).active
... len(Account.find([('id', '=', cash.id)]))
True
1
>>> with config.set_context(date=fiscalyear.start_date):
... Account(cash.id).active
... len(Account.find([('id', '=', cash.id)]))
True
1
>>> with config.set_context(date=fiscalyear.end_date):
... Account(cash.id).active
... len(Account.find([('id', '=', cash.id)]))
True
1
>>> with config.set_context(date=fiscalyear.start_date - relativedelta(days=1)):
... Account(cash.id).active
... len(Account.find([('id', '=', cash.id)]))
False
0
>>> with config.set_context(date=fiscalyear.end_date + relativedelta(days=1)):
... Account(cash.id).active
... len(Account.find([('id', '=', cash.id)]))
False
0

View File

@@ -0,0 +1,4 @@
[
{"party_required": true}
,{"party_required": false}
]

View File

@@ -0,0 +1,126 @@
==========================
Account Reconcile Scenario
==========================
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.company.tests.tools import create_company
>>> from trytond.tests.tools import activate_modules, assertEqual
>>> party_required = globals().get('party_required', True)
Activate modules::
>>> config = activate_modules('account', create_company, create_chart)
>>> Journal = Model.get('account.journal')
>>> Line = Model.get('account.move.line')
>>> Move = Model.get('account.move')
>>> Party = Model.get('party.party')
Create fiscal year::
>>> fiscalyear = create_fiscalyear()
>>> fiscalyear.click('create_period')
>>> period = fiscalyear.periods[0]
Get accounts::
>>> accounts = get_accounts()
>>> receivable = accounts['receivable']
>>> revenue = accounts['revenue']
>>> expense = accounts['expense']
>>> cash = accounts['cash']
>>> receivable.party_required = party_required
>>> receivable.save()
Create parties::
>>> customer = Party(name='Customer')
>>> customer.save()
Create Moves to reconcile::
>>> 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(42)
>>> line = move.lines.new()
>>> line.account = receivable
>>> line.debit = Decimal(42)
>>> if line.account.party_required:
... line.party = customer
>>> 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(40)
>>> line = move.lines.new()
>>> line.account = receivable
>>> line.credit = Decimal(40)
>>> if line.account.party_required:
... line.party = customer
>>> move.save()
Create a write off method::
>>> journal_writeoff = Journal(name='Write-Off', type='write-off')
>>> journal_writeoff.save()
>>> WriteOff = Model.get('account.move.reconcile.write_off')
>>> writeoff_method = WriteOff()
>>> writeoff_method.name = 'Write Off'
>>> writeoff_method.journal = journal_writeoff
>>> writeoff_method.debit_account = expense
>>> writeoff_method.credit_account = expense
>>> writeoff_method.save()
Run Reconcile for only balanced::
>>> reconcile = Wizard('account.reconcile')
>>> reconcile.form.only_balanced = True
>>> reconcile.execute('setup')
>>> reconcile.state
'end'
Run Reconcile wizard::
>>> reconcile = Wizard('account.reconcile')
>>> reconcile.execute('setup')
>>> assertEqual(reconcile.form.party, (customer if party_required else None))
>>> reconcile.form.write_off_amount
Decimal('0.00')
>>> len(reconcile.form.lines)
0
>>> reconcile.form.lines.extend(reconcile.form.lines.find())
>>> len(reconcile.form.lines)
2
>>> reconcile.form.write_off_amount
Decimal('2.00')
>>> reconcile.form.write_off = writeoff_method
>>> reconcile.execute('reconcile')
>>> lines = Line.find([('account', '=', receivable.id)])
>>> len(lines)
3
>>> all(l.reconciliation for l in lines)
True

View File

@@ -0,0 +1,84 @@
====================================
Account Reconcile Automatic Scenario
====================================
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.company.tests.tools import create_company
>>> from trytond.tests.tools import activate_modules
Activate modules::
>>> config = activate_modules('account', create_company, create_chart)
>>> Journal = Model.get('account.journal')
>>> Line = Model.get('account.move.line')
>>> Move = Model.get('account.move')
>>> Party = Model.get('party.party')
Create fiscal year::
>>> fiscalyear = create_fiscalyear()
>>> fiscalyear.click('create_period')
>>> period = fiscalyear.periods[0]
Get accounts::
>>> accounts = get_accounts()
Create parties::
>>> customer = Party(name="Customer")
>>> customer.save()
Create Moves to reconcile::
>>> 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 = accounts['revenue']
>>> line.credit = Decimal(42)
>>> line = move.lines.new()
>>> line.account = accounts['receivable']
>>> line.debit = Decimal(42)
>>> line.party = customer
>>> move.save()
>>> move = Move()
>>> move.period = period
>>> move.journal = journal_cash
>>> move.date = period.start_date
>>> line = move.lines.new()
>>> line.account = accounts['cash']
>>> line.debit = Decimal(42)
>>> line = move.lines.new()
>>> line.account = accounts['receivable']
>>> line.credit = Decimal(42)
>>> line.party = customer
>>> move.save()
Run Reconcile wizard::
>>> reconcile = Wizard('account.reconcile')
>>> reconcile.form.automatic = True
>>> reconcile.execute('setup')
>>> lines = Line.find([('account', '=', accounts['receivable'].id)])
>>> len(lines)
2
>>> all(l.reconciliation for l in lines)
True

View File

@@ -0,0 +1,187 @@
===============================
Account Reconciliation Scenario
===============================
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.company.tests.tools import create_company
>>> from trytond.tests.tools import activate_modules, assertEqual, assertTrue
Activate modules::
>>> config = activate_modules('account', create_company, create_chart)
>>> GLLine = Model.get('account.general_ledger.line')
Create fiscal year::
>>> fiscalyear = create_fiscalyear()
>>> fiscalyear.click('create_period')
>>> period = fiscalyear.periods[0]
Get accounts::
>>> accounts = get_accounts()
>>> receivable = accounts['receivable']
>>> revenue = accounts['revenue']
>>> expense = accounts['expense']
>>> cash = accounts['cash']
Create parties::
>>> Party = Model.get('party.party')
>>> customer = Party(name='Customer')
>>> customer.save()
Create Moves for direct reconciliation::
>>> 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(42)
>>> line = move.lines.new()
>>> line.account = receivable
>>> line.debit = Decimal(42)
>>> line.party = customer
>>> 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(42)
>>> line = move.lines.new()
>>> line.account = receivable
>>> line.credit = Decimal(42)
>>> line.party = customer
>>> move.save()
>>> reconcile2, = [l for l in move.lines if l.account == receivable]
Reconcile Lines without writeoff::
>>> reconcile_lines = Wizard('account.move.reconcile_lines',
... [reconcile1, reconcile2])
>>> reconcile_lines.state
'end'
>>> reconcile1.reload()
>>> reconcile2.reload()
>>> assertEqual(reconcile1.reconciliation, reconcile2.reconciliation)
>>> assertTrue(reconcile1.reconciliation)
>>> len(reconcile1.reconciliation.lines)
2
Unreconcile lines::
>>> unreconcile_lines = Wizard(
... 'account.move.unreconcile_lines', [reconcile1])
>>> unreconcile_lines.state
'end'
>>> reconcile1.reload()
>>> reconcile1.reconciliation
>>> reconcile2.reload()
>>> reconcile2.reconciliation
Reconcile general ledger lines::
>>> gl_reconcile1 = GLLine(reconcile1.id)
>>> gl_reconcile2 = GLLine(reconcile2.id)
>>> reconcile_lines = Wizard('account.move.reconcile_lines',
... [gl_reconcile1, gl_reconcile2])
>>> reconcile_lines.state
'end'
>>> gl_reconcile1.reload()
>>> gl_reconcile2.reload()
>>> assertEqual(gl_reconcile1.reconciliation, gl_reconcile2.reconciliation)
>>> assertTrue(gl_reconcile1.reconciliation)
Unreconcile general ledger, lines::
>>> unreconcile_lines = Wizard(
... 'account.move.unreconcile_lines', [gl_reconcile1])
>>> unreconcile_lines.state
'end'
>>> gl_reconcile1.reload()
>>> gl_reconcile1.reconciliation
>>> gl_reconcile2.reload()
>>> gl_reconcile2.reconciliation
Create Moves for writeoff reconciliation::
>>> move = Move()
>>> move.period = period
>>> move.journal = journal_revenue
>>> move.date = period.start_date
>>> line = move.lines.new()
>>> line.account = revenue
>>> line.credit = Decimal(68)
>>> line = move.lines.new()
>>> line.account = receivable
>>> line.debit = Decimal(68)
>>> line.party = customer
>>> 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(65)
>>> line = move.lines.new()
>>> line.account = receivable
>>> line.credit = Decimal(65)
>>> line.party = customer
>>> move.save()
>>> reconcile2, = [l for l in move.lines if l.account == receivable]
Create a write-off payment method::
>>> journal_writeoff = Journal(name='Write-Off', type='write-off')
>>> journal_writeoff.save()
>>> WriteOff = Model.get('account.move.reconcile.write_off')
>>> writeoff_method = WriteOff()
>>> writeoff_method.name = 'Write Off'
>>> writeoff_method.journal = journal_writeoff
>>> writeoff_method.debit_account = expense
>>> writeoff_method.credit_account = expense
>>> writeoff_method.save()
Reconcile Lines with write-off::
>>> reconcile_lines = Wizard('account.move.reconcile_lines',
... [reconcile1, reconcile2])
>>> reconcile_lines.form_state
'writeoff'
>>> reconcile_lines.form.writeoff = writeoff_method
>>> reconcile_lines.execute('reconcile')
>>> reconcile1.reload()
>>> reconcile2.reload()
>>> assertEqual(reconcile1.reconciliation, reconcile2.reconciliation)
>>> assertTrue(reconcile1.reconciliation)
>>> len(reconcile1.reconciliation.lines)
3
>>> writeoff_line1, = [l for l in reconcile1.reconciliation.lines
... if l.credit == Decimal(3)]
>>> writeoff_line2, = [l for l in writeoff_line1.move.lines
... if l != writeoff_line1]
>>> assertEqual(writeoff_line2.account, expense)
>>> writeoff_line2.debit
Decimal('3')

View File

@@ -0,0 +1,4 @@
[
{"post_moves": false}
,{"post_moves": true}
]

View File

@@ -0,0 +1,116 @@
=========================================
Account Reconciliation Alternate Currency
=========================================
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.company.tests.tools import create_company
>>> from trytond.modules.currency.tests.tools import get_currency
>>> from trytond.tests.tools import activate_modules, assertEqual, assertTrue
>>> post_moves = globals().get('post_moves', False)
Activate modules::
>>> config = activate_modules('account', create_company, create_chart)
>>> Configuration = Model.get('account.configuration')
>>> Journal = Model.get('account.journal')
>>> Move = Model.get('account.move')
>>> Party = Model.get('party.party')
>>> Reconciliation = Model.get('account.move.reconciliation')
Create currencies::
>>> usd = get_currency('USD')
>>> eur = get_currency('EUR')
Create fiscal year::
>>> fiscalyear = create_fiscalyear()
>>> fiscalyear.click('create_period')
>>> period = fiscalyear.periods[0]
Get accounts::
>>> accounts = get_accounts()
Configure currency exchange::
>>> currency_exchange_account, = (
... accounts['revenue'].duplicate(
... default={'name': "Currency Exchange"}))
>>> configuration = Configuration(1)
>>> configuration.currency_exchange_credit_account = (
... currency_exchange_account)
>>> configuration.save()
Create party::
>>> party = Party(name="Party")
>>> party.save()
Create moves to reconcile::
>>> journal_expense, = Journal.find([('code', '=', 'EXP')])
>>> journal_cash, = Journal.find([('code', '=', 'CASH')])
>>> move = Move()
>>> move.period = period
>>> move.journal = journal_expense
>>> move.date = period.start_date
>>> line = move.lines.new()
>>> line.account = accounts['expense']
>>> line.debit = Decimal('50.00')
>>> line = move.lines.new()
>>> line.account = accounts['payable']
>>> line.party = party
>>> line.credit = Decimal('50.00')
>>> line.amount_second_currency = Decimal('-90.00')
>>> line.second_currency = eur
>>> move.save()
>>> if post_moves:
... move.click('post')
>>> reconcile1, = [l for l in move.lines if l.account == accounts['payable']]
>>> move = Move()
>>> move.period = period
>>> move.journal = journal_cash
>>> move.date = period.end_date
>>> line = move.lines.new()
>>> line.account = accounts['cash']
>>> line.credit = Decimal('45.00')
>>> line = move.lines.new()
>>> line.account = accounts['payable']
>>> line.party = party
>>> line.debit = Decimal('45.00')
>>> line.amount_second_currency = Decimal('-90.00')
>>> line.second_currency = eur
>>> move.save()
>>> if post_moves:
... move.click('post')
>>> reconcile2, = [l for l in move.lines if l.account == accounts['payable']]
Reconcile lines::
>>> reconcile_lines = Wizard(
... 'account.move.reconcile_lines', [reconcile1, reconcile2])
>>> reconcile_lines.state
'end'
>>> assertEqual(reconcile1.reconciliation, reconcile2.reconciliation)
>>> assertTrue(reconcile1.reconciliation)
>>> reconciliation, = Reconciliation.find([])
>>> len(reconciliation.lines)
3
>>> currency_exchange_account.reload()
>>> currency_exchange_account.balance
Decimal('-5.00')
>>> len(Move.find([('state', '=', 'posted' if post_moves else 'draft')]))
3

View File

@@ -0,0 +1,4 @@
[
{"post_moves": false}
,{"post_moves": true}
]

View File

@@ -0,0 +1,135 @@
========================================================
Account Reconciliation Alternate Currency with Write-Off
========================================================
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.company.tests.tools import create_company
>>> from trytond.modules.currency.tests.tools import get_currency
>>> from trytond.tests.tools import activate_modules, assertTrue
>>> post_moves = globals().get('post_moves', False)
Activate modules::
>>> config = activate_modules('account', create_company, create_chart)
>>> Configuration = Model.get('account.configuration')
>>> Journal = Model.get('account.journal')
>>> Move = Model.get('account.move')
>>> Party = Model.get('party.party')
>>> Reconciliation = Model.get('account.move.reconciliation')
>>> WriteOff = Model.get('account.move.reconcile.write_off')
Create currencies::
>>> usd = get_currency('USD')
>>> eur = get_currency('EUR')
Create fiscal year::
>>> fiscalyear = create_fiscalyear()
>>> fiscalyear.click('create_period')
>>> period = fiscalyear.periods[0]
Get accounts::
>>> accounts = get_accounts()
Configure currency exchange::
>>> currency_exchange_account, = (
... accounts['revenue'].duplicate(
... default={'name': "Currency Exchange"}))
>>> configuration = Configuration(1)
>>> configuration.currency_exchange_credit_account = (
... currency_exchange_account)
>>> configuration.save()
Create write-off::
>>> journal_writeoff = Journal(
... name="Write-Off", type='write-off')
>>> journal_writeoff.save()
>>> write_off = WriteOff()
>>> write_off.name = "Write-Off"
>>> write_off.journal = journal_writeoff
>>> write_off.debit_account, = accounts['expense'].duplicate()
>>> write_off.credit_account, = accounts['revenue'].duplicate()
>>> write_off.save()
Create party::
>>> party = Party(name="Party")
>>> party.save()
Create moves to reconcile::
>>> journal_expense, = Journal.find([('code', '=', 'EXP')])
>>> journal_cash, = Journal.find([('code', '=', 'CASH')])
>>> move = Move()
>>> move.period = period
>>> move.journal = journal_expense
>>> move.date = period.start_date
>>> line = move.lines.new()
>>> line.account = accounts['expense']
>>> line.debit = Decimal('50.00')
>>> line = move.lines.new()
>>> line.account = accounts['payable']
>>> line.party = party
>>> line.credit = Decimal('50.00')
>>> line.amount_second_currency = Decimal('-90.00')
>>> line.second_currency = eur
>>> move.save()
>>> if post_moves:
... move.click('post')
>>> reconcile1, = [l for l in move.lines if l.account == accounts['payable']]
>>> move = Move()
>>> move.period = period
>>> move.journal = journal_cash
>>> move.date = period.end_date
>>> line = move.lines.new()
>>> line.account = accounts['cash']
>>> line.credit = Decimal('45.00')
>>> line = move.lines.new()
>>> line.account = accounts['payable']
>>> line.party = party
>>> line.debit = Decimal('45.00')
>>> line.amount_second_currency = Decimal('-89.00')
>>> line.second_currency = eur
>>> move.save()
>>> if post_moves:
... move.click('post')
>>> reconcile2, = [l for l in move.lines if l.account == accounts['payable']]
Reconcile lines::
>>> reconcile_lines = Wizard(
... 'account.move.reconcile_lines', [reconcile1, reconcile2])
>>> reconcile_lines.form_state
'writeoff'
>>> reconcile_lines.form.writeoff = write_off
>>> reconcile_lines.execute('reconcile')
>>> reconcile1.reconciliation == reconcile2.reconciliation
True
>>> assertTrue(reconcile1.reconciliation)
>>> reconciliation, = Reconciliation.find([])
>>> len(reconciliation.lines)
4
>>> write_off.credit_account.reload()
>>> write_off.credit_account.balance
Decimal('-0.50')
>>> currency_exchange_account.reload()
>>> currency_exchange_account.balance
Decimal('-4.50')
>>> len(Move.find([('state', '=', 'posted' if post_moves else 'draft')]))
4

View File

@@ -0,0 +1,69 @@
=====================================
Account Reconciliation Empty Scenario
=====================================
Imports::
>>> from decimal import Decimal
>>> from proteus import Model
>>> from trytond.modules.account.tests.tools import (
... create_chart, create_fiscalyear, get_accounts)
>>> from trytond.modules.company.tests.tools import create_company
>>> from trytond.modules.currency.tests.tools import get_currency
>>> from trytond.tests.tools import activate_modules, assertTrue
Activate modules::
>>> config = activate_modules('account', create_company, create_chart)
>>> Journal = Model.get('account.journal')
>>> Move = Model.get('account.move')
Create currencies::
>>> usd = get_currency('USD')
>>> eur = get_currency('EUR')
Create fiscal year::
>>> fiscalyear = create_fiscalyear()
>>> fiscalyear.click('create_period')
Get accounts::
>>> accounts = get_accounts()
>>> account = accounts['cash']
>>> account.reconcile = True
>>> account.save()
>>> journal, = Journal.find([('code', '=', 'CASH')])
Lines with empty debit/credit are reconciled::
>>> move = Move()
>>> move.journal = journal
>>> line = move.lines.new()
>>> line.account = account
>>> line.debit = line.credit = Decimal('0')
>>> move.save()
>>> move.click('post')
>>> move.state
'posted'
>>> line, = move.lines
>>> assertTrue(line.reconciliation)
Lines with empty debit/credit but second currency are not reconciled::
>>> move = Move()
>>> move.journal = journal
>>> line = move.lines.new()
>>> line.account = account
>>> line.debit = line.credit = Decimal('0')
>>> line.amount_second_currency = Decimal('0.15')
>>> line.second_currency = eur
>>> move.save()
>>> move.click('post')
>>> move.state
'posted'
>>> line, = move.lines
>>> line.reconciliation

View File

@@ -0,0 +1,137 @@
=================================
Account Close Fiscalyear Scenario
=================================
Imports::
>>> import datetime as dt
>>> from decimal import Decimal
>>> from dateutil.relativedelta import relativedelta
>>> 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()
>>> last_year = today - relativedelta(years=1)
Activate modules::
>>> config = activate_modules('account', create_company, create_chart)
>>> Account = Model.get('account.account')
>>> AccountType = Model.get('account.account.type')
>>> Journal = Model.get('account.journal')
>>> Journal = Model.get('account.journal')
>>> Move = Model.get('account.move')
>>> Party = Model.get('party.party')
>>> Period = Model.get('account.period')
>>> Sequence = Model.get('ir.sequence')
Create fiscal year::
>>> fiscalyear = create_fiscalyear(today=last_year)
>>> fiscalyear.click('create_period')
>>> period = fiscalyear.periods[0]
Get accounts::
>>> accounts = get_accounts()
Prepare the closing settings for fiscalyear close::
>>> journal_closing = Journal()
>>> journal_closing.name = 'Closing'
>>> journal_closing.code = 'CLO'
>>> journal_closing.type = 'situation'
>>> journal_closing.save()
>>> period_closing = Period()
>>> period_closing.name = 'Closing'
>>> period_closing.start_date = fiscalyear.end_date
>>> period_closing.end_date = fiscalyear.end_date
>>> period_closing.fiscalyear = fiscalyear
>>> period_closing.type = 'adjustment'
>>> period_closing.save()
>>> account_pl, = Account.find([('code', '=', '3.2.1')])
Create children accounts::
>>> receivable_customer = Account()
>>> receivable_customer.name = "Customer Receivable"
>>> receivable_customer.parent = accounts['receivable']
>>> receivable_customer.save()
Create parties::
>>> customer = Party(name="Customer")
>>> customer.save()
Create and post a move using children accounts::
>>> journal_revenue, = Journal.find([
... ('code', '=', 'REV'),
... ])
>>> move = Move()
>>> move.period = period
>>> move.journal = journal_revenue
>>> move.date = period.start_date
>>> line = move.lines.new()
>>> line.account = accounts['revenue']
>>> line.credit = Decimal(42)
>>> line = move.lines.new()
>>> line.account = receivable_customer
>>> line.debit = Decimal(21)
>>> line.party = customer
>>> line = move.lines.new()
>>> line.account = accounts['receivable']
>>> line.debit = Decimal(21)
>>> line.party = customer
>>> move.save()
>>> move.click('post')
Balance non deferral::
>>> balance_non_deferral = Wizard('account.fiscalyear.balance_non_deferral')
>>> balance_non_deferral.form.fiscalyear = fiscalyear
>>> balance_non_deferral.form.journal = journal_closing
>>> balance_non_deferral.form.period = period_closing
>>> balance_non_deferral.form.credit_account = account_pl
>>> balance_non_deferral.form.debit_account = account_pl
>>> balance_non_deferral.execute('balance')
>>> move, = Move.find([('state', '=', 'draft')])
>>> move.click('post')
Renew fiscalyear using the wizard::
>>> renew_fiscalyear = Wizard('account.fiscalyear.renew')
>>> renew_fiscalyear.form.reset_sequences = False
>>> renew_fiscalyear.execute('create_')
Check receivable balance before closing fiscalyear::
>>> accounts['receivable'].reload()
>>> accounts['receivable'].balance
Decimal('42.00')
>>> receivable_customer.reload()
>>> receivable_customer.balance
Decimal('21.00')
Close fiscalyear::
>>> fiscalyear.click('close')
>>> fiscalyear.state
'closed'
Check receivable amounts after closing fiscalyear::
>>> accounts['receivable'].reload()
>>> accounts['receivable'].balance
Decimal('42.00')
>>> receivable_customer.reload()
>>> receivable_customer.balance
Decimal('21.00')

View File

@@ -0,0 +1,135 @@
====================
Move Cancel Scenario
====================
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.company.tests.tools import create_company
>>> from trytond.modules.currency.tests.tools import get_currency
>>> from trytond.tests.tools import activate_modules, assertEqual
Activate modules::
>>> config = activate_modules('account', create_company, create_chart)
>>> Reconciliation = Model.get('account.move.reconciliation')
Create fiscal year::
>>> fiscalyear = create_fiscalyear()
>>> fiscalyear.click('create_period')
>>> period = fiscalyear.periods[0]
Get accounts::
>>> accounts = get_accounts()
>>> receivable = accounts['receivable']
>>> revenue = accounts['revenue']
Create parties::
>>> Party = Model.get('party.party')
>>> customer = Party(name='Customer')
>>> customer.save()
>>> party = Party(name='Party')
>>> party.save()
Create Move to cancel::
>>> 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(42)
>>> line = move.lines.new()
>>> line.account = receivable
>>> line.debit = Decimal(32)
>>> line.party = customer
>>> line.second_currency = get_currency('EUR')
>>> line.amount_second_currency = Decimal(30)
>>> line = move.lines.new()
>>> line.account = receivable
>>> line.debit = Decimal(10)
>>> line.party = party
>>> move.save()
>>> revenue.reload()
>>> revenue.credit
Decimal('42.00')
>>> receivable.reload()
>>> receivable.debit
Decimal('42.00')
Cancel reversal Move::
>>> cancel_move = Wizard('account.move.cancel', [move])
>>> cancel_move.form.description = "Reversal"
>>> cancel_move.form.reversal = True
>>> cancel_move.execute('cancel')
>>> cancel_move.state
'end'
>>> move.reload()
>>> [bool(l.reconciliation) for l in move.lines if l.account == receivable]
[True, True]
>>> line, _ = [l for l in move.lines if l.account == receivable]
>>> cancel_move, = [l.move for l in line.reconciliation.lines
... if l.move != move]
>>> assertEqual(cancel_move.origin, move)
>>> cancel_move.description
'Reversal'
>>> assertEqual({l.origin for l in cancel_move.lines}, set(move.lines))
>>> revenue.reload()
>>> revenue.credit
Decimal('42.00')
>>> revenue.debit
Decimal('42.00')
>>> receivable.reload()
>>> receivable.credit
Decimal('42.00')
>>> receivable.debit
Decimal('42.00')
>>> reconciliations = {
... l.reconciliation for l in cancel_move.lines if l.reconciliation}
>>> Reconciliation.delete(list(reconciliations))
>>> cancel_move.reload()
>>> cancel_move.delete()
Cancel Move::
>>> cancel_move = Wizard('account.move.cancel', [move])
>>> cancel_move.form.description = 'Cancel'
>>> cancel_move.form.reversal = False
>>> cancel_move.execute('cancel')
>>> cancel_move.state
'end'
>>> move.reload()
>>> [bool(l.reconciliation) for l in move.lines if l.account == receivable]
[True, True]
>>> line, _ = [l for l in move.lines if l.account == receivable]
>>> cancel_move, = [l.move for l in line.reconciliation.lines
... if l.move != move]
>>> assertEqual(cancel_move.origin, move)
>>> cancel_move.description
'Cancel'
>>> assertEqual({l.origin for l in cancel_move.lines}, set(move.lines))
>>> revenue.reload()
>>> revenue.credit
Decimal('0.00')
>>> receivable.reload()
>>> receivable.debit
Decimal('0.00')

View File

@@ -0,0 +1,87 @@
==================
Move Copy Scenario
==================
Imports::
>>> from decimal import Decimal
>>> from proteus import Model
>>> 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, assertEqual, assertNotEqual
Activate modules::
>>> config = activate_modules('account', create_company, create_chart)
>>> Journal = Model.get('account.journal')
>>> Move = Model.get('account.move')
>>> Party = Model.get('party.party')
Create a fiscal year::
>>> fiscalyear = create_fiscalyear()
>>> fiscalyear.click('create_period')
>>> period = fiscalyear.periods[0]
Get accounts::
>>> accounts = get_accounts()
Create a party::
>>> party = Party(name="Party")
>>> party.save()
Create a posted move::
>>> move = Move()
>>> move.period = period
>>> move.journal, = Journal.find([('code', '=', 'REV')])
>>> move.date = period.start_date
>>> line = move.lines.new()
>>> line.account = accounts['revenue']
>>> line.credit = Decimal(42)
>>> line = move.lines.new()
>>> line.account = accounts['receivable']
>>> line.debit = Decimal(42)
>>> line.party = party
>>> move.save()
>>> move.click('post')
>>> move.state
'posted'
Copy move on open period::
>>> copy_move, = move.duplicate()
>>> copy_move.number
>>> copy_move.state
'draft'
>>> copy_move.post_date
>>> assertEqual(copy_move.period, move.period)
>>> assertEqual(copy_move.date, move.date)
>>> copy_move.delete()
Copy move on closed period::
>>> period.click('close')
>>> period.state
'closed'
>>> copy_move, = move.duplicate()
Traceback (most recent call last):
...
CopyWarning: ...
>>> config.skip_warning = True
>>> copy_move, = move.duplicate()
>>> copy_move.number
>>> copy_move.state
'draft'
>>> copy_move.post_date
>>> assertNotEqual(copy_move.period, move.period)
>>> copy_move.period.state
'open'
>>> assertNotEqual(copy_move.date, move.date)

View File

@@ -0,0 +1,101 @@
=======================
Delegate Lines Scenario
=======================
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.company.tests.tools import create_company
>>> from trytond.modules.currency.tests.tools import get_currency
>>> from trytond.tests.tools import activate_modules, assertEqual
Activate modules::
>>> config = activate_modules('account', create_company, create_chart)
>>> Journal = Model.get('account.journal')
>>> Move = Model.get('account.move')
>>> Party = Model.get('party.party')
Get currencies::
>>> usd = get_currency('USD')
>>> eur = get_currency('EUR')
Create fiscal year::
>>> fiscalyear = create_fiscalyear()
>>> fiscalyear.click('create_period')
>>> period = fiscalyear.periods[0]
Get accounts::
>>> accounts = get_accounts()
Create parties::
>>> party1 = Party(name="Party 1")
>>> party1.save()
>>> party2 = Party(name="Party 2")
>>> party2.save()
Create lines to delegate::
>>> journal, = Journal.find([
... ('code', '=', 'REV'),
... ])
>>> move = Move(journal=journal)
>>> move.date = period.start_date
>>> line = move.lines.new()
>>> line.account = accounts['revenue']
>>> line.credit = Decimal('100.00')
>>> line = move.lines.new()
>>> line.account = accounts['receivable']
>>> line.party = party1
>>> line.debit = Decimal('80.00')
>>> line.second_currency = eur
>>> line.amount_second_currency = Decimal('100.00')
>>> line.maturity_date = period.end_date
>>> line = move.lines.new()
>>> line.account = accounts['receivable']
>>> line.party = party1
>>> line.debit = Decimal('20.00')
>>> move.save()
>>> receivable_lines = [
... l for l in move.lines if l.account == accounts['receivable']]
>>> accounts['receivable'].reload()
>>> accounts['receivable'].balance
Decimal('100.00')
>>> party1.reload()
>>> party1.receivable
Decimal('100.00')
>>> party2.reload()
>>> party2.receivable
Decimal('0')
Delegate lines::
>>> delegate = Wizard('account.move.line.delegate', receivable_lines)
>>> assertEqual(delegate.form.journal, journal)
>>> delegate.form.party = party2
>>> delegate.form.description = "Delegate lines"
>>> delegate.execute('delegate')
>>> accounts['receivable'].reload()
>>> accounts['receivable'].balance
Decimal('100.00')
>>> party1.reload()
>>> party1.receivable
Decimal('0')
>>> party2.reload()
>>> party2.receivable
Decimal('100.00')
>>> all(l.reconciliation.delegate_to for l in receivable_lines)
True

View File

@@ -0,0 +1,160 @@
====================
Group Lines Scenario
====================
Imports::
>>> import datetime as dt
>>> from decimal import Decimal
>>> from proteus import Model, Wizard
>>> from trytond.modules.account.exceptions import CancelDelegatedWarning
>>> from trytond.modules.account.tests.tools import (
... create_chart, create_fiscalyear, get_accounts)
>>> from trytond.modules.company.tests.tools import create_company
>>> from trytond.modules.currency.tests.tools import get_currency
>>> from trytond.tests.tools import activate_modules, assertEqual
Activate modules::
>>> config = activate_modules('account', create_company, create_chart)
>>> Warning = Model.get('res.user.warning')
Get currency::
>>> usd = get_currency('USD')
>>> eur = get_currency('EUR')
Create fiscal year::
>>> fiscalyear = create_fiscalyear()
>>> fiscalyear.click('create_period')
>>> period = fiscalyear.periods[0]
Get accounts::
>>> accounts = get_accounts()
>>> payable = accounts['payable']
>>> receivable = accounts['receivable']
>>> revenue = accounts['revenue']
>>> expense = accounts['expense']
Create parties::
>>> Party = Model.get('party.party')
>>> party = Party(name="Party")
>>> party.save()
Create Lines to group::
>>> Journal = Model.get('account.journal')
>>> Move = Model.get('account.move')
>>> journal_revenue, = Journal.find([
... ('code', '=', 'REV'),
... ])
>>> journal_expense, = Journal.find([
... ('code', '=', 'EXP'),
... ])
>>> move = Move()
>>> 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.party = party
>>> line.debit = Decimal(100)
>>> line.second_currency = eur
>>> line.amount_second_currency = Decimal(90)
>>> line.maturity_date = period.start_date + dt.timedelta(days=2)
>>> move.save()
>>> move = Move()
>>> move.journal = journal_expense
>>> move.date = period.start_date
>>> line = move.lines.new()
>>> line.account = expense
>>> line.debit = Decimal(50)
>>> line = move.lines.new()
>>> line.account = payable
>>> line.party = party
>>> line.credit = Decimal(50)
>>> line.second_currency = eur
>>> line.amount_second_currency = Decimal(45)
>>> line.maturity_date = period.start_date + dt.timedelta(days=4)
>>> move.save()
>>> receivable.reload()
>>> receivable.balance, receivable.amount_second_currency
(Decimal('100.00'), Decimal('90.00'))
>>> payable.reload()
>>> payable.balance, payable.amount_second_currency
(Decimal('-50.00'), Decimal('-45.00'))
Group lines::
>>> journal_cash, = Journal.find([
... ('code', '=', 'CASH'),
... ])
>>> Line = Model.get('account.move.line')
>>> lines = Line.find([('account', 'in', [payable.id, receivable.id])])
>>> len(lines)
2
>>> group = Wizard('account.move.line.group', lines)
>>> group.form.journal = journal_cash
>>> group.form.description = "Group lines"
>>> group.execute('group')
>>> receivable.reload()
>>> receivable.balance, receivable.amount_second_currency
(Decimal('50.00'), Decimal('45.00'))
>>> payable.reload()
>>> payable.balance, payable.amount_second_currency
(Decimal('0.00'), Decimal('0.00'))
>>> delegated_line1, delegated_line2 = lines
>>> delegated_line1.reload()
>>> delegated_line2.reload()
>>> delegated_line1.delegated_amount
Decimal('45')
>>> delegated_line2.delegated_amount
Decimal('45')
>>> Reconciliation = Model.get('account.move.reconciliation')
>>> reconciliations = Reconciliation.find([])
>>> len(reconciliations)
2
>>> all(r.delegate_to for r in reconciliations)
True
>>> delegate_to = reconciliations[0].delegate_to
>>> assertEqual(delegate_to.account, receivable)
>>> delegate_to.debit
Decimal('50')
>>> assertEqual(
... delegate_to.maturity_date, period.start_date + dt.timedelta(days=2))
>>> delegate_to.move_description_used
'Group lines'
Cancelling the delegation move::
>>> delegation_move = delegate_to.move
>>> cancel = Wizard('account.move.cancel', [delegation_move])
>>> try:
... cancel.execute('cancel')
... except CancelDelegatedWarning as warning:
... Warning(user=config.user, name=warning.name).save()
... raise
Traceback (most recent call last):
...
CancelDelegatedWarning: ...
>>> cancel.execute('cancel')
>>> Reconciliation.find([('id', '=', reconciliations[0].id)])
[]
>>> delegated_line1.reload()
>>> delegated_line1.delegated_amount

View File

@@ -0,0 +1,142 @@
=========================
Reschedule Lines Scenario
=========================
Imports::
>>> from decimal import Decimal
>>> from dateutil.relativedelta import relativedelta
>>> 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.modules.currency.tests.tools import get_currency
>>> from trytond.tests.tools import activate_modules, assertEqual
Activate modules::
>>> config = activate_modules('account', create_company, create_chart)
>>> Journal = Model.get('account.journal')
>>> Line = Model.get('account.move.line')
>>> Move = Model.get('account.move')
>>> Party = Model.get('party.party')
Get currencies::
>>> usd = get_currency('USD')
>>> eur = get_currency('EUR')
Create fiscal year::
>>> fiscalyear = create_fiscalyear()
>>> fiscalyear.click('create_period')
>>> period = fiscalyear.periods[0]
Get accounts::
>>> accounts = get_accounts()
>>> receivable = accounts['receivable']
>>> revenue = accounts['revenue']
Create parties::
>>> party = Party(name="Party")
>>> party.save()
Create Lines to reschedule::
>>> journal_revenue, = Journal.find([
... ('code', '=', 'REV'),
... ])
>>> move = Move()
>>> move.journal = journal_revenue
>>> move.date = period.start_date
>>> line = move.lines.new()
>>> line.account = revenue
>>> line.credit = Decimal('90.00')
>>> line = move.lines.new()
>>> line.account = receivable
>>> line.party = party
>>> line.debit = Decimal('90.00')
>>> line.second_currency = eur
>>> line.amount_second_currency = Decimal('100.00')
>>> line.maturity_date = period.start_date
>>> move.save()
>>> line, = [l for l in move.lines if l.account == receivable]
>>> receivable.reload()
>>> receivable.balance, receivable.amount_second_currency
(Decimal('90.00'), Decimal('100.00'))
Split line by amount::
>>> reschedule = Wizard('account.move.line.reschedule', [line])
>>> reschedule.form.total_amount
Decimal('100.00')
>>> reschedule.form.start_date = period.end_date
>>> reschedule.form.frequency = 'other'
>>> reschedule.form.interval = 2
>>> reschedule.form.amount = Decimal('30.00')
>>> reschedule.execute('preview')
>>> term1, term2, term3, term4 = reschedule.form.terms
>>> assertEqual(term1.date, period.end_date)
>>> assertEqual(term2.date, period.end_date + relativedelta(months=2))
>>> assertEqual(term3.date, period.end_date + relativedelta(months=4))
>>> assertEqual(term4.date, period.end_date + relativedelta(months=6))
>>> term1.amount, term2.amount, term3.amount, term4.amount
(Decimal('30.00'), Decimal('30.00'), Decimal('30.00'), Decimal('10.00'))
Split line by number::
>>> reschedule = Wizard('account.move.line.reschedule', [line])
>>> reschedule.form.total_amount
Decimal('100.00')
>>> reschedule.form.start_date = period.end_date
>>> reschedule.form.frequency = 'monthly'
>>> reschedule.form.number = 3
>>> reschedule.execute('preview')
>>> reschedule.form.description = "Split 3 months"
>>> term1, term2, term3 = reschedule.form.terms
>>> assertEqual(term1.date, period.end_date)
>>> assertEqual(term2.date, period.end_date + relativedelta(months=1))
>>> assertEqual(term3.date, period.end_date + relativedelta(months=2))
>>> term1.amount, term2.amount, term3.amount
(Decimal('33.33'), Decimal('33.33'), Decimal('33.34'))
>>> term1.amount = Decimal('40.00')
>>> term2.amount = term3.amount = Decimal('30.00')
>>> term3.date = period.end_date + relativedelta(months=3)
>>> reschedule.execute('reschedule')
>>> reschedule_move, = reschedule.actions[0]
>>> reschedule_move.description
'Split 3 months'
Check receivable::
>>> receivable.reload()
>>> receivable.balance, receivable.amount_second_currency
(Decimal('90.00'), Decimal('100.00'))
>>> lines = Line.find([
... ('account', '=', receivable.id),
... ('reconciliation', '=', None),
... ], order=[('maturity_date', 'ASC')])
>>> line1, line2, line3 = lines
>>> line1.debit, line1.amount
(Decimal('36.00'), Decimal('40.00'))
>>> assertEqual(line1.maturity_date, period.end_date)
>>> line2.debit, line2.amount
(Decimal('27.00'), Decimal('30.00'))
>>> assertEqual(line2.maturity_date, period.end_date + relativedelta(months=1))
>>> line3.debit, line3.amount
(Decimal('27.00'), Decimal('30.00'))
>>> assertEqual(line3.maturity_date, period.end_date + relativedelta(months=3))

View File

@@ -0,0 +1,143 @@
======================
Move Template Scenario
======================
Imports::
>>> import datetime
>>> from decimal import Decimal
>>> from proteus import Model, Wizard
>>> from trytond.modules.account.tests.tools import (
... create_chart, create_fiscalyear, create_tax, create_tax_code, get_accounts)
>>> from trytond.modules.company.tests.tools import create_company
>>> from trytond.tests.tools import (
... activate_modules, assertEqual, assertGreaterEqual, assertLessEqual)
>>> today = datetime.date.today()
Activate modules::
>>> config = activate_modules('account', create_company, create_chart)
Create fiscal year::
>>> fiscalyear = create_fiscalyear()
>>> fiscalyear.click('create_period')
>>> period_ids = [p.id for p in fiscalyear.periods]
Get accounts::
>>> accounts = get_accounts()
>>> payable = accounts['payable']
>>> expense = accounts['expense']
>>> tax = accounts['tax']
Create tax code::
>>> TaxCode = Model.get('account.tax.code')
>>> tax = create_tax(Decimal('0.1'))
>>> tax.save()
>>> base_code = create_tax_code(tax, amount='base')
>>> base_code.save()
>>> tax_code = create_tax_code(tax)
>>> tax_code.save()
Create parties::
>>> Party = Model.get('party.party')
>>> supplier = Party(name='Supplier')
>>> supplier.save()
Create Template::
>>> MoveTemplate = Model.get('account.move.template')
>>> Journal = Model.get('account.journal')
>>> template = MoveTemplate()
>>> template.name = 'Test'
>>> template.journal, = Journal.find([
... ('code', '=', 'CASH'),
... ])
>>> _ = template.keywords.new(name='party', string='Party',
... type_='party')
>>> _ = template.keywords.new(name='description', string='Description',
... type_='char')
>>> _ = template.keywords.new(name='amount', string='Amount',
... type_='numeric', digits=2)
>>> template.description = '{party} - {description}'
>>> line = template.lines.new()
>>> line.operation = 'credit'
>>> line.account = payable
>>> line.party = 'party'
>>> line.amount = 'amount'
>>> line.description = "{description} 1"
>>> line = template.lines.new()
>>> line.operation = 'debit'
>>> line.account = expense
>>> line.amount = 'amount / 1.1'
>>> ttax = line.taxes.new()
>>> ttax.amount = line.amount
>>> ttax.tax = tax
>>> ttax.type = 'base'
>>> line.description = "{description} 2"
>>> line = template.lines.new()
>>> line.operation = 'debit'
>>> line.account = tax.invoice_account
>>> line.amount = 'amount * (1 - 1/1.1)'
>>> line.description = "{description} 3"
>>> ttax = line.taxes.new()
>>> ttax.amount = line.amount
>>> ttax.tax = tax
>>> ttax.type = 'tax'
>>> template.save()
Create Move::
>>> create_move = Wizard('account.move.template.create')
>>> assertEqual(create_move.form.date, today)
>>> period = create_move.form.period
>>> assertLessEqual(period.start_date, today)
>>> assertGreaterEqual(period.end_date, today)
>>> index = fiscalyear.periods.index(create_move.form.period)
>>> next_period = fiscalyear.periods[index + 1]
>>> create_move.form.date = next_period.start_date
>>> assertEqual(create_move.form.period, next_period)
>>> prev_period = fiscalyear.periods[index - 1]
>>> create_move.form.period = prev_period
>>> assertEqual(create_move.form.date, prev_period.end_date)
>>> create_move.form.period = next_period
>>> assertEqual(create_move.form.date, next_period.start_date)
>>> create_move.form.template = template
>>> create_move.execute('keywords')
>>> data = {}
>>> keywords = data['keywords'] = {}
>>> keywords['party'] = supplier.id
>>> keywords['description'] = 'Test'
>>> keywords['amount'] = Decimal('12.24')
>>> context = create_move._context.copy()
>>> context.update(create_move._config.context)
>>> _ = create_move._proxy.execute(create_move.session_id, data, 'create_',
... context)
.. note:: using custom call because proteus doesn't support fake model
Check the Move::
>>> Move = Model.get('account.move')
>>> move, = Move.find([])
>>> len(move.lines)
3
>>> sorted((l.debit, l.credit) for l in move.lines)
[(Decimal('0'), Decimal('12.24')), (Decimal('1.11'), Decimal('0')), (Decimal('11.13'), Decimal('0'))]
>>> sorted([l.description for l in move.lines])
['Test 1', 'Test 2', 'Test 3']
>>> move.description
'Supplier - Test'
>>> with config.set_context(periods=period_ids):
... base_code = TaxCode(base_code.id)
... base_code.amount
Decimal('11.13')
>>> with config.set_context(periods=period_ids):
... tax_code = TaxCode(tax_code.id)
... tax_code.amount
Decimal('1.11')

View File

@@ -0,0 +1,66 @@
=================================
Account Renew Fiscalyear Scenario
=================================
Imports::
>>> from proteus import Wizard
>>> from trytond.modules.account.tests.tools import create_fiscalyear
>>> from trytond.modules.company.tests.tools import create_company
>>> from trytond.tests.tools import activate_modules, assertEqual
Activate modules::
>>> config = activate_modules('account', create_company)
Create fiscal year::
>>> fiscalyear = create_fiscalyear()
>>> fiscalyear.click('create_period')
>>> period = fiscalyear.periods.new()
>>> period.name = 'Adjustment'
>>> period.start_date = fiscalyear.end_date
>>> period.end_date = fiscalyear.end_date
>>> period.type = 'adjustment'
>>> fiscalyear.save()
Set the sequence number::
>>> sequence = fiscalyear.move_sequence
>>> sequence.number_next = 10
>>> sequence.save()
Renew fiscalyear using the wizard::
>>> renew_fiscalyear = Wizard('account.fiscalyear.renew')
>>> renew_fiscalyear.form.reset_sequences = False
>>> renew_fiscalyear.execute('create_')
>>> new_fiscalyear, = renew_fiscalyear.actions[0]
>>> len(new_fiscalyear.periods)
12
>>> int(new_fiscalyear.move_sequence.number_next)
10
Renew fiscalyear resetting sequences::
>>> renew_fiscalyear = Wizard('account.fiscalyear.renew')
>>> renew_fiscalyear.form.reset_sequences = True
>>> renew_fiscalyear.execute('create_')
>>> new_fiscalyear, = renew_fiscalyear.actions[0]
>>> int(new_fiscalyear.move_sequence.number_next)
1
Set the sequence name::
>>> sequence = new_fiscalyear.move_sequence
>>> sequence.name = 'Sequence %s' % new_fiscalyear.name
>>> sequence.save()
Renew fiscalyear and test sequence name is updated::
>>> renew_fiscalyear = Wizard('account.fiscalyear.renew')
>>> renew_fiscalyear.form.reset_sequences = True
>>> renew_fiscalyear.execute('create_')
>>> new_fiscalyear, = renew_fiscalyear.actions[0]
>>> assertEqual(new_fiscalyear.move_sequence.name,
... 'Sequence %s' % new_fiscalyear.name)

View File

@@ -0,0 +1,366 @@
========================
Account Reports Scenario
========================
Imports::
>>> import datetime as dt
>>> from decimal import Decimal
>>> from proteus import Model, Report
>>> from trytond.modules.account.tests.tools import (
... create_chart, create_fiscalyear, get_accounts)
>>> from trytond.modules.company.tests.tools import create_company, get_company
>>> from trytond.tests.tools import activate_modules
>>> today = dt.date.today()
Activate modules::
>>> config = activate_modules('account', create_company, create_chart)
>>> company = get_company()
Create fiscal year::
>>> fiscalyear = create_fiscalyear(today=today)
>>> fiscalyear.click('create_period')
>>> periods = fiscalyear.periods
>>> period_1, period_3, period_5 = periods[0], periods[2], periods[4]
Get accounts::
>>> accounts = get_accounts()
>>> receivable = accounts['receivable']
>>> revenue = accounts['revenue']
>>> expense = accounts['expense']
>>> cash = accounts['cash']
Create a child account::
>>> _ = revenue.childs.new()
>>> revenue.save()
>>> child_revenue, = revenue.childs
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_3
>>> move.journal = journal_revenue
>>> move.date = period_3.start_date
>>> line = move.lines.new()
>>> line.account = child_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_5
>>> move.journal = journal_cash
>>> move.date = period_5.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_child_revenue, = GeneralLedgerAccount.find([
... ('account', '=', child_revenue.id),
... ])
... gl_revenue, = GeneralLedgerAccount.find([
... ('account', '=', revenue.id),
... ])
... glp_receivable, = GeneralLedgerAccountParty.find([
... ('account', '=', receivable.id),
... ('party', '=', party.id),
... ])
>>> gl_child_revenue.start_balance
Decimal('0.00')
>>> gl_child_revenue.credit
Decimal('10.00')
>>> gl_child_revenue.debit
Decimal('0.00')
>>> gl_child_revenue.end_balance
Decimal('-10.00')
>>> gl_child_revenue.line_count
1
>>> gl_revenue.start_balance
Decimal('0.00')
>>> gl_revenue.credit
Decimal('0.00')
>>> gl_revenue.debit
Decimal('0.00')
>>> gl_revenue.end_balance
Decimal('-10.00')
>>> gl_revenue.line_count
0
>>> 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')
>>> glp_receivable.line_count
2
>>> context = {
... 'company': company.id,
... 'fiscalyear': fiscalyear.id,
... 'from_date': period_1.start_date,
... 'to_date': period_3.end_date,
... }
>>> with config.set_context(context):
... gl_child_revenue, = GeneralLedgerAccount.find([
... ('account', '=', child_revenue.id),
... ])
... gl_revenue, = GeneralLedgerAccount.find([
... ('account', '=', revenue.id),
... ])
... glp_receivable, = GeneralLedgerAccountParty.find([
... ('account', '=', receivable.id),
... ('party', '=', party.id),
... ])
>>> gl_child_revenue.start_balance
Decimal('0.00')
>>> gl_child_revenue.credit
Decimal('10.00')
>>> gl_child_revenue.debit
Decimal('0.00')
>>> gl_child_revenue.end_balance
Decimal('-10.00')
>>> gl_child_revenue.line_count
1
>>> gl_revenue.start_balance
Decimal('0.00')
>>> gl_revenue.credit
Decimal('0.00')
>>> gl_revenue.debit
Decimal('0.00')
>>> gl_revenue.end_balance
Decimal('-10.00')
>>> gl_revenue.line_count
0
>>> glp_receivable.start_balance
Decimal('0.00')
>>> glp_receivable.credit
Decimal('0.00')
>>> glp_receivable.debit
Decimal('10.00')
>>> glp_receivable.end_balance
Decimal('10.00')
>>> glp_receivable.line_count
1
>>> context = {
... 'company': company.id,
... 'fiscalyear': fiscalyear.id,
... 'start_period': period_3.id,
... }
>>> with config.set_context(context):
... gl_child_revenue, = GeneralLedgerAccount.find([
... ('account', '=', child_revenue.id),
... ])
... gl_revenue, = GeneralLedgerAccount.find([
... ('account', '=', revenue.id),
... ])
>>> gl_child_revenue.start_balance
Decimal('0.00')
>>> gl_child_revenue.credit
Decimal('10.00')
>>> gl_child_revenue.debit
Decimal('0.00')
>>> gl_child_revenue.end_balance
Decimal('-10.00')
>>> gl_child_revenue.line_count
1
>>> gl_revenue.start_balance
Decimal('0.00')
>>> gl_revenue.credit
Decimal('0.00')
>>> gl_revenue.debit
Decimal('0.00')
>>> gl_revenue.end_balance
Decimal('-10.00')
>>> gl_revenue.line_count
0
>>> context = {
... 'company': company.id,
... 'fiscalyear': fiscalyear.id,
... 'start_period': period_5.id,
... }
>>> with config.set_context(context):
... gl_child_revenue, = GeneralLedgerAccount.find([
... ('account', '=', child_revenue.id),
... ])
... gl_revenue, = GeneralLedgerAccount.find([
... ('account', '=', revenue.id),
... ])
>>> gl_child_revenue.start_balance
Decimal('-10.00')
>>> gl_child_revenue.credit
Decimal('0.00')
>>> gl_child_revenue.debit
Decimal('0.00')
>>> gl_child_revenue.end_balance
Decimal('-10.00')
>>> gl_child_revenue.line_count
0
>>> 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')
>>> gl_revenue.line_count
0
>>> context = {
... 'company': company.id,
... 'fiscalyear': fiscalyear.id,
... 'from_date': period_3.start_date,
... }
>>> with config.set_context(context):
... gl_child_revenue, = GeneralLedgerAccount.find([
... ('account', '=', child_revenue.id),
... ])
... gl_revenue, = GeneralLedgerAccount.find([
... ('account', '=', revenue.id),
... ])
>>> gl_child_revenue.start_balance
Decimal('0.00')
>>> gl_child_revenue.credit
Decimal('10.00')
>>> gl_child_revenue.debit
Decimal('0.00')
>>> gl_child_revenue.end_balance
Decimal('-10.00')
>>> gl_child_revenue.line_count
1
>>> gl_revenue.start_balance
Decimal('0.00')
>>> gl_revenue.credit
Decimal('0.00')
>>> gl_revenue.debit
Decimal('0.00')
>>> gl_revenue.end_balance
Decimal('-10.00')
>>> gl_revenue.line_count
0
>>> context = {
... 'company': company.id,
... 'fiscalyear': fiscalyear.id,
... 'from_date': period_5.start_date,
... }
>>> with config.set_context(context):
... gl_child_revenue, = GeneralLedgerAccount.find([
... ('account', '=', child_revenue.id),
... ])
... gl_revenue, = GeneralLedgerAccount.find([
... ('account', '=', revenue.id),
... ])
>>> gl_child_revenue.start_balance
Decimal('-10.00')
>>> gl_child_revenue.credit
Decimal('0.00')
>>> gl_child_revenue.debit
Decimal('0.00')
>>> gl_child_revenue.end_balance
Decimal('-10.00')
>>> gl_child_revenue.line_count
0
>>> 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')
>>> gl_revenue.line_count
0
>>> trial_balance = Report('account.trial_balance', context={
... 'company': company.id,
... 'fiscalyear': fiscalyear.id,
... })
>>> _ = trial_balance.execute(gl_accounts)
>>> Type = Model.get('account.account.type')
>>> statement = Report('account.account.type.statement')
>>> _ = statement.execute(Type.find([]))
>>> 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)
>>> general_journal = Report('account.move.general_journal')
>>> _ = general_journal.execute(Move.find([]))
>>> with config.set_context(
... start_date=period_5.start_date,
... end_date=period_5.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')

View File

@@ -0,0 +1,87 @@
=========================
Account Tax Code Scenario
=========================
Imports::
>>> from decimal import Decimal
>>> from proteus import Model, Wizard
>>> from trytond.modules.account.tests.tools import (
... create_chart, create_fiscalyear, create_tax, create_tax_code, get_accounts)
>>> from trytond.modules.company.tests.tools import create_company
>>> from trytond.tests.tools import activate_modules
Activate modules::
>>> config = activate_modules('account', create_company, create_chart)
Create fiscal year::
>>> fiscalyear = create_fiscalyear()
>>> fiscalyear.click('create_period')
>>> period = fiscalyear.periods[0]
Get accounts::
>>> accounts = get_accounts()
Create tax code::
>>> TaxCode = Model.get('account.tax.code')
>>> tax = create_tax(Decimal('0.1'))
>>> tax.save()
>>> base_code = create_tax_code(tax, amount='base')
>>> base_code.save()
>>> tax_code_invoice = create_tax_code(tax)
>>> tax_code_invoice.save()
>>> tax_code_credit = create_tax_code(tax, type='credit')
>>> tax_code_credit.save()
Create parties::
>>> Party = Model.get('party.party')
>>> party = Party(name='Party')
>>> party.save()
Create some moves::
>>> Journal = Model.get('account.journal')
>>> Move = Model.get('account.move')
>>> journal, = Journal.find([
... ('code', '=', 'EXP'),
... ])
>>> move = Move(period=period, journal=journal)
>>> move.date = period.start_date
>>> line = move.lines.new()
>>> line.account = accounts['expense']
>>> line.credit = Decimal(10)
>>> line = move.lines.new()
>>> line.account = accounts['payable']
>>> line.debit = Decimal(11)
>>> line.party = party
>>> line = move.lines.new()
>>> line.account = accounts['tax']
>>> line.credit = Decimal(1)
>>> tax_line = line.tax_lines.new()
>>> tax_line.amount = line.credit
>>> tax_line.type = 'tax'
>>> tax_line.tax = tax
>>> move.save()
>>> _ = move.duplicate()
>>> cancel_move = Wizard('account.move.cancel', [move])
>>> cancel_move.form.reversal = False
>>> cancel_move.execute('cancel')
Check tax code::
>>> TaxCode = Model.get('account.tax.code')
>>> with config.set_context(periods=[period.id]):
... tax_code_invoice = TaxCode(tax_code_invoice.id)
... tax_code_credit = TaxCode(tax_code_credit.id)
>>> tax_code_invoice.amount, tax_code_credit.amount
(Decimal('1.00'), Decimal('0.00'))

View File

@@ -0,0 +1,37 @@
=========================
Account Tax Test Scenario
=========================
Imports::
>>> from decimal import Decimal
>>> from proteus import Wizard
>>> from trytond.modules.account.tests.tools import (
... create_chart, create_tax, get_accounts)
>>> from trytond.modules.company.tests.tools import create_company
>>> from trytond.tests.tools import activate_modules, assertEqual
Activate modules::
>>> config = activate_modules('account', create_company, create_chart)
Get accounts::
>>> accounts = get_accounts()
Create tax::
>>> tax = create_tax(Decimal('0.1'))
>>> tax.save()
Test Tax::
>>> tax_test = Wizard('account.tax.test')
>>> tax_test.form.unit_price = Decimal('100.00')
>>> tax_test.form.taxes.append(tax)
>>> result, = tax_test.form.result
>>> assertEqual(result.tax, tax)
>>> assertEqual(result.account, accounts['tax'])
>>> assertEqual(result.base, Decimal('100.00'))
>>> assertEqual(result.amount, Decimal('10.00'))

File diff suppressed because it is too large Load Diff

View 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)

View File

@@ -0,0 +1,151 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import datetime
from dateutil.relativedelta import relativedelta
from proteus import Model, Wizard
from proteus.config import get_config
from trytond.modules.company.tests.tools import get_company
__all__ = ['create_fiscalyear', 'create_chart', 'get_accounts',
'create_tax', 'create_tax_code']
def create_fiscalyear(company=None, today=None, config=None):
"Create a fiscal year for the company on today or range"
FiscalYear = Model.get('account.fiscalyear', config=config)
Sequence = Model.get('ir.sequence.strict', config=config)
SequenceType = Model.get('ir.sequence.type', config=config)
if not company:
company = get_company(config=config)
if not today:
today = datetime.date.today()
if isinstance(today, datetime.date):
start_date = end_date = today
else:
start_date, end_date = today
today = start_date + (end_date - start_date) / 2
start_date = min(start_date, today - relativedelta(months=6, day=1))
end_date = max(end_date, today + relativedelta(months=5, day=31))
assert start_date <= end_date
fiscalyear = FiscalYear(name=str(today.year))
fiscalyear.start_date = start_date
fiscalyear.end_date = end_date
fiscalyear.company = company
sequence_type, = SequenceType.find(
[('name', '=', "Account Move")], limit=1)
move_sequence = Sequence(
name=str(today.year),
sequence_type=sequence_type,
company=company)
move_sequence.save()
fiscalyear.move_sequence = move_sequence
return fiscalyear
def create_chart(
company=None, chart='account.account_template_root_en', config=None):
"Create chart of accounts"
if config is None:
config = get_config()
AccountTemplate = Model.get('account.account.template', config=config)
ModelData = Model.get('ir.model.data', config=config)
if not company:
company = get_company(config=config)
chart_id = ModelData.get_id(chart, config.context)
account_template = AccountTemplate(chart_id)
create_chart = Wizard('account.create_chart', config=config)
create_chart.execute('account')
create_chart.form.account_template = account_template
create_chart.form.company = company
create_chart.execute('create_account')
accounts = get_accounts(company, config=config)
if accounts['receivable'].party_required:
create_chart.form.account_receivable = accounts['receivable']
if accounts['payable'].party_required:
create_chart.form.account_payable = accounts['payable']
if hasattr(create_chart.form, 'category_account_expense'):
create_chart.form.category_account_expense = accounts['expense']
if hasattr(create_chart.form, 'category_account_revenue'):
create_chart.form.category_account_revenue = accounts['revenue']
create_chart.execute('create_properties')
return create_chart
def get_accounts(company=None, config=None):
"Return accounts per kind"
Account = Model.get('account.account', config=config)
if not company:
company = get_company(config=config)
accounts = {}
for type in ['receivable', 'payable', 'revenue', 'expense']:
try:
accounts[type], = Account.find([
('type.%s' % type, '=', True),
('company', '=', company.id),
('closed', '!=', True),
], limit=1)
except ValueError:
pass
try:
accounts['cash'], = Account.find([
('company', '=', company.id),
('code', '=', '1.1.1'),
], limit=1)
except ValueError:
pass
try:
accounts['tax'], = Account.find([
('company', '=', company.id),
('code', '=', '6.3.6'),
], limit=1)
except ValueError:
pass
return accounts
def create_tax(rate, company=None, config=None):
"Create a tax of rate"
Tax = Model.get('account.tax', config=config)
if not company:
company = get_company(config=config)
accounts = get_accounts(company, config=config)
tax = Tax()
tax.name = 'Tax %s' % rate
tax.description = tax.name
tax.type = 'percentage'
tax.rate = rate
tax.invoice_account = accounts['tax']
tax.credit_note_account = accounts['tax']
return tax
def create_tax_code(
tax, amount='tax', type='invoice', operator='+', config=None):
"Create a tax code for the tax"
TaxCode = Model.get('account.tax.code', config=config)
tax_code = TaxCode(name="Tax Code %s" % tax.name)
tax_code.company = tax.company
line = tax_code.lines.new()
line.operator = '+'
line.tax = tax
line.amount = amount
line.type = type
return tax_code