Commit 89b128aa authored by Romain Courteaud's avatar Romain Courteaud

slapos_accounting: test: wip accounting checks

parent 2277bd25
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2022 Nexedi SA and Contributors. All Rights Reserved.
#
##############################################################################
from erp5.component.test.testSlapOSERP5VirtualMasterScenario import TestSlapOSVirtualMasterScenarioMixin
from DateTime import DateTime
class PinnedDateTime(object):
"""
Context manager for changing the zope date
"""
def __init__(self, testinstance, datetime):
self.datetime = datetime
self.testinstance = testinstance
def __enter__(self):
self.testinstance.pinDateTime(self.datetime)
def __exit__(self, *args, **kw):
self.testinstance.unpinDateTime()
class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
def bootstrapAccountingTest(self):
currency, _, _, sale_person = self.bootstrapVirtualMasterTest()
self.tic()
self.logout()
# lets join as slapos administrator, which will manager the project
owner_reference = 'project-%s' % self.generateNewId()
self.joinSlapOS(self.web_site, owner_reference)
self.login()
owner_person = self.portal.portal_catalog.getResultValue(
portal_type="ERP5 Login",
reference=owner_reference).getParentValue()
self.tic()
self.logout()
self.login(sale_person.getUserId())
with PinnedDateTime(self, DateTime('2020/01/01')):
project_relative_url = self.addProject(
is_accountable=True,
person=owner_person,
currency=currency
)
self.tic()
self.logout()
self.login()
project = self.portal.restrictedTraverse(project_relative_url)
preference = self.portal.portal_preferences.slapos_default_system_preference
preference.edit(
preferred_subscription_assignment_category_list=[
'function/customer',
'role/client',
'destination_project/%s' % project.getRelativeUrl()
]
)
return owner_person, currency, project
def test_rejectedSubscriptionScenario(self):
"""
User does not pay the subscription, which is cancelled after some time
"""
_, _, project = self.bootstrapAccountingTest()
self.assertEqual(project.getValidationState(), "invalidated")
subscription_request = self.portal.portal_catalog.getResultValue(
portal_type="Subscription Request",
aggregate__uid=project.getUid()
)
self.assertEqual(subscription_request.getSimulationState(), "cancelled")
# Ensure no unexpected object has been created
# 2 assignment
# 2 sale trade condition
# 1 subscription requests
self.assertRelatedObjectCount(project, 5)
self.checkERP5StateBeforeExit()
def test_notPaidOpenOrderScenario(self):
"""
User does not pay the subscription, which is cancelled after some time
"""
with PinnedDateTime(self, DateTime('2020/05/19')):
owner_person, currency, project = self.bootstrapAccountingTest()
# Ensure no unexpected object has been created
# 2 assignment
# 2 sale trade condition
# 1 subscription requests
self.assertRelatedObjectCount(project, 5)
self.assertEqual(project.getValidationState(), "validated")
subscription_request = self.portal.portal_catalog.getResultValue(
portal_type="Subscription Request",
aggregate__uid=project.getUid()
)
self.assertEqual(subscription_request.getSimulationState(), "submitted")
with PinnedDateTime(self, DateTime('2021/04/04')):
payment_transaction = owner_person.Person_addDepositPayment(99*10, currency.getRelativeUrl(), 1)
payment_transaction.PaymentTransaction_acceptDepositPayment()
self.tic()
self.assertEqual(subscription_request.getSimulationState(), "invalidated")
open_sale_order = self.portal.portal_catalog.getResultValue(
portal_type="Open Sale Order Line",
aggregate__uid=project.getUid()
).getParentValue()
self.assertEqual(open_sale_order.getValidationState(), "validated")
# invoice is the same month's day of the person creation
# So, the open order period before '2021/04/03' starts on '2021/03/19'
self.assertEqual(open_sale_order.getStartDate(), DateTime('2021/03/19'))
self.assertEqual(open_sale_order.getStartDate(),
open_sale_order.getStopDate())
first_invoice = self.portal.portal_catalog.getResultValue(
portal_type="Invoice Line",
aggregate__uid=project.getUid()
).getParentValue()
self.assertEqual(first_invoice.getSimulationState(), "confirmed")
self.assertEqual(first_invoice.getStartDate(), DateTime('2021/03/19'))
self.assertEqual(first_invoice.getStopDate(), DateTime('2021/04/19'))
# Discount and first subscription
self.assertEqual(first_invoice.getTotalPrice(), 24.384)
# Ensure no unexpected object has been created
# 2 assignment
# 2 sale trade condition
# 1 subscription requests
self.assertRelatedObjectCount(project, 10)
with PinnedDateTime(self, DateTime('2021/07/05')):
self.portal.portal_alarms.update_open_order_simulation.activeSense()
self.tic()
self.assertEqual(first_invoice.getSimulationState(), "stopped")
# Ensure no unexpected object has been created
# 1 open order
# 2 assignment
# 2 sale trade condition
# 1 subscription requests
self.assertRelatedObjectCount(project, 22)
with PinnedDateTime(self, DateTime('2021/07/06')):
self.checkERP5StateBeforeExit()
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Test Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>default_reference</string> </key>
<value> <string>testSlapOSERP5AccountingScenario</string> </value>
</item>
<item>
<key> <string>default_source_reference</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testSlapOSERP5AccountingScenario</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Test Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -5,5 +5,6 @@ test.erp5.testSlapOSAccountingInteractionWorkflow
test.erp5.testSlapOSAccountingRule
test.erp5.testSlapOSAccountingSkins
test.erp5.testSlapOSConsumptionSkins
test.erp5.testSlapOSERP5AccountingScenario
test.erp5.testSlapOSEntityCreatePayment
test.erp5.testSlapOSSaleSupply
\ No newline at end of file
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