Commit a6bae06d authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_payzen: Include script to get Appropriate State of Payment to show to the user.

parent 44493e2e
simulation_state = context.getSimulationState()
if simulation_state in ("cancelled", "deleted", "draft"):
result = "Cancelled"
elif simulation_state in ("planned", "confirmed", "ordered", "started"):
result = "Ongoing"
else:
portal = context.getPortalObject()
paid = True
for line in context.getMovementList(portal.getPortalAccountingMovementTypeList()):
node_value = line.getSourceValue(portal_type='Account')
if node_value.getAccountType() == 'asset/receivable':
if not line.hasGroupingReference():
paid = False
break
reversal = portal.portal_catalog.getResultValue(
portal_type="Sale Invoice Transaction",
simulation_state="stopped",
default_causality_uid=context.getUid()
)
if reversal is not None and (context.getTotalPrice() + reversal.getTotalPrice()) == 0:
result = "Cancelled"
elif paid:
result = "Paid"
elif context.getTotalPrice() == 0:
result = "Free!"
else:
# Check if there is an ongoing payzen payment
payment = context.SaleInvoiceTransaction_getPayzenPaymentRelatedValue()
if payment is None:
result = "Unpaid"
else:
# Check if mapping exists
person = portal.ERP5Site_getAuthenticatedMemberPersonValue()
payzen_id = person.Person_restrictMethodAsShadowUser(
shadow_document=person,
callable_object=payment.PaymentTransaction_getPayzenId,
argument_list=[])[0]
if payzen_id is None:
result = "Pay now"
else:
result = "Waiting for payment confirmation"
return result
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<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></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>AccountingTransaction_getPaymentState</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -541,6 +541,85 @@ class TestSlapOSPayzenBase_getPayzenServiceRelativeUrl(SlapOSTestCaseMixinWithAb
result = self.portal.Base_getPayzenServiceRelativeUrl()
self.assertEquals(result, 'portal_secure_payments/slapos_payzen_test')
class TestSlapOSPayzenAccountingTransaction_getPaymentState(
SlapOSTestCaseMixinWithAbort):
def test_AccountingTransaction_getPaymentState_draft_payment(self):
invoice = self.createSaleInvoiceTransaction()
self.assertEquals("Cancelled", invoice.AccountingTransaction_getPaymentState())
def test_AccountingTransaction_getPaymentState_deleted_payment(self):
invoice = self.createSaleInvoiceTransaction()
invoice.delete()
self.assertEquals("Cancelled", invoice.AccountingTransaction_getPaymentState())
def test_AccountingTransaction_getPaymentState_cancelled_payment(self):
invoice = self.createSaleInvoiceTransaction()
invoice.cancel()
self.assertEquals("Cancelled", invoice.AccountingTransaction_getPaymentState())
def test_AccountingTransaction_getPaymentState_planned_payment(self):
invoice = self.createSaleInvoiceTransaction()
invoice.plan()
self.assertEquals("Ongoing", invoice.AccountingTransaction_getPaymentState())
def test_AccountingTransaction_getPaymentState_confirmed_payment(self):
invoice = self.createSaleInvoiceTransaction()
invoice.setStartDate(DateTime())
invoice.confirm()
self.assertEquals("Ongoing", invoice.AccountingTransaction_getPaymentState())
def test_AccountingTransaction_getPaymentState_started_payment(self):
invoice = self.createSaleInvoiceTransaction()
invoice.start()
self.assertEquals("Ongoing", invoice.AccountingTransaction_getPaymentState())
def test_AccountingTransaction_getPaymentState_reversed_payment(self):
invoice = self.createPayzenSaleInvoiceTransaction()
self.tic()
reversal = invoice.SaleInvoiceTransaction_createReversalPayzenTransaction()
self.tic()
self.assertEquals("Cancelled", invoice.AccountingTransaction_getPaymentState())
self.assertEquals(0, invoice.getTotalPrice() + reversal.getTotalPrice())
def test_AccountingTransaction_getPaymentState_free_payment(self):
invoice = self.createPayzenSaleInvoiceTransaction(price=0)
self.tic()
self.assertEquals("Free!", invoice.AccountingTransaction_getPaymentState())
def test_AccountingTransaction_getPaymentState_unpaid_payment(self):
invoice = self.createPayzenSaleInvoiceTransaction()
# If payment is not indexed or not started the state should be unpaid
self.assertEquals("Unpaid", invoice.AccountingTransaction_getPaymentState())
def test_AccountingTransaction_getPaymentState_paynow_payment(self):
person = self.makePerson()
invoice = self.createPayzenSaleInvoiceTransaction(
destination_section=person.getRelativeUrl())
self.tic()
self.login(person.getUserId())
self.assertEquals("Pay now", invoice.AccountingTransaction_getPaymentState())
def test_AccountingTransaction_getPaymentState_waiting_payment(self):
person = self.makePerson()
invoice = self.createPayzenSaleInvoiceTransaction(
destination_section=person.getRelativeUrl())
self.tic()
payment = invoice.SaleInvoiceTransaction_getPayzenPaymentRelatedValue()
payment.PaymentTransaction_generatePayzenId()
self.login(person.getUserId())
self.assertEquals("Waiting for payment confirmation",
invoice.AccountingTransaction_getPaymentState())
def test_AccountingTransaction_getPaymentState_paid_payment(self):
invoice = self.createPayzenSaleInvoiceTransaction()
self.tic()
for line in invoice.getMovementList(self.portal.getPortalAccountingMovementTypeList()):
node_value = line.getSourceValue(portal_type='Account')
if node_value.getAccountType() == 'asset/receivable':
line.setGroupingReference("TEST%s" % self.new_id)
self.assertEquals("Paid", invoice.AccountingTransaction_getPaymentState())
class TestSlapOSPayzenSaleInvoiceTransaction_getPayzenPaymentRelatedValue(
SlapOSTestCaseMixinWithAbort):
......
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