Commit 6855ce26 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_crm: Do not send emails for the first payment request for subscription

    This email is already part of Subscription System. Regularisation Request is only for later payments.
parent 8eb15b5b
......@@ -653,7 +653,7 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
self.assertEqual(len(line_list), 0)
@changeSkin('RJS')
def useWechatManually(self, web_site, user_id):
def useWechatManually(self, web_site, user_id, is_email_expected=True):
person = self.portal.portal_catalog.getResultValue(
portal_type="Person",
......@@ -669,7 +669,11 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
if [q for q in candidate[1] if email in q] and body in candidate[2]:
return candidate[2]
to_click_message = findMessage(email, 'A new invoice has been generated.')
self.assertNotEqual(None, to_click_message)
if is_email_expected:
self.assertNotEqual(None, to_click_message)
else:
self.assertEqual(None, to_click_message)
# If you are using live test, be aware that the call of the alarm can be
# not enough for the number of objects on the site.
......@@ -682,7 +686,7 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
PaymentTransaction_redirectToManualWechatPayment()
@changeSkin('RJS')
def usePayzenManually(self, web_site, user_id):
def usePayzenManually(self, web_site, user_id, is_email_expected=True):
person = self.portal.portal_catalog.getResultValue(
portal_type="Person",
......@@ -698,7 +702,11 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
if [q for q in candidate[1] if email in q] and body in candidate[2]:
return candidate[2]
to_click_message = findMessage(email, 'A new invoice has been generated.')
self.assertNotEqual(None, to_click_message)
if is_email_expected:
self.assertNotEqual(None, to_click_message)
else:
self.assertEqual(None, to_click_message)
# Pay to payzen...
# If you are using live test, be aware that the call of the alarm can be
......
......@@ -19,8 +19,24 @@ ticket = portal.portal_catalog.getResultValue(
default_source_project_uid=person.getUid(),
simulation_state=['suspended', 'validated'],
)
if (ticket is None) and int(person.Entity_statOutstandingAmount()) > 0:
if ticket is not None:
return ticket, None
outstanding_amount = person.Entity_statSlapOSOutstandingAmount()
# Amount to be ignored, as it comes from the first invoice generated
# after the subscription. We do not take it into account as no service
# was provided yet.
unpaid_payment_amount = 0
for payment in person.Person_getSubscriptionRequestFirstUnpaidPaymentList():
unpaid_payment_amount += payment.PaymentTransaction_getTotalPayablePrice()
# It can't be smaller, we are considernig all open invoices are from unpaid_payment_amount
if round(float(outstanding_amount), 2) == round(-float(unpaid_payment_amount), 2):
return ticket, None
if int(outstanding_amount) > 0:
tag = "%s_addRegularisationRequest_inProgress" % person.getUid()
if (portal.portal_activities.countMessageWithTag(tag) > 0):
# The regularisation request is already under creation but can not be fetched from catalog
......@@ -56,7 +72,7 @@ if (ticket is None) and int(person.Entity_statOutstandingAmount()) > 0:
A new invoice has been generated.
You can access it in your invoice section at %s.
Do not hesitate to visit the web forum (http://community.slapos.org/forum) in case of question.
Do not hesitate to visit our website (http://slapos.vifib.com/) in case of question.
Regards,
The slapos team
......
portal = context.getPortalObject()
from erp5.component.module.DateUtils import addToDate
from Products.ZSQLCatalog.SQLCatalog import Query
from DateTime import DateTime
unpaid_list = []
subscription_request_list = portal.portal_catalog(
portal_type="Subscription Request",
simulation_state=["ordered", "confirmed"],
default_destination_section_uid=context.getUid(),
# Select "Subscription Request" with most likely unpaid invoices, recently generated.
creation_date=Query(creation_date=addToDate(DateTime(), to_add={'day': -20}), range="min"))
for subscription_request in subscription_request_list:
first_period_payment = subscription_request.SubscriptionRequest_verifyPaymentBalanceIsReady()
if first_period_payment is not None and first_period_payment.getSimulationState() == "started":
unpaid_list.append(first_period_payment)
return unpaid_list
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<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>Person_getSubscriptionRequestFirstUnpaidPaymentList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -146,7 +146,7 @@ return dict(vads_url_already_registered="%s/already_registered" % (payment_trans
self.portal.portal_secure_payments.slapos_wechat_test.setWechatMode("UNITTEST")
self.login(person.getUserId())
self.useWechatManually(self.web_site, person.getUserId())
self.useWechatManually(self.web_site, person.getUserId(), is_email_expected=False)
payment = self.portal.portal_catalog.getResultValue(
portal_type="Payment Transaction",
......
......@@ -309,7 +309,7 @@ class TestSlapOSSubscriptionScenarioMixin(DefaultScenarioMixin):
quantity = subscription_request.getQuantity()
self.login(person.getUserId())
self.usePayzenManually(self.web_site, person.getUserId())
self.usePayzenManually(self.web_site, person.getUserId(), is_email_expected=False)
payment = self.portal.portal_catalog.getResultValue(
portal_type="Payment Transaction",
......
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