Commit 25fd8d3a authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_accounting: Create Payment Transaction before redirect to handle...

slapos_accounting: Create Payment Transaction before redirect to handle external payment redirection
parent ac978a55
......@@ -52,6 +52,14 @@
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
<value>
<tuple>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getReceivableAccountList</string> </value>
......
......@@ -10,7 +10,7 @@ if not invoice_list:
# For now consider a single value is passed, in future we intend to create
# a single payment per invoice.
current_invoice = invoice_list[0]
payment_tag ="sale_invoice_transaction_create_payment_%s" % current_invoice.getUid()
payment_tag = "sale_invoice_transaction_create_payment_%s" % current_invoice.getUid()
if context.REQUEST.get(payment_tag, None) is not None:
raise ValueError('This script was already called twice on the same transaction ')
......@@ -21,9 +21,12 @@ context.serialize()
quantity = 0
for movement in current_invoice.searchFolder(
portal_type='Sale Invoice Transaction Line',
default_source_uid=[i.uid for i in context.Base_getReceivableAccountList()]):
default_source_uid=[i.uid for i in context.Base_getReceivableAccountList()]):
quantity += movement.getQuantity()
if quantity >= 0:
raise ValueError('You cannot generate Payment Transaction for zero or negative amounts.')
current_payment = portal.accounting_module.newContent(
portal_type="Payment Transaction",
causality=current_invoice.getRelativeUrl(),
......@@ -57,13 +60,19 @@ current_payment.newContent(
stop_date=current_invoice.getStopDate())
comment = translateString("Initialised by Entity_createPaymentTransaction.")
current_payment.confirm(comment=comment)
# Reindex with a tag to ensure that there will be no generation while the object isn't
# reindexed.
payment_tag ="sale_invoice_transaction_create_payment_%s" % current_invoice.getUid()
current_payment.activate(tag=payment_tag).immediateReindexObject()
# Call script rather them call confirm(), since it would set security and fail whenever
# start is called.
current_payment.AccountingTransaction_setReference()
comment = translateString("Initialised by Entity_createPaymentTransaction.")
current_payment.start(comment=comment)
# Set a flag on the request for prevent 2 calls on the same transaction
context.REQUEST.set(payment_tag, 1)
......
payment_mode = context.getPaymentMode()
entity = context.getDestinationSectionValue()
def wrapWithShadow(entity, invoice):
return entity.Entity_createPaymentTransaction([invoice])
payment = entity.Person_restrictMethodAsShadowUser(
shadow_document=entity,
callable_object=wrapWithShadow,
argument_list=[entity, context])
if web_site is None:
web_site = context.getWebSiteValue()
if payment_mode == "wechat":
return context.PaymentTransaction_redirectToManualWechatPayment(web_site=web_site)
return payment.PaymentTransaction_redirectToManualWechatPayment(web_site=web_site)
elif payment_mode == "payzen":
return context.PaymentTransaction_redirectToManualPayzenPayment(web_site=web_site)
return payment.PaymentTransaction_redirectToManualPayzenPayment(web_site=web_site)
raise ValueError("%s isn't an acceptable payment mode" % payment_mode)
......@@ -54,7 +54,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>PaymentTransaction_redirectToManualSlapOSPayment</string> </value>
<value> <string>SaleInvoiceTransaction_redirectToManualSlapOSPayment</string> </value>
</item>
</dictionary>
</pickle>
......
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