Commit c0e8548a authored by Romain Courteaud's avatar Romain Courteaud

slapos_subscription_request: drop unused SubscriptionRequest_verifyReservationPaymentTransaction

parent 2c3a9767
from DateTime import DateTime
if context.getSimulationState() != "draft":
return
sale_invoice_transaction = context.getCausalityValue(
portal_type="Sale Invoice Transaction")
if sale_invoice_transaction is None:
if context.getCreationDate() < DateTime() - 1:
context.cancel(comment="No sale invoice transaction attached, so subscription is cancelled")
return
if sale_invoice_transaction.getSimulationState() in ["draft", "cancelled", "deleted"]:
context.cancel(comment="Invoice is cancelled, so subscription is cancelled")
return
payment_transaction_list = sale_invoice_transaction.getCausalityRelatedValueList(
portal_type="Payment Transaction")
cancel_subscription_request = None
is_paid = False
for payment_transaction in payment_transaction_list:
if cancel_subscription_request != False and payment_transaction.getSimulationState() in ["draft", "cancelled", "deleted"]:
cancel_subscription_request = True
if payment_transaction.getSimulationState() == "stopped":
cancel_subscription_request = False
is_paid = True
if cancel_subscription_request:
context.cancel(comment="Payment is cancelled, so subscription is cancelled")
sale_invoice_transaction.cancel(comment="Payment is cancelled, so invoice is cancelled")
for payment_transaction in payment_transaction_list:
if payment_transaction.getSimulationState() == "started":
payment_transaction.cancel("Subscription is been cancelled")
# Check if payment_transaction is payed.
if not is_paid:
# Nothing to do bug wait the payment
return
if context.getSpecialise(portal_type="Subscription Condition") is not None:
# Ensure Subscription is updated
context.SubscriptionRequest_applyCondition()
context.plan(comment="Payment is consider valid.")
<?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></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SubscriptionRequest_verifyReservationPaymentTransaction</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -710,168 +710,6 @@ class TestSubscriptionRequest_notifyInstanceIsReady(TestSubscriptionSkinsMixin):
event.getTextContent(),'%s %s %s' % (person.getTitle(), subscription_request.getTitle(),
self.instance_tree.getRelativeUrl()))
class TestSubscriptionRequest_verifyReservationPaymentTransaction(TestSubscriptionSkinsMixin):
def test_no_sale_invoice(self):
person = self.makePerson()
subscription_request = self.newSubscriptionRequest(
quantity=1, destination_section_value=person)
# Too early to cancel
self.assertEqual(subscription_request.SubscriptionRequest_verifyReservationPaymentTransaction(),
None)
self.assertEqual(subscription_request.getSimulationState(),
"draft")
def getCreationDate(self):
return DateTime() - 1.1
from Products.ERP5Type.Base import Base
original_get_creation = Base.getCreationDate
Base.getCreationDate = getCreationDate
try:
self.assertEqual(subscription_request.SubscriptionRequest_verifyReservationPaymentTransaction(),
None)
finally:
Base.getCreationDate = original_get_creation
self.assertEqual(subscription_request.getSimulationState(),
"cancelled")
def _test_cancel_due_payment_state(self, state="draft"):
email = "abc%s@nexedi.com" % self.new_id
name = "Cous Cous %s" % self.new_id
person, _ = self.portal.SubscriptionRequest_createUser(name=name, email=email)
self.tic()
subscription_request = self.newSubscriptionRequest(
quantity=1, destination_section_value=person,
default_email_text="abc%s@nexedi.com" % self.new_id)
invoice_template_path = "accounting_module/template_pre_payment_subscription_sale_invoice_transaction"
invoice_template = self.portal.restrictedTraverse(invoice_template_path)
payment_template = self.portal.restrictedTraverse("accounting_module/slapos_pre_payment_template")
# Too early to cancel
self.assertEqual(subscription_request.SubscriptionRequest_verifyReservationPaymentTransaction(), None)
self.assertEqual(subscription_request.getSimulationState(), "draft")
current_invoice = invoice_template.Base_createCloneDocument(batch_mode=1)
current_payment = payment_template.Base_createCloneDocument(batch_mode=1)
current_invoice.start()
subscription_request.edit(causality_value=current_invoice)
current_payment.setCausalityValue(current_invoice)
if state == "cancelled":
current_payment.cancel()
elif state == "deleted":
current_payment.delete()
self.tic()
self.assertEqual(subscription_request.SubscriptionRequest_verifyReservationPaymentTransaction(),
None)
self.assertEqual(current_invoice.getSimulationState(), "cancelled")
self.assertEqual(subscription_request.getSimulationState(),
"cancelled")
def test_draft_payment_state(self):
self._test_cancel_due_payment_state()
def test_cancelled_payment_state(self):
self._test_cancel_due_payment_state(state="cancelled")
def test_deleted_payment_state(self):
self._test_cancel_due_payment_state(state="deleted")
def test_stopped_payment_state(self, state="draft"):
email = "abc%s@nexedi.com" % self.new_id
name = "Cous Cous %s" % self.new_id
person, _ = self.portal.SubscriptionRequest_createUser(name=name, email=email)
self.tic()
subscription_request = self.newSubscriptionRequest(
quantity=1, destination_section_value=person,
default_email_text="abc%s@nexedi.com" % self.new_id)
invoice_template_path = "accounting_module/template_pre_payment_subscription_sale_invoice_transaction"
invoice_template = self.portal.restrictedTraverse(invoice_template_path)
payment_template = self.portal.restrictedTraverse("accounting_module/slapos_pre_payment_template")
# Too early to cancel
self.assertEqual(subscription_request.SubscriptionRequest_verifyReservationPaymentTransaction(), None)
self.assertEqual(subscription_request.getSimulationState(), "draft")
current_invoice = invoice_template.Base_createCloneDocument(batch_mode=1)
current_payment = payment_template.Base_createCloneDocument(batch_mode=1)
current_invoice.confirm()
current_invoice.start()
current_invoice.stop()
subscription_request.edit(causality_value=current_invoice)
current_payment.setCausalityValue(current_invoice)
current_payment.confirm()
current_payment.start()
self.tic()
self.assertEqual(subscription_request.SubscriptionRequest_verifyReservationPaymentTransaction(),
None)
self.assertEqual(subscription_request.getSimulationState(),
"draft")
current_payment.stop()
self.assertEqual(subscription_request.SubscriptionRequest_verifyReservationPaymentTransaction(),
None)
self.assertEqual(subscription_request.getSimulationState(),
"planned")
def _test_cancel_due_sale_invoice_state(self, state="draft"):
email = "abc%s@nexedi.com" % self.new_id
name = "Cous Cous %s" % self.new_id
person, _ = self.portal.SubscriptionRequest_createUser(name=name, email=email)
self.tic()
subscription_request = self.newSubscriptionRequest(
quantity=1, destination_section_value=person,
default_email_text="abc%s@nexedi.com" % self.new_id)
invoice_template_path = "accounting_module/template_pre_payment_subscription_sale_invoice_transaction"
invoice_template = self.portal.restrictedTraverse(invoice_template_path)
# Too early to cancel
self.assertEqual(subscription_request.SubscriptionRequest_verifyReservationPaymentTransaction(),
None)
self.assertEqual(subscription_request.getSimulationState(),
"draft")
current_invoice = invoice_template.Base_createCloneDocument(batch_mode=1)
subscription_request.edit(causality_value=current_invoice)
if state == "cancelled":
current_invoice.cancel()
elif state == "deleted":
current_invoice.delete()
self.assertEqual(subscription_request.SubscriptionRequest_verifyReservationPaymentTransaction(),
None)
self.assertEqual(subscription_request.getSimulationState(),
"cancelled")
def test_draft_sale_invoice_state(self):
self._test_cancel_due_sale_invoice_state()
def test_cancelled_sale_invoice_state(self):
self._test_cancel_due_sale_invoice_state(state="cancelled")
def test_deleted_sale_invoice_state(self):
self._test_cancel_due_sale_invoice_state(state="deleted")
class TestSubscriptionRequest_verifyInstanceIsAllocated(TestSubscriptionSkinsMixin):
......
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