Commit ed692acb authored by Romain Courteaud's avatar Romain Courteaud

slapos_accounting: drop Entity_statSlapOSOutstandingAmount

parent 3ce9d0a0
portal = context.getPortalObject()
from DateTime import DateTime
if contract is None:
contract = portal.portal_catalog.getResultValue(
portal_type="Cloud Contract",
default_destination_section_uid=context.getUid(),
validation_state=['invalidated', 'validated'],
)
if contract is None:
return context.Entity_statOutstandingAmount()
# We evaluate Multiple scenarios
amount = context.Entity_statOutstandingAmount()
# All payed so just return
if not amount:
return amount
maximum_invoice_delay = contract.getMaximumInvoiceDelay()
maximum_invoice_credit = 0.0
# For now we only support those 2 currencies
currency_uid_list = [
portal.currency_module.EUR.getUid(),
portal.currency_module.CNY.getUid(),
]
contract_line_list = contract.objectValues(
portal_type="Cloud Contract Line")
if not len(contract_line_list):
return context.Entity_statOutstandingAmount(
at_date=at_date)
for currency_uid in currency_uid_list:
for line in contract_line_list:
if line.getPriceCurrencyUid() == currency_uid:
maximum_invoice_credit = line.getMaximumInvoiceCredit()
amount_per_currency = context.Entity_statOutstandingAmount(
at_date=at_date, resource_uid=currency_uid)
if amount_per_currency > maximum_invoice_credit:
return amount_per_currency - maximum_invoice_credit
# We exceed maximum amount because
# user already requested too much
if maximum_invoice_delay:
# Recalculate now ignoring the all invoices from lastest days.
at_date = DateTime()-maximum_invoice_delay
return context.Entity_statOutstandingAmount(
at_date=at_date)
return amount
<?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>contract=None, at_date=None, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Entity_statSlapOSOutstandingAmount</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
# Copyright (c) 2013 Nexedi SA and Contributors. All Rights Reserved.
from erp5.component.test.SlapOSTestCaseMixin import SlapOSTestCaseMixinWithAbort, simulate
from DateTime import DateTime
class TestSlapOSEntity_statSlapOSOutstandingAmount(SlapOSTestCaseMixinWithAbort):
def createPerson(self):
new_id = self.generateNewId()
return self.portal.person_module.newContent(
portal_type='Person',
title="Person %s" % new_id,
reference="TESTPERS-%s" % new_id,
)
def createCloudContract(self):
new_id = self.generateNewId()
return self.portal.cloud_contract_module.newContent(
portal_type='Cloud Contract',
title="Contract %s" % new_id,
reference="TESTCONTRACT-%s" % new_id,
)
@simulate("Entity_statOutstandingAmount", "*args, **kwargs",
"return 'simulated_result'")
def test_outstanding_amount_missing_cloud_contract(self):
person = self.createPerson()
self.assertEqual('simulated_result',
person.Entity_statSlapOSOutstandingAmount())
@simulate("Entity_statOutstandingAmount", "*args, **kwargs",
"return None")
def test_outstanding_with_cloud_contract_but_no_amount(self):
person = self.createPerson()
cloud_contract = self.createCloudContract()
cloud_contract.setDestinationSection(person.getRelativeUrl())
cloud_contract.validate()
# Provide contract w/o indexation
self.assertEqual(None,
person.Entity_statSlapOSOutstandingAmount(contract=cloud_contract))
self.tic()
# Provide contract w/o indexation
self.assertEqual(None,
person.Entity_statSlapOSOutstandingAmount())
@simulate("Entity_statOutstandingAmount", "*args, **kwargs",
"return kwargs.get('at_date', 195.0)")
def test_outstanding_with_cloud_contract_but_no_line(self):
person = self.createPerson()
cloud_contract = self.createCloudContract()
cloud_contract.setDestinationSection(person.getRelativeUrl())
cloud_contract.validate()
self.tic()
# Without Lines the result uses at_date
at_date=DateTime()
self.assertEqual(at_date,
person.Entity_statSlapOSOutstandingAmount(at_date=at_date))
@simulate("Entity_statOutstandingAmount", "at_date=None, resource_uid=None",
"""
from DateTime import DateTime
assert at_date in (None, DateTime().earliestTime()-1)
if at_date == DateTime().earliestTime()-1:
return -999
if resource_uid in (None, context.currency_module.EUR.getUid()):
return 195.0
else:
return 0""")
def test_outstanding_with_cloud_contract_with_linein_euro(self):
person = self.createPerson()
cloud_contract = self.createCloudContract()
cloud_contract.setDestinationSection(person.getRelativeUrl())
cloud_contract.validate()
line = cloud_contract.newContent(
price_currency_value=self.portal.currency_module.CNY,
maximum_invoice_credit=10.0
)
self.tic()
# Without Lines the result uses at_date
self.assertEqual(195.0,
person.Entity_statSlapOSOutstandingAmount())
line.edit(
price_currency_value=self.portal.currency_module.EUR,
)
# Without Lines the result uses at_date
self.assertEqual(185.0,
person.Entity_statSlapOSOutstandingAmount())
line.setMaximumInvoiceCredit(200)
# Without Lines the result uses at_date
self.assertEqual(195.0,
person.Entity_statSlapOSOutstandingAmount())
# We need at least one day
cloud_contract.setMaximumInvoiceDelay(1)
self.pinDateTime(DateTime().earliestTime())
self.addCleanup(self.unpinDateTime)
# Without Lines the result uses at_date
self.assertEqual(-999,
person.Entity_statSlapOSOutstandingAmount())
self.unpinDateTime()
\ 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>testSlapOSContractSkins</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testSlapOSContractSkins</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,6 +5,5 @@ test.erp5.testSlapOSAccountingInteractionWorkflow
test.erp5.testSlapOSAccountingRule
test.erp5.testSlapOSAccountingSkins
test.erp5.testSlapOSConsumptionSkins
test.erp5.testSlapOSContractSkins
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