Commit 17686abf authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_crm: Use new API to check if the user has something to Pay

parent f55ffdc7
...@@ -19,7 +19,7 @@ ticket = portal.portal_catalog.getResultValue( ...@@ -19,7 +19,7 @@ ticket = portal.portal_catalog.getResultValue(
default_source_project_uid=person.getUid(), default_source_project_uid=person.getUid(),
simulation_state=['suspended', 'validated'], simulation_state=['suspended', 'validated'],
) )
if (ticket is None) and int(person.Entity_statBalance()) > 0: if (ticket is None) and int(person.Entity_statOutstandingAmount()) > 0:
tag = "%s_addRegularisationRequest_inProgress" % person.getUid() tag = "%s_addRegularisationRequest_inProgress" % person.getUid()
if (portal.portal_activities.countMessageWithTag(tag) > 0): if (portal.portal_activities.countMessageWithTag(tag) > 0):
......
...@@ -6,7 +6,7 @@ state = context.getSimulationState() ...@@ -6,7 +6,7 @@ state = context.getSimulationState()
person = context.getSourceProjectValue(portal_type="Person") person = context.getSourceProjectValue(portal_type="Person")
if (state != 'suspended') or \ if (state != 'suspended') or \
(person is None) or \ (person is None) or \
(int(person.Entity_statBalance()) > 0): (int(person.Entity_statOutstandingAmount()) > 0):
return return
else: else:
context.invalidate(comment="Automatically disabled as balance is %s" % person.Entity_statBalance()) context.invalidate(comment="Automatically disabled as balance is %s" % person.Entity_statOutstandingAmount())
...@@ -30,7 +30,7 @@ import difflib ...@@ -30,7 +30,7 @@ import difflib
class TestSlapOSPerson_checkToCreateRegularisationRequest(SlapOSTestCaseMixinWithAbort): class TestSlapOSPerson_checkToCreateRegularisationRequest(SlapOSTestCaseMixinWithAbort):
@simulate('Entity_statBalance', '*args, **kwargs', 'return "1"') @simulate('Entity_statOutstandingAmount', '*args, **kwargs', 'return "1"')
def test_addRegularisationRequest_payment_requested(self): def test_addRegularisationRequest_payment_requested(self):
for preference in \ for preference in \
self.portal.portal_catalog(portal_type="System Preference"): self.portal.portal_catalog(portal_type="System Preference"):
...@@ -84,7 +84,7 @@ The slapos team ...@@ -84,7 +84,7 @@ The slapos team
'assert reference == "slapos-crm.create.regularisation.request"\n' \ 'assert reference == "slapos-crm.create.regularisation.request"\n' \
'return context.restrictedTraverse(' \ 'return context.restrictedTraverse(' \
'context.REQUEST["test_addRegularisationRequest_notification_message"])') 'context.REQUEST["test_addRegularisationRequest_notification_message"])')
@simulate('Entity_statBalance', '*args, **kwargs', 'return "1"') @simulate('Entity_statOutstandingAmount', '*args, **kwargs', 'return "1"')
def test_addRegularisationRequest_notification_message(self): def test_addRegularisationRequest_notification_message(self):
for preference in \ for preference in \
self.portal.portal_catalog(portal_type="System Preference"): self.portal.portal_catalog(portal_type="System Preference"):
...@@ -143,7 +143,7 @@ The slapos team ...@@ -143,7 +143,7 @@ The slapos team
# ticket2 = person.Person_checkToCreateRegularisationRequest() # ticket2 = person.Person_checkToCreateRegularisationRequest()
# self.assertEqual(ticket.getRelativeUrl(), ticket2.getRelativeUrl()) # self.assertEqual(ticket.getRelativeUrl(), ticket2.getRelativeUrl())
@simulate('Entity_statBalance', '*args, **kwargs', 'return "1"') @simulate('Entity_statOutstandingAmount', '*args, **kwargs', 'return "1"')
def test_addRegularisationRequest_do_not_duplicate_ticket_if_not_reindexed(self): def test_addRegularisationRequest_do_not_duplicate_ticket_if_not_reindexed(self):
person = self.makePerson(index=0, user=0) person = self.makePerson(index=0, user=0)
ticket, event = person.Person_checkToCreateRegularisationRequest() ticket, event = person.Person_checkToCreateRegularisationRequest()
...@@ -154,7 +154,7 @@ The slapos team ...@@ -154,7 +154,7 @@ The slapos team
self.assertEqual(ticket2, None) self.assertEqual(ticket2, None)
self.assertEqual(event2, None) self.assertEqual(event2, None)
@simulate('Entity_statBalance', '*args, **kwargs', 'return "0"') @simulate('Entity_statOutstandingAmount', '*args, **kwargs', 'return "0"')
@simulate('RegularisationRequest_checkToSendUniqEvent', @simulate('RegularisationRequest_checkToSendUniqEvent',
'*args, **kwargs', '*args, **kwargs',
'raise NotImplementedError, "Should not have been called"') 'raise NotImplementedError, "Should not have been called"')
...@@ -164,7 +164,7 @@ The slapos team ...@@ -164,7 +164,7 @@ The slapos team
self.assertEqual(ticket, None) self.assertEqual(ticket, None)
self.assertEqual(event, None) self.assertEqual(event, None)
@simulate('Entity_statBalance', '*args, **kwargs', 'return "1"') @simulate('Entity_statOutstandingAmount', '*args, **kwargs', 'return "1"')
def test_addRegularisationRequest_existing_suspended_ticket(self): def test_addRegularisationRequest_existing_suspended_ticket(self):
person = self.makePerson(index=0, user=0) person = self.makePerson(index=0, user=0)
ticket, event = person.Person_checkToCreateRegularisationRequest() ticket, event = person.Person_checkToCreateRegularisationRequest()
...@@ -176,7 +176,7 @@ The slapos team ...@@ -176,7 +176,7 @@ The slapos team
self.assertEqual(ticket2.getRelativeUrl(), ticket.getRelativeUrl()) self.assertEqual(ticket2.getRelativeUrl(), ticket.getRelativeUrl())
self.assertEqual(event2, None) self.assertEqual(event2, None)
@simulate('Entity_statBalance', '*args, **kwargs', 'return "1"') @simulate('Entity_statOutstandingAmount', '*args, **kwargs', 'return "1"')
def test_addRegularisationRequest_existing_validated_ticket(self): def test_addRegularisationRequest_existing_validated_ticket(self):
person = self.makePerson(index=0, user=0) person = self.makePerson(index=0, user=0)
ticket, event = person.Person_checkToCreateRegularisationRequest() ticket, event = person.Person_checkToCreateRegularisationRequest()
...@@ -189,7 +189,7 @@ The slapos team ...@@ -189,7 +189,7 @@ The slapos team
self.assertEqual(ticket2.getRelativeUrl(), ticket.getRelativeUrl()) self.assertEqual(ticket2.getRelativeUrl(), ticket.getRelativeUrl())
self.assertEqual(event2, None) self.assertEqual(event2, None)
@simulate('Entity_statBalance', '*args, **kwargs', 'return "1"') @simulate('Entity_statOutstandingAmount', '*args, **kwargs', 'return "1"')
def test_addRegularisationRequest_existing_invalidated_ticket(self): def test_addRegularisationRequest_existing_invalidated_ticket(self):
person = self.makePerson(index=0, user=0) person = self.makePerson(index=0, user=0)
ticket = person.Person_checkToCreateRegularisationRequest()[0] ticket = person.Person_checkToCreateRegularisationRequest()[0]
...@@ -226,7 +226,7 @@ class TestSlapOSRegularisationRequest_invalidateIfPersonBalanceIsOk( ...@@ -226,7 +226,7 @@ class TestSlapOSRegularisationRequest_invalidateIfPersonBalanceIsOk(
ticket.RegularisationRequest_invalidateIfPersonBalanceIsOk, ticket.RegularisationRequest_invalidateIfPersonBalanceIsOk,
REQUEST={}) REQUEST={})
@simulate('Entity_statBalance', '*args, **kwargs', 'return "0"') @simulate('Entity_statOutstandingAmount', '*args, **kwargs', 'return "0"')
def test_invalidateIfPersonBalanceIsOk_matching_case(self): def test_invalidateIfPersonBalanceIsOk_matching_case(self):
person = self.makePerson(index=0, user=0) person = self.makePerson(index=0, user=0)
ticket = self.createRegularisationRequest() ticket = self.createRegularisationRequest()
...@@ -236,7 +236,7 @@ class TestSlapOSRegularisationRequest_invalidateIfPersonBalanceIsOk( ...@@ -236,7 +236,7 @@ class TestSlapOSRegularisationRequest_invalidateIfPersonBalanceIsOk(
ticket.RegularisationRequest_invalidateIfPersonBalanceIsOk() ticket.RegularisationRequest_invalidateIfPersonBalanceIsOk()
self.assertEqual(ticket.getSimulationState(), 'invalidated') self.assertEqual(ticket.getSimulationState(), 'invalidated')
@simulate('Entity_statBalance', '*args, **kwargs', 'return "0"') @simulate('Entity_statOutstandingAmount', '*args, **kwargs', 'return "0"')
def test_invalidateIfPersonBalanceIsOk_not_suspended(self): def test_invalidateIfPersonBalanceIsOk_not_suspended(self):
person = self.makePerson(index=0, user=0) person = self.makePerson(index=0, user=0)
ticket = self.createRegularisationRequest() ticket = self.createRegularisationRequest()
...@@ -245,7 +245,7 @@ class TestSlapOSRegularisationRequest_invalidateIfPersonBalanceIsOk( ...@@ -245,7 +245,7 @@ class TestSlapOSRegularisationRequest_invalidateIfPersonBalanceIsOk(
ticket.RegularisationRequest_invalidateIfPersonBalanceIsOk() ticket.RegularisationRequest_invalidateIfPersonBalanceIsOk()
self.assertEqual(ticket.getSimulationState(), 'validated') self.assertEqual(ticket.getSimulationState(), 'validated')
@simulate('Entity_statBalance', '*args, **kwargs', 'return "0"') @simulate('Entity_statOutstandingAmount', '*args, **kwargs', 'return "0"')
def test_invalidateIfPersonBalanceIsOk_no_person(self): def test_invalidateIfPersonBalanceIsOk_no_person(self):
ticket = self.createRegularisationRequest() ticket = self.createRegularisationRequest()
ticket.validate() ticket.validate()
...@@ -253,7 +253,7 @@ class TestSlapOSRegularisationRequest_invalidateIfPersonBalanceIsOk( ...@@ -253,7 +253,7 @@ class TestSlapOSRegularisationRequest_invalidateIfPersonBalanceIsOk(
ticket.RegularisationRequest_invalidateIfPersonBalanceIsOk() ticket.RegularisationRequest_invalidateIfPersonBalanceIsOk()
self.assertEqual(ticket.getSimulationState(), 'suspended') self.assertEqual(ticket.getSimulationState(), 'suspended')
@simulate('Entity_statBalance', '*args, **kwargs', 'return "1"') @simulate('Entity_statOutstandingAmount', '*args, **kwargs', 'return "1"')
def test_invalidateIfPersonBalanceIsOk_wrong_balance(self): def test_invalidateIfPersonBalanceIsOk_wrong_balance(self):
person = self.makePerson(index=0, user=0) person = self.makePerson(index=0, user=0)
ticket = self.createRegularisationRequest() ticket = self.createRegularisationRequest()
......
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