first commit
This commit is contained in:
2
modules/account_consolidation/tests/__init__.py
Normal file
2
modules/account_consolidation/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.
204
modules/account_consolidation/tests/scenario_consolidation.rst
Normal file
204
modules/account_consolidation/tests/scenario_consolidation.rst
Normal file
@@ -0,0 +1,204 @@
|
||||
==============================
|
||||
Account Consolidation Scenario
|
||||
==============================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> 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
|
||||
>>> from trytond.modules.currency.tests.tools import get_currency
|
||||
>>> from trytond.tests.tools import activate_modules, set_user
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules(['account_consolidation'])
|
||||
|
||||
>>> Company = Model.get('company.company')
|
||||
>>> Consolidation = Model.get('account.consolidation')
|
||||
>>> Journal = Model.get('account.journal')
|
||||
>>> Move = Model.get('account.move')
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> User = Model.get('res.user')
|
||||
|
||||
Get journals::
|
||||
|
||||
>>> expense_journal, = Journal.find([('code', '=', 'EXP')])
|
||||
>>> revenue_journal, = Journal.find([('code', '=', 'REV')])
|
||||
|
||||
Create currencies::
|
||||
|
||||
>>> usd = get_currency('USD')
|
||||
>>> eur = get_currency('EUR')
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> supplier = Party(name="Supplier")
|
||||
>>> supplier.save()
|
||||
>>> customer = Party(name="Customer")
|
||||
>>> customer.save()
|
||||
|
||||
Create companies::
|
||||
|
||||
>>> party = Party(name="Dunder Mifflin")
|
||||
>>> party.save()
|
||||
>>> _ = create_company(party, usd)
|
||||
>>> dunder_mifflin, = Company.find([('party', '=', party.id)], limit=1)
|
||||
|
||||
>>> party = Party(name="Saber")
|
||||
>>> party.save()
|
||||
>>> _ = create_company(party, eur)
|
||||
>>> saber, = Company.find([('party', '=', party.id)], limit=1)
|
||||
|
||||
>>> user = User(config.user)
|
||||
>>> user.company_filter = 'all'
|
||||
>>> user.companies.extend([dunder_mifflin, saber])
|
||||
>>> user.save()
|
||||
>>> set_user(user.id)
|
||||
|
||||
|
||||
Create fiscal year for Dunder Mifflin::
|
||||
|
||||
>>> fiscalyear = create_fiscalyear(dunder_mifflin)
|
||||
>>> fiscalyear.click('create_period')
|
||||
>>> period = fiscalyear.periods[0]
|
||||
|
||||
Create chart of accounts for Dunder Mifflin::
|
||||
|
||||
>>> _ = create_chart(dunder_mifflin)
|
||||
>>> accounts_dunder = get_accounts(dunder_mifflin)
|
||||
|
||||
Create some moves for Dunder Mifflin::
|
||||
|
||||
>>> move = Move(company=dunder_mifflin)
|
||||
>>> move.journal = revenue_journal
|
||||
>>> move.period = period
|
||||
>>> line = move.lines.new(
|
||||
... account=accounts_dunder['receivable'],
|
||||
... party=customer,
|
||||
... debit=Decimal('200.00'))
|
||||
>>> line = move.lines.new(
|
||||
... account=accounts_dunder['revenue'],
|
||||
... credit=Decimal('200.00'))
|
||||
>>> move.click('post')
|
||||
|
||||
>>> move = Move(company=dunder_mifflin, consolidation_company=saber)
|
||||
>>> move.journal = expense_journal
|
||||
>>> move.period = period
|
||||
>>> line = move.lines.new(
|
||||
... account=accounts_dunder['payable'],
|
||||
... party=saber.party,
|
||||
... credit=Decimal('100.00'))
|
||||
>>> line = move.lines.new(
|
||||
... account=accounts_dunder['expense'],
|
||||
... debit=Decimal('100.00'))
|
||||
>>> move.click('post')
|
||||
|
||||
Create fiscal year for Saber::
|
||||
|
||||
>>> fiscalyear = create_fiscalyear(saber)
|
||||
>>> fiscalyear.click('create_period')
|
||||
>>> period = fiscalyear.periods[0]
|
||||
|
||||
Create chart of accounts for Saber::
|
||||
|
||||
>>> _ = create_chart(saber)
|
||||
>>> accounts_saber = get_accounts(saber)
|
||||
|
||||
Create same moves for Saber::
|
||||
|
||||
>>> move = Move(company=saber, consolidation_company=dunder_mifflin)
|
||||
>>> move.journal = revenue_journal
|
||||
>>> move.period = period
|
||||
>>> line = move.lines.new(
|
||||
... account=accounts_saber['receivable'],
|
||||
... party=dunder_mifflin.party,
|
||||
... debit=Decimal('50.00'))
|
||||
>>> line = move.lines.new(
|
||||
... account=accounts_saber['revenue'],
|
||||
... credit=Decimal('50.00'))
|
||||
>>> move.click('post')
|
||||
|
||||
>>> move = Move(company=saber)
|
||||
>>> move.journal = expense_journal
|
||||
>>> move.period = period
|
||||
>>> line = move.lines.new(
|
||||
... account=accounts_saber['payable'],
|
||||
... party=supplier,
|
||||
... credit=Decimal('40.00'))
|
||||
>>> line = move.lines.new(
|
||||
... account=accounts_saber['expense'],
|
||||
... debit=Decimal('40.00'))
|
||||
>>> move.click('post')
|
||||
|
||||
Setup consolidation::
|
||||
|
||||
>>> balance_group = Consolidation(name="Balance")
|
||||
>>> balance_group.statement = 'balance'
|
||||
>>> receivable_group = balance_group.children.new(
|
||||
... name="Receivable", assets=True)
|
||||
>>> receivable_group.types.append(accounts_dunder['receivable'].type)
|
||||
>>> receivable_group.types.append(accounts_saber['receivable'].type)
|
||||
>>> payable_group = balance_group.children.new(
|
||||
... name="Payable")
|
||||
>>> payable_group.types.append(accounts_dunder['payable'].type)
|
||||
>>> payable_group.types.append(accounts_saber['payable'].type)
|
||||
>>> balance_group.save()
|
||||
|
||||
>>> income_group = Consolidation(name="Income")
|
||||
>>> income_group.statement = 'income'
|
||||
>>> income_group.save()
|
||||
|
||||
>>> revenue_group = Consolidation(name="Revenue")
|
||||
>>> revenue_group.statement = 'income'
|
||||
>>> revenue_group.parent = income_group
|
||||
>>> revenue_group.types.append(accounts_dunder['revenue'].type)
|
||||
>>> revenue_group.types.append(accounts_saber['revenue'].type)
|
||||
>>> revenue_group.save()
|
||||
|
||||
>>> expense_group = Consolidation(name="Expense")
|
||||
>>> expense_group.statement = 'income'
|
||||
>>> expense_group.parent = income_group
|
||||
>>> expense_group.types.append(accounts_dunder['expense'].type)
|
||||
>>> expense_group.types.append(accounts_saber['expense'].type)
|
||||
>>> expense_group.save()
|
||||
|
||||
Check consolidation amount only for Dunder Mifflin::
|
||||
|
||||
>>> with config.set_context(
|
||||
... companies=[dunder_mifflin.id], currency=usd.id):
|
||||
... Consolidation(balance_group.id).amount
|
||||
Decimal('-100.00')
|
||||
|
||||
>>> with config.set_context(
|
||||
... companies=[dunder_mifflin.id], currency=eur.id):
|
||||
... Consolidation(balance_group.id).amount
|
||||
Decimal('-200.00')
|
||||
|
||||
>>> with config.set_context(
|
||||
... companies=[dunder_mifflin.id], currency=usd.id):
|
||||
... Consolidation(income_group.id).amount
|
||||
Decimal('100.00')
|
||||
|
||||
Check consolidation amount only for Dunder Mifflin and Saber::
|
||||
|
||||
>>> with config.set_context(
|
||||
... companies=[dunder_mifflin.id, saber.id], currency=usd.id):
|
||||
... Consolidation(balance_group.id).amount
|
||||
Decimal('-180.00')
|
||||
|
||||
>>> with config.set_context(
|
||||
... companies=[dunder_mifflin.id, saber.id], currency=usd.id):
|
||||
... Consolidation(income_group.id).amount
|
||||
Decimal('180.00')
|
||||
|
||||
Test report::
|
||||
|
||||
>>> statement = Report('account.consolidation.statement', context={
|
||||
... 'companies': [dunder_mifflin.id, saber.id],
|
||||
... 'currency': usd.id,
|
||||
... })
|
||||
>>> _ = statement.execute(Consolidation.find([]))
|
||||
64
modules/account_consolidation/tests/scenario_invoice.rst
Normal file
64
modules/account_consolidation/tests/scenario_invoice.rst
Normal file
@@ -0,0 +1,64 @@
|
||||
================
|
||||
Invoice 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.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
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules(['account_consolidation', 'account_invoice'])
|
||||
|
||||
>>> Company = Model.get('company.company')
|
||||
>>> Invoice = Model.get('account.invoice')
|
||||
>>> Party = Model.get('party.party')
|
||||
|
||||
Create companies::
|
||||
|
||||
>>> party = Party(name="Dunder Mifflin")
|
||||
>>> party.save()
|
||||
>>> _ = create_company(party)
|
||||
>>> dunder_mifflin, = Company.find([('party', '=', party.id)], limit=1)
|
||||
|
||||
>>> party = Party(name="Saber")
|
||||
>>> party.save()
|
||||
>>> _ = create_company(party)
|
||||
>>> saber, = Company.find([('party', '=', party.id)], limit=1)
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = set_fiscalyear_invoice_sequences(
|
||||
... create_fiscalyear(dunder_mifflin))
|
||||
>>> fiscalyear.click('create_period')
|
||||
>>> period_ids = [p.id for p in fiscalyear.periods]
|
||||
|
||||
Create chart of accounts::
|
||||
|
||||
>>> _ = create_chart(dunder_mifflin)
|
||||
>>> accounts = get_accounts(dunder_mifflin)
|
||||
|
||||
Create invoice::
|
||||
|
||||
>>> invoice = Invoice()
|
||||
>>> invoice.party = saber.party
|
||||
>>> line = invoice.lines.new()
|
||||
>>> line.account = accounts['revenue']
|
||||
>>> line.quantity = 5
|
||||
>>> line.unit_price = Decimal('10.0000')
|
||||
>>> invoice.click('post')
|
||||
>>> invoice.state
|
||||
'posted'
|
||||
|
||||
Check consolidation company::
|
||||
|
||||
>>> assertEqual(invoice.consolidation_company, saber)
|
||||
>>> assertEqual(invoice.move.consolidation_company, saber)
|
||||
24
modules/account_consolidation/tests/test_module.py
Normal file
24
modules/account_consolidation/tests/test_module.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# 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 CompanyAcountConsolidationTestMixin(CompanyTestMixin):
|
||||
|
||||
@property
|
||||
def _skip_company_rule(self):
|
||||
return super()._skip_company_rule | {
|
||||
('account.move', 'consolidation_company'),
|
||||
('account.invoice', 'consolidation_company'),
|
||||
}
|
||||
|
||||
|
||||
class AccountConsolidationTestCase(
|
||||
CompanyAcountConsolidationTestMixin, ModuleTestCase):
|
||||
"Test Account Consolidation module"
|
||||
module = 'account_consolidation'
|
||||
extras = ['account_invoice']
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
8
modules/account_consolidation/tests/test_scenario.py
Normal file
8
modules/account_consolidation/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