Commit f83baeac authored by Romain Courteaud's avatar Romain Courteaud

slapos_crm: use Entity_hasOutstandingAmount

Entity_getOutstandingAmount is meaningless in case of multiple source_section and multiple currencies.
Entity_hasOutstandingAmount will only report True or False.
parent 79b1be21
......@@ -24,13 +24,7 @@ if ticket is not None:
return ticket, None
mail_message = None
outstanding_amount = person.Entity_statSlapOSOutstandingAmount()
# It can't be smaller, we are considernig all open invoices are from unpaid_payment_amount
if round(float(outstanding_amount), 2) == round(float(0), 2):
return ticket, None
if int(outstanding_amount) > 0:
if person.Entity_hasOutstandingAmount():
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
......
......@@ -26,196 +26,6 @@ from erp5.component.test.SlapOSTestCaseMixin import \
SlapOSTestCaseMixin,SlapOSTestCaseMixinWithAbort, simulate
from zExceptions import Unauthorized
from DateTime import DateTime
import difflib
class TestSlapOSPerson_checkToCreateRegularisationRequest(SlapOSTestCaseMixinWithAbort):
@simulate('NotificationTool_getDocumentValue',
'reference=None, language="en"',
'assert reference == "slapos-crm.create.regularisation.request"\n' \
'return')
@simulate('Entity_statOutstandingAmount', '*args, **kwargs', 'return "1"')
def test_addRegularisationRequest_payment_requested(self):
for preference in \
self.portal.portal_catalog(portal_type="System Preference"):
preference = preference.getObject()
if preference.getPreferenceState() == 'global':
preference.setPreferredSlaposWebSiteUrl('http://foobar.org/')
project = self.addProject()
person = self.makePerson(project, index=0, user=0)
before_date = DateTime()
ticket, event = person.Person_checkToCreateRegularisationRequest()
after_date = DateTime()
self.assertEqual(ticket.getPortalType(), 'Regularisation Request')
self.assertEqual(ticket.getSimulationState(), 'suspended')
self.assertEqual(ticket.getSourceProject(), person.getRelativeUrl())
self.assertEqual(ticket.getResource(),
'service_module/slapos_crm_acknowledgement')
self.assertEqual(ticket.getTitle(),
'Account regularisation expected for "%s"' % person.getTitle())
self.assertEqual(ticket.getDestination(),
person.getRelativeUrl())
self.assertEqual(ticket.getDestinationDecision(),
person.getRelativeUrl())
self.assertEqual(event.getPortalType(), 'Mail Message')
self.assertEqual(event.getResource(),
'service_module/slapos_crm_acknowledgement')
self.assertTrue(event.getStartDate() >= before_date)
self.assertTrue(event.getStopDate() <= after_date)
self.assertEqual(event.getTitle(), "Invoice payment requested")
self.assertEqual(event.getDestination(),
person.getRelativeUrl())
self.assertEqual(event.getSource(),
ticket.getSource())
expected_text_content = """Dear Member Template,
A new invoice has been generated.
You can access it in your invoice section at http://foobar.org/.
Regards,
The slapos team
"""
self.assertEqual(event.getTextContent(), expected_text_content,
'\n'.join([x for x in difflib.unified_diff(
event.getTextContent().splitlines(),
expected_text_content.splitlines())]))
self.assertEqual(event.getSimulationState(), 'delivered')
@simulate('NotificationTool_getDocumentValue',
'reference=None, language="en"',
'assert reference == "slapos-crm.create.regularisation.request"\n' \
'return context.restrictedTraverse(' \
'context.REQUEST["test_addRegularisationRequest_notification_message"])')
@simulate('Entity_statOutstandingAmount', '*args, **kwargs', 'return "1"')
def test_addRegularisationRequest_notification_message(self):
for preference in \
self.portal.portal_catalog(portal_type="System Preference"):
preference = preference.getObject()
if preference.getPreferenceState() == 'global':
preference.setPreferredSlaposWebSiteUrl('http://foobar.org/')
project = self.addProject()
person = self.makePerson(project, index=0, user=0)
new_id = self.generateNewId()
notification_message = self.portal.notification_message_module.newContent(
portal_type="Notification Message",
title='Test NM title %s' % new_id,
text_content='Test NM content\n%s\n' % new_id,
content_type='text/plain',
)
self.portal.REQUEST\
['test_addRegularisationRequest_notification_message'] = \
notification_message.getRelativeUrl()
before_date = DateTime()
ticket, event = person.Person_checkToCreateRegularisationRequest()
after_date = DateTime()
self.assertEqual(ticket.getPortalType(), 'Regularisation Request')
self.assertEqual(ticket.getSimulationState(), 'suspended')
self.assertEqual(ticket.getSourceProject(), person.getRelativeUrl())
self.assertEqual(ticket.getResource(),
'service_module/slapos_crm_acknowledgement')
self.assertEqual(ticket.getTitle(),
'Account regularisation expected for "%s"' % person.getTitle())
self.assertEqual(ticket.getDestination(),
person.getRelativeUrl())
self.assertEqual(ticket.getDestinationDecision(),
person.getRelativeUrl())
self.assertEqual(event.getPortalType(), 'Mail Message')
self.assertEqual(event.getResource(),
'service_module/slapos_crm_acknowledgement')
self.assertTrue(event.getStartDate() >= before_date)
self.assertTrue(event.getStopDate() <= after_date)
self.assertEqual(event.getTitle(),
'Test NM title %s' % new_id)
self.assertEqual(event.getDestination(),
person.getRelativeUrl())
self.assertEqual(event.getSource(),
ticket.getSource())
expected_text_content = 'Test NM content\n%s\n' % new_id
self.assertEqual(event.getTextContent(), expected_text_content,
'\n'.join([x for x in difflib.unified_diff(
event.getTextContent().splitlines(),
expected_text_content.splitlines())]))
self.assertEqual(event.getSimulationState(), 'delivered')
# def test_addRegularisationRequest_do_not_duplicate_ticket(self):
# person = self.createPerson()
# ticket = person.Person_checkToCreateRegularisationRequest()
# ticket2 = person.Person_checkToCreateRegularisationRequest()
# self.assertEqual(ticket.getRelativeUrl(), ticket2.getRelativeUrl())
@simulate('Entity_statOutstandingAmount', '*args, **kwargs', 'return "1"')
def test_addRegularisationRequest_do_not_duplicate_ticket_if_not_reindexed(self):
project = self.addProject()
person = self.makePerson(project, index=0, user=0)
ticket, event = person.Person_checkToCreateRegularisationRequest()
transaction.commit()
ticket2, event2 = person.Person_checkToCreateRegularisationRequest()
self.assertNotEqual(ticket, None)
self.assertNotEqual(event, None)
self.assertEqual(ticket2, None)
self.assertEqual(event2, None)
@simulate('Entity_statOutstandingAmount', '*args, **kwargs', 'return "0"')
@simulate('RegularisationRequest_checkToSendUniqEvent',
'*args, **kwargs',
'raise NotImplementedError, "Should not have been called"')
def test_addRegularisationRequest_balance_ok(self):
project = self.addProject()
person = self.makePerson(project, index=0, user=0)
ticket, event = person.Person_checkToCreateRegularisationRequest()
self.assertEqual(ticket, None)
self.assertEqual(event, None)
@simulate('Entity_statOutstandingAmount', '*args, **kwargs', 'return "1"')
def test_addRegularisationRequest_existing_suspended_ticket(self):
project = self.addProject()
person = self.makePerson(project, index=0, user=0)
ticket, event = person.Person_checkToCreateRegularisationRequest()
transaction.commit()
self.tic()
ticket2, event2 = person.Person_checkToCreateRegularisationRequest()
self.assertNotEqual(ticket, None)
self.assertNotEqual(event, None)
self.assertEqual(ticket2.getRelativeUrl(), ticket.getRelativeUrl())
self.assertEqual(event2, None)
@simulate('Entity_statOutstandingAmount', '*args, **kwargs', 'return "1"')
def test_addRegularisationRequest_existing_validated_ticket(self):
project = self.addProject()
person = self.makePerson(project, index=0, user=0)
ticket, event = person.Person_checkToCreateRegularisationRequest()
ticket.validate()
transaction.commit()
self.tic()
ticket2, event2 = person.Person_checkToCreateRegularisationRequest()
self.assertNotEqual(ticket, None)
self.assertNotEqual(event, None)
self.assertEqual(ticket2.getRelativeUrl(), ticket.getRelativeUrl())
self.assertEqual(event2, None)
@simulate('Entity_statOutstandingAmount', '*args, **kwargs', 'return "1"')
def test_addRegularisationRequest_existing_invalidated_ticket(self):
project = self.addProject()
person = self.makePerson(project, index=0, user=0)
ticket = person.Person_checkToCreateRegularisationRequest()[0]
ticket.invalidate()
transaction.commit()
self.tic()
ticket2, event2 = person.Person_checkToCreateRegularisationRequest()
self.assertNotEqual(ticket2.getRelativeUrl(), ticket.getRelativeUrl())
self.assertNotEqual(event2, None)
def test_addRegularisationRequest_REQUEST_disallowed(self):
project = self.addProject()
person = self.makePerson(project, index=0, user=0)
self.assertRaises(
Unauthorized,
person.Person_checkToCreateRegularisationRequest,
REQUEST={})
class TestSlapOSRegularisationRequest_invalidateIfPersonBalanceIsOk(
......
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