Commit 6dcc6eb8 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_panel: Handle deposit outstanding amount as a list

   Since it should handle multiple *_section.
parent 179a897e
......@@ -16,33 +16,45 @@ entity = portal.portal_membership.getAuthenticatedMember().getUserValue()
if entity is None:
return '<p>Nothing to pay with your account</p>'
is_payment_configured = 1
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.getUid()
if secure_service_relative_url is not None:
# Existing invoices
outstanding_amount_list = entity.Entity_getOutstandingAmountList(
ledger_uid=ledger_uid,
resource_uid=currency_uid
)
for outstanding_amount in outstanding_amount_list:
html_content += """
<p><a href="%(payment_url)s">%(total_price)s %(currency)s</a></p>
""" % {
'total_price': outstanding_amount.total_price,
'currency': outstanding_amount.getPriceCurrencyReference(),
'payment_url': '%s/SaleInvoiceTransaction_createExternalPaymentTransactionFromAmountAndRedirect' % outstanding_amount.absolute_url()
}
deposit_price = entity.Entity_getOutstandingDepositAmount(currency_uid)
if 0 < deposit_price:
if secure_service_relative_url is None:
is_payment_configured = 0
outstanding_amount_list = entity.Entity_getOutstandingAmountList(
ledger_uid=ledger_uid,
resource_uid=currency_uid
)
for outstanding_amount in outstanding_amount_list:
if not is_payment_configured:
return '<p>Please contact us to handle your payment</p>'
html_content += """
<p><a href="%(payment_url)s">%(total_price)s %(currency)s</a></p>
""" % {
'total_price': outstanding_amount.total_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 += """
<p><a href="%(payment_url)s">%(total_price)s %(currency)s</a></p>
""" % {
'total_price': deposit_price,
'currency': currency_value.getReference(),
'total_price': outstanding_amount.total_price,
'currency': currency_value.getReference(),
'payment_url': '%s/Entity_createExternalPaymentTransactionFromDepositAndRedirect?currency_reference=%s' % (entity.absolute_url(), currency_value.getReference())
}
......
......@@ -10,10 +10,20 @@ if currency_reference:
if currency_value is None:
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())
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:
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