Commit ac978a55 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_payzen&wechat: Update script to create reversal Sale Invoice Transaction

parent f090874c
...@@ -13,14 +13,9 @@ assert context.getTotalPrice() != 0 ...@@ -13,14 +13,9 @@ assert context.getTotalPrice() != 0
assert context.getSpecialise() in ("sale_trade_condition_module/slapos_aggregated_trade_condition", assert context.getSpecialise() in ("sale_trade_condition_module/slapos_aggregated_trade_condition",
"sale_trade_condition_module/slapos_aggregated_subscription_trade_condition") "sale_trade_condition_module/slapos_aggregated_subscription_trade_condition")
paid = True
for line in context.getMovementList(portal.getPortalAccountingMovementTypeList()): # Dont create if the invoice is already paied
node_value = line.getSourceValue(portal_type='Account') assert not context.SaleInvoiceTransaction_isLettered()
if node_value.getAccountType() == 'asset/receivable':
if not line.hasGroupingReference():
paid = False
break
assert not paid
payment = portal.portal_catalog.getResultValue( payment = portal.portal_catalog.getResultValue(
portal_type="Payment Transaction", portal_type="Payment Transaction",
...@@ -28,17 +23,13 @@ payment = portal.portal_catalog.getResultValue( ...@@ -28,17 +23,13 @@ payment = portal.portal_catalog.getResultValue(
default_causality_uid=context.getUid(), default_causality_uid=context.getUid(),
default_payment_mode_uid=portal.portal_categories.payment_mode.payzen.getUid(), default_payment_mode_uid=portal.portal_categories.payment_mode.payzen.getUid(),
) )
assert payment is not None if payment is not None and payment.PaymentTransaction_getPayzenId()[1] is None:
assert payment.getSimulationState() == 'started' # The payment transaction will be cancelled by a proper alarm.
assert payment.getPaymentMode() == 'payzen' raise ValueError("Payment Transaction is waiting for External Payzen confirmation!")
assert payment.PaymentTransaction_getPayzenId()[1] is None
# Should be safe now to fix everything # Should be safe now to fix everything
context.SaleInvoiceTransaction_resetPaymentMode() context.SaleInvoiceTransaction_resetPaymentMode()
payment.edit(payment_mode=None)
reversal_transaction = context.Base_createCloneDocument(batch_mode=1) reversal_transaction = context.Base_createCloneDocument(batch_mode=1)
payment.cancel(
comment="Reversal sale invoice transaction created %s" % reversal_transaction.getRelativeUrl())
reversal_transaction.edit( reversal_transaction.edit(
title="Reversal Transaction for %s" % context.getTitle(), title="Reversal Transaction for %s" % context.getTitle(),
......
...@@ -10,16 +10,12 @@ assert context.getPortalType() == 'Sale Invoice Transaction' ...@@ -10,16 +10,12 @@ assert context.getPortalType() == 'Sale Invoice Transaction'
assert context.getPaymentMode() == 'wechat' assert context.getPaymentMode() == 'wechat'
assert context.getSimulationState() == 'stopped' assert context.getSimulationState() == 'stopped'
assert context.getTotalPrice() != 0 assert context.getTotalPrice() != 0
assert context.getSpecialise() == "sale_trade_condition_module/slapos_aggregated_trade_condition" assert context.getSpecialise() in ("sale_trade_condition_module/slapos_aggregated_trade_condition",
"sale_trade_condition_module/slapos_aggregated_subscription_trade_condition")
paid = True
for line in context.getMovementList(portal.getPortalAccountingMovementTypeList()): # Dont create if the invoice is already paied
node_value = line.getSourceValue(portal_type='Account') assert not context.SaleInvoiceTransaction_isLettered()
if node_value.getAccountType() == 'asset/receivable':
if not line.hasGroupingReference():
paid = False
break
assert not paid
payment = portal.portal_catalog.getResultValue( payment = portal.portal_catalog.getResultValue(
portal_type="Payment Transaction", portal_type="Payment Transaction",
...@@ -27,17 +23,13 @@ payment = portal.portal_catalog.getResultValue( ...@@ -27,17 +23,13 @@ payment = portal.portal_catalog.getResultValue(
default_causality_uid=context.getUid(), default_causality_uid=context.getUid(),
default_payment_mode_uid=portal.portal_categories.payment_mode.wechat.getUid(), default_payment_mode_uid=portal.portal_categories.payment_mode.wechat.getUid(),
) )
assert payment is not None if payment is not None and payment.PaymentTransaction_getWechatId()[1] is None:
assert payment.getSimulationState() == 'started' # The payment transaction will be cancelled by a proper alarm.
assert payment.getPaymentMode() == 'wechat' raise ValueError("Payment Transaction is waiting for External Wechat confirmation!")
assert payment.PaymentTransaction_getWechatId()[1] is None
# Should be safe now to fix everything # Should be safe now to fix everything
context.SaleInvoiceTransaction_resetPaymentMode() context.SaleInvoiceTransaction_resetPaymentMode()
payment.edit(payment_mode=None)
reversal_transaction = context.Base_createCloneDocument(batch_mode=1) reversal_transaction = context.Base_createCloneDocument(batch_mode=1)
payment.cancel(
comment="Reversal sale invoice transaction created %s" % reversal_transaction.getRelativeUrl())
reversal_transaction.edit( reversal_transaction.edit(
title="Reversal Transaction for %s" % context.getTitle(), title="Reversal Transaction for %s" % context.getTitle(),
......
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