Commit d11bb206 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_panel: Fixup to allow us to pay deposit

parent acb86e5c
......@@ -237,6 +237,7 @@ def makeTestSlapOSCodingStyleTestCase(tested_business_template):
'slapos_panel/ComputerNetwork_getNewsDict',
'slapos_panel/ComputerNetwork_invalidateOnSlaposPanel',
'slapos_panel/Document_getNewsDict',
'slapos_panel/Entity_createExternalPaymentTransactionFromDepositAndRedirect',
'slapos_panel/Event_getSafeSourceTitle',
'slapos_panel/InstanceNode_addSlapOSAllocationSupply',
'slapos_panel/InstanceTreeModule_selectRequestProject',
......
......@@ -16,11 +16,11 @@ entity = portal.portal_membership.getAuthenticatedMember().getUserValue()
if entity is None:
return '<p>Nothing to pay with your account</p>'
for currency_uid, secure_service_relative_url in [
(portal.currency_module.EUR.getUid(), portal.Base_getPayzenServiceRelativeUrl()),
# (portal.currency_module.CNY.getUid(), portal.Base_getWechatServiceRelativeUrl())
for currency_value, secure_service_relative_url in [
(portal.currency_module.EUR, portal.Base_getPayzenServiceRelativeUrl()),
# (portal.currency_module.CNY, portal.Base_getWechatServiceRelativeUrl())
]:
currency_uid = currency_value.getCurrencyUid()
if secure_service_relative_url is not None:
# Existing invoices
outstanding_amount_list = entity.Entity_getOutstandingAmountList(
......@@ -36,26 +36,14 @@ for currency_uid, secure_service_relative_url in [
'payment_url': '%s/SaleInvoiceTransaction_createExternalPaymentTransactionFromAmountAndRedirect' % outstanding_amount.absolute_url()
}
# Existing subscription request
deposit_price = 0
for sql_subscription_request in portal.portal_catalog(
portal_type="Subscription Request",
simulation_state='submitted',
destination_section__uid=entity.getUid(),
price_currency__uid=currency_uid,
ledger__uid=ledger_uid
):
subscription_request = sql_subscription_request.getObject()
subscription_request_total_price = subscription_request.getTotalPrice()
if 0 < subscription_request_total_price:
deposit_price += subscription_request_total_price
deposit_price = entity.Entity_getOutstandingDepositAmount(currency_uid)
if 0 < deposit_price:
html_content += """
<p><a href="%(payment_url)s">%(total_price)s %(currency)s</a></p>
""" % {
'total_price': deposit_price,
'currency': currency_uid,
'payment_url': '%s/SaleInvoiceTransaction_createExternalPaymentTransactionFromAmountAndRedirect' % entity.absolute_url()
'currency': currency_value.getReference(),
'payment_url': '%s/Entity_createExternalPaymentTransactionFromDepositAndRedirect?currency_reference=%s' % (entity.absolute_url(), currency_value.getReference())
}
if html_content:
......
portal = context.getPortalObject()
web_site = context.getWebSiteValue()
if currency_reference is not None:
currency_value = portal.portal_catalog.getResultValue(
portal_type="Currency",
reference=currency_reference,
validation_state="validated")
if currency_value is None:
raise ValueError("Unknown Currency: %s" % currency_reference)
currency_uid = currency_value.getUid()
assert web_site is not None
deposit_price = context.Entity_getOutstandingDepositAmount(currency_uid)
if 0 >= deposit_price:
raise ValueError("Nothing to pay")
payment_mode = None
resource_uid = currency_uid
for accepted_resource_uid, accepted_payment_mode, is_activated in [
(portal.currency_module.EUR.getUid(), 'payzen', portal.Base_getPayzenServiceRelativeUrl()),
# (portal.currency_module.CNY, 'wechat', portal.Base_getWechatServiceRelativeUrl())
]:
if is_activated and (resource_uid == accepted_resource_uid):
payment_mode = accepted_payment_mode
assert payment_mode is not None
def wrapWithShadow(entity, total_amount, currency_value):
return entity.Person_addDepositPayment(
total_amount,
currency_value.getRelativeUrl(),
batch=1
)
payment_transaction = context.Person_restrictMethodAsShadowUser(
shadow_document=context,
callable_object=wrapWithShadow,
argument_list=[context, deposit_price, currency_value])
if (payment_mode == "wechat"):
return payment_transaction.PaymentTransaction_redirectToManualWechatPayment(web_site=web_site)
elif (payment_mode == "payzen"):
return payment_transaction.PaymentTransaction_redirectToManualPayzenPayment(web_site=web_site)
else:
raise NotImplementedError('not implemented')
<?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>currency_reference=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Entity_createExternalPaymentTransactionFromDepositAndRedirect</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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