Commit 9954e8c8 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_accounting: Create and close accounting period for create Balance Transaction

parent 50dc2fc4
......@@ -11,7 +11,6 @@ from DateTime import DateTime
class TestSlapOSManualAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
def bootstrapManualAccountingTest(self):
currency, _, _, sale_person = self.bootstrapVirtualMasterTest()
self.tic()
......@@ -69,6 +68,40 @@ class TestSlapOSManualAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
return accountant_person, accountant_organisation, \
bank_account, currency
def createBalanceForOrganisation(self, accountant, organisation, transaction_list):
# Group is required and should be unique, else the Balance will
# generate/cover way too much.
self.login()
group = self.portal.portal_categories.group.newContent(
id='test_group_%s' % self.generateNewId(),
title="Group for %s" % organisation.getTitle()
)
self.logout()
self.login(accountant.getUserId())
organisation.setGroup(group.getId())
# Create Accounting Period and start
year = DateTime().strftime("%Y")
accounting_period = organisation.newContent(
portal_type="Accounting Period",
title=year,
start_date=DateTime("%s/01/01" % year),
stop_date=DateTime("%s/12/31" % year)
)
self.portal.portal_workflow.doActionFor(accounting_period, "start_action")
self.tic()
# Close all transactions before close the period.
for transaction in transaction_list:
self.portal.portal_workflow.doActionFor(transaction, "deliver_action")
self.tic()
self.portal.portal_workflow.doActionFor(accounting_period, "stop_action",
profit_and_loss_account="account_module/profit_loss")
self.tic()
def groupAndAssertLineList(self, entity, line_list):
# Emulate the Grouping fast input
grouped_line_list = entity.AccountingTransaction_guessGroupedLines(
......@@ -94,7 +127,6 @@ class TestSlapOSManualAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
self.tic()
self.assertEqual(transaction.getSimulationState(), 'stopped')
def test_purchase_invoice_transaction(self, provider_as_organisation=False):
"""
Accountant creates a Purchase Invoice Transaction and group it with a
......@@ -202,12 +234,12 @@ class TestSlapOSManualAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
self.groupAndAssertLineList(
provider, [payable_line, purchase_payable_line])
self.createBalanceForOrganisation(
accountant_person, accountant_organisation, [payment, transaction])
def test_purchase_invoice_transaction_organisation(self):
self.test_purchase_invoice_transaction(provider_as_organisation=False)
# def test_balance_transaction(self):
# Do fake balance for 2023 ?
def test_accounting_transaction(self, customer_as_organisation=False):
""" Basic scenario for accountant create an Accounting transaction
to rembourse a customer (person by default)
......@@ -306,6 +338,9 @@ class TestSlapOSManualAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
self.groupAndAssertLineList(
customer, [payable_line, accounting_payable_line])
self.createBalanceForOrganisation(
accountant_person, accountant_organisation, [payment, transaction])
def test_accounting_transaction_organisation(self):
""" Basic scenario for accountant create an Accounting transaction
to rembourse a customer (organisation)
......@@ -326,11 +361,12 @@ class TestSlapOSManualAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
trade_condition = self.portal.sale_trade_condition_module.newContent(
portal_type='Sale Trade Condition',
trade_condition_type='default',
reference='manual_accounting_for_%s' % accountant_organisation.getReference(),
reference='manual_accounting_for_%s' % accountant_person.getReference(),
specialise_value=business_process_module.slapos_manual_accounting_business_process
)
self.portal.portal_workflow.doActionFor(trade_condition, 'validate_action')
self.assertEqual(trade_condition.checkConsistency(), [])
self.tic()
self.login(accountant_person.getUserId())
......@@ -426,7 +462,10 @@ class TestSlapOSManualAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
self.groupAndAssertLineList(
customer, [receivable_line, transaction.receivable])
self.createBalanceForOrganisation(
accountant_person, accountant_organisation, [payment, transaction])
def test_sale_invoice_transaction_organisation(self):
""" Basic scenario for accountant create an Sale invoice transaction
to sell services for a customer (Organisation)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment