Commit 7c4188b1 authored by Romain Courteaud's avatar Romain Courteaud

slapos_accounting: wip Entity_hasOutstandingAmount

parent 6c186bf4
"""return a list of invoices with the following attributes: """return a list of invoices with the following attributes:
- payment_request_uid: the uid of the invoice, we consider that payment request is the invoice. - payment_request_uid: the uid of the invoice
- node_relative_url : the url of the account ( if group_by_node=True is passed ).
- total_price: the amount left to pay for this invoice - total_price: the amount left to pay for this invoice
- getTotalPrice: the original amount of this invoice. - getTotalPrice: the original amount of this invoice.
Arguments: Arguments:
- group_by_node (default True)
If you pass group_by_node=False you have a list of all invoices,
without the breakdown by account but if you pass group_by_node=True,
you have on line for each account.
To display to the user the list of invoices he has to pay, pass group_by_node=False,
to create a list to pass to Entity_createPaymentTransaction, use group_by_node=True.
- at_date (default None) - at_date (default None)
- include_planned (default True)
In current configuration, planned transactions, are used only in Payment Transactions for invoices of non-debitable customers.
If you pass include_planned=True, you will get only unpaid invoices for which payment deadline is past
If you pass include_planned=False, you will get all unpaid invoices, also those for which payment deadline is not past
""" """
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery, ComplexQuery
portal = context.getPortalObject() portal = context.getPortalObject()
params = dict() params = dict()
if at_date: if at_date:
params['at_date'] = at_date params['at_date'] = at_date
params['grouping_query'] = ComplexQuery(
params['grouping_reference'] = None SimpleQuery(grouping_reference=None),
SimpleQuery(grouping_date=at_date, comparison_operator=">"),
logical_operator="OR")
else:
params['grouping_reference'] = None
object_list = [] object_list = []
if include_planned:
simulation_state_tuple = ('stopped', 'delivered', 'planned', 'confirmed', 'started')
else:
simulation_state_tuple = ('stopped', 'delivered')
if section_uid is None:
params['group_by_mirror_section'] = True
else:
params['section_uid'] = section_uid
if resource_uid is None:
params['group_by_resource'] = True
else:
params['resource_uid'] = resource_uid
for (idx, brain) in enumerate(portal.portal_simulation.getInventoryList( for (idx, brain) in enumerate(portal.portal_simulation.getInventoryList(
mirror_section_uid=context.getUid(), mirror_section_uid=context.getUid(),
simulation_state=('stopped', 'delivered'), simulation_state=simulation_state_tuple,
group_by_payment_request=True,
group_by_node=group_by_node,
node_uid=[x.uid for x in context.Base_getReceivableAccountList()] or -1, node_uid=[x.uid for x in context.Base_getReceivableAccountList()] or -1,
**params )): **params )):
...@@ -26,7 +60,6 @@ for (idx, brain) in enumerate(portal.portal_simulation.getInventoryList( ...@@ -26,7 +60,6 @@ for (idx, brain) in enumerate(portal.portal_simulation.getInventoryList(
# directly in listbox. We should probably add support for this in getInventoryList instead # directly in listbox. We should probably add support for this in getInventoryList instead
# of this hack # of this hack
# XXX In our case, this hould be always None.
payment_request_uid = brain.payment_request_uid payment_request_uid = brain.payment_request_uid
if not payment_request_uid: if not payment_request_uid:
payment_request_uid = brain.getObject().getExplanationUid() payment_request_uid = brain.getObject().getExplanationUid()
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>at_date=None, **kw</string> </value> <value> <string>resource_uid=None, section_uid=None, group_by_node=True, at_date=None, include_planned=True, **kw</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>*args, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Entity_hasOutstandingAmount</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -97,6 +97,8 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin): ...@@ -97,6 +97,8 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
# 1 subscription requests # 1 subscription requests
self.assertRelatedObjectCount(project, 5) self.assertRelatedObjectCount(project, 5)
self.assertFalse(owner_person.Entity_hasOutstandingAmount())
self.assertFalse(owner_person.Entity_hasOutstandingAmount(include_planned=False))
self.assertEqual(project.getValidationState(), "validated") self.assertEqual(project.getValidationState(), "validated")
subscription_request = self.portal.portal_catalog.getResultValue( subscription_request = self.portal.portal_catalog.getResultValue(
portal_type="Subscription Request", portal_type="Subscription Request",
...@@ -109,6 +111,11 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin): ...@@ -109,6 +111,11 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
payment_transaction.PaymentTransaction_acceptDepositPayment() payment_transaction.PaymentTransaction_acceptDepositPayment()
self.tic() self.tic()
self.assertTrue(owner_person.Entity_hasOutstandingAmount())
amount_list = owner_person.Entity_getOutstandingAmountList()
self.assertEquals(len(amount_list), 1)
self.assertEquals(amount_list[0].total_price, 24.384)
self.assertFalse(owner_person.Entity_hasOutstandingAmount(include_planned=False))
self.assertEqual(subscription_request.getSimulationState(), "invalidated") self.assertEqual(subscription_request.getSimulationState(), "invalidated")
open_sale_order = self.portal.portal_catalog.getResultValue( open_sale_order = self.portal.portal_catalog.getResultValue(
portal_type="Open Sale Order Line", portal_type="Open Sale Order Line",
...@@ -124,6 +131,7 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin): ...@@ -124,6 +131,7 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
portal_type="Invoice Line", portal_type="Invoice Line",
aggregate__uid=project.getUid() aggregate__uid=project.getUid()
).getParentValue() ).getParentValue()
self.assertEqual(first_invoice.getUid(), amount_list[0].payment_request_uid)
self.assertEqual(first_invoice.getSimulationState(), "confirmed") self.assertEqual(first_invoice.getSimulationState(), "confirmed")
self.assertEqual(first_invoice.getStartDate(), DateTime('2021/03/19')) self.assertEqual(first_invoice.getStartDate(), DateTime('2021/03/19'))
self.assertEqual(first_invoice.getStopDate(), DateTime('2021/04/19')) self.assertEqual(first_invoice.getStopDate(), DateTime('2021/04/19'))
...@@ -139,6 +147,14 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin): ...@@ -139,6 +147,14 @@ class TestSlapOSAccountingScenario(TestSlapOSVirtualMasterScenarioMixin):
self.portal.portal_alarms.update_open_order_simulation.activeSense() self.portal.portal_alarms.update_open_order_simulation.activeSense()
self.tic() self.tic()
self.assertTrue(owner_person.Entity_hasOutstandingAmount())
amount_list = owner_person.Entity_getOutstandingAmountList()
self.assertEquals(len(amount_list), 1)
self.assertEquals(amount_list[0].total_price, 175.584)
self.assertTrue(owner_person.Entity_hasOutstandingAmount(include_planned=False))
amount_list = owner_person.Entity_getOutstandingAmountList(include_planned=False)
self.assertEquals(len(amount_list), 1)
self.assertEquals(amount_list[0].total_price, 125.184)
self.assertEqual(first_invoice.getSimulationState(), "stopped") self.assertEqual(first_invoice.getSimulationState(), "stopped")
# Ensure no unexpected object has been created # Ensure no unexpected object has been created
# 1 open order # 1 open order
......
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