Commit f1dc41ed authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_panel: Handle deposit outstanding amount as a list

   Since it should handle multiple *_section.
parent 752f6121
...@@ -16,33 +16,45 @@ entity = portal.portal_membership.getAuthenticatedMember().getUserValue() ...@@ -16,33 +16,45 @@ entity = portal.portal_membership.getAuthenticatedMember().getUserValue()
if entity is None: if entity is None:
return '<p>Nothing to pay with your account</p>' return '<p>Nothing to pay with your account</p>'
is_payment_configured = 1
for currency_value, secure_service_relative_url in [ for currency_value, secure_service_relative_url in [
(portal.currency_module.EUR, portal.Base_getPayzenServiceRelativeUrl()), (portal.currency_module.EUR, portal.Base_getPayzenServiceRelativeUrl()),
# (portal.currency_module.CNY, portal.Base_getWechatServiceRelativeUrl()) # (portal.currency_module.CNY, portal.Base_getWechatServiceRelativeUrl())
]: ]:
currency_uid = currency_value.getUid() currency_uid = currency_value.getUid()
if secure_service_relative_url is not None:
# Existing invoices if secure_service_relative_url is None:
outstanding_amount_list = entity.Entity_getOutstandingAmountList( is_payment_configured = 0
ledger_uid=ledger_uid,
resource_uid=currency_uid outstanding_amount_list = entity.Entity_getOutstandingAmountList(
) ledger_uid=ledger_uid,
for outstanding_amount in outstanding_amount_list: resource_uid=currency_uid
html_content += """ )
<p><a href="%(payment_url)s">%(total_price)s %(currency)s</a></p> for outstanding_amount in outstanding_amount_list:
""" % { if not is_payment_configured:
'total_price': outstanding_amount.total_price, return '<p>Please contact us to handle your payment</p>'
'currency': outstanding_amount.getPriceCurrencyReference(),
'payment_url': '%s/SaleInvoiceTransaction_createExternalPaymentTransactionFromAmountAndRedirect' % outstanding_amount.absolute_url() html_content += """
} <p><a href="%(payment_url)s">%(total_price)s %(currency)s</a></p>
""" % {
deposit_price = entity.Entity_getOutstandingDepositAmount(currency_uid) 'total_price': outstanding_amount.total_price,
if 0 < deposit_price: 'currency': outstanding_amount.getPriceCurrencyReference(),
'payment_url': '%s/SaleInvoiceTransaction_createExternalPaymentTransactionFromAmountAndRedirect' % outstanding_amount.absolute_url()
}
outstanding_amount_list = entity.Entity_getOutstandingDepositAmountList(
resource_uid=currency_uid,
ledger_uid=ledger_uid
)
for outstanding_amount in outstanding_amount_list:
if 0 < outstanding_amount.total_price:
if not is_payment_configured:
return '<p>Please contact us to handle your payment</p>'
html_content += """ html_content += """
<p><a href="%(payment_url)s">%(total_price)s %(currency)s</a></p> <p><a href="%(payment_url)s">%(total_price)s %(currency)s</a></p>
""" % { """ % {
'total_price': deposit_price, 'total_price': outstanding_amount.total_price,
'currency': currency_value.getReference(), 'currency': currency_value.getReference(),
'payment_url': '%s/Entity_createExternalPaymentTransactionFromDepositAndRedirect?currency_reference=%s' % (entity.absolute_url(), currency_value.getReference()) 'payment_url': '%s/Entity_createExternalPaymentTransactionFromDepositAndRedirect?currency_reference=%s' % (entity.absolute_url(), currency_value.getReference())
} }
......
...@@ -10,10 +10,20 @@ if currency_reference: ...@@ -10,10 +10,20 @@ if currency_reference:
if currency_value is None: if currency_value is None:
raise ValueError("Unknown Currency: %s" % currency_reference) raise ValueError("Unknown Currency: %s" % currency_reference)
ledger_uid = portal.portal_categories.ledger.automated.getUid()
currency_uid = currency_value.getUid()
payment_mode = context.Base_getPaymentModeForCurrency(currency_value.getUid()) payment_mode = context.Base_getPaymentModeForCurrency(currency_value.getUid())
assert payment_mode is not None assert payment_mode is not None
deposit_price = context.Entity_getOutstandingDepositAmount(currency_value.getUid()) outstanding_amount_list = context.Entity_getOutstandingDepositAmountList(
resource_uid=currency_uid, ledger_uid=ledger_uid)
if len(outstanding_amount_list) != 1:
raise ValueError("It was expected exactly one amount to pay for %s currency (%s found)" % (
currency_uid, outstanding_amount_list))
deposit_price = outstanding_amount_list[0].total_price
if 0 >= deposit_price: if 0 >= deposit_price:
raise ValueError("Nothing to pay") raise ValueError("Nothing to pay")
......
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