Commit f5a1573a authored by Romain Courteaud's avatar Romain Courteaud

slapos_crm: fixup slapos_crm_create_regularisation_request tests

parent 89d0ba45
......@@ -3,28 +3,23 @@ portal = context.getPortalObject()
person_uid_list = []
for (_, brain) in enumerate(portal.portal_simulation.getInventoryList(
simulation_state=('stopped', 'delivered'),
parent_payment_mode_uid = [
portal.portal_categories.payment_mode.payzen.getUid(),
portal.portal_categories.payment_mode.wechat.getUid()],
group_by_mirror_section=True,
portal_type=portal.getPortalAccountingMovementTypeList(),
node_uid=[x.uid for x in context.Base_getReceivableAccountList()],
grouping_reference=None)):
parent__ledger__uid=portal.portal_categories.ledger.automated.getUid(),
grouping_reference=None
)):
payment_request_uid = brain.payment_request_uid
if not payment_request_uid:
payment_request_uid = brain.getObject().getExplanationUid()
payment_request = portal.portal_catalog.getObject(uid=payment_request_uid)
section_uid = payment_request.getDestinationSectionUid(portal_type="Person")
section_uid = brain.getDestinationSectionUid(portal_type="Person")
if section_uid is not None:
person_uid_list.append(section_uid)
portal.portal_catalog.searchAndActivate(
portal_type="Person",
validation_state="validated",
uid=person_uid_list,
method_id='Person_checkToCreateRegularisationRequest',
activate_kw={'tag': tag}
)
if person_uid_list:
portal.portal_catalog.searchAndActivate(
portal_type="Person",
validation_state="validated",
uid=person_uid_list,
method_id='Person_checkToCreateRegularisationRequest',
activate_kw={'tag': tag}
)
context.activate(after_tag=tag).getId()
......@@ -24,144 +24,144 @@ from erp5.component.test.SlapOSTestCaseMixin import \
SlapOSTestCaseMixin, SlapOSTestCaseMixinWithAbort
from DateTime import DateTime
class TestSlapOSCRMCreateRegularisationRequest(SlapOSTestCaseMixin):
def createFinalInvoice(self, person):
template = self.portal.restrictedTraverse(
self.portal.portal_preferences.getPreferredDefaultPrePaymentSubscriptionInvoiceTemplate())
current_invoice = template.Base_createCloneDocument(batch_mode=1)
current_invoice.edit(
destination_value=person,
class TestSlapOSCRMCreateRegularisationRequestAlarm(SlapOSTestCaseMixin):
def createFinalInvoice(self, person, grouping_reference=None,
ledger="automated",
source="account_module/receivable",
is_stopped=True):
current_invoice = self.portal.accounting_module.newContent(
portal_type="Sale Invoice Transaction",
destination_section_value=person,
destination_decision_value=person,
start_date=DateTime('2019/10/20'),
stop_date=DateTime('2019/10/20'),
title='Fake Invoice for Demo User Functional',
price_currency="currency_module/EUR",
reference='1')
cell = current_invoice["1"]["movement_0"]
cell.edit(quantity=1)
cell.setPrice(1)
resource="currency_module/EUR",
reference='1',
ledger=ledger)
current_invoice.receivable.edit(
source=source,
quantity=1,
price=1,
grouping_reference=grouping_reference
)
current_invoice.plan()
current_invoice.confirm()
current_invoice.startBuilding()
current_invoice.reindexObject()
current_invoice.stop()
if is_stopped:
current_invoice.stop()
self.tic()
current_invoice.Delivery_manageBuildingCalculatingDelivery()
self.tic()
applied_rule = current_invoice.getCausalityRelated(portal_type="Applied Rule")
for sm in self.portal.portal_catalog(portal_type='Simulation Movement',
simulation_state=['draft', 'planned', None],
left_join_list=['delivery_uid'],
delivery_uid=None,
path="%%%s%%" % applied_rule):
if sm.getDelivery() is not None:
continue
root_applied_rule = sm.getRootAppliedRule()
root_applied_rule_path = root_applied_rule.getPath()
sm.getCausalityValue(portal_type='Business Link').build(
path='%s/%%' % root_applied_rule_path)
return current_invoice
def test_createRegularisationRequest_expected_person(self):
#################################################################
# slapos_crm_create_regularisation_request
#################################################################
def test_Person_checkToCreateRegularisationRequest_alarm_expectedPerson(self):
new_id = self.generateNewId()
person = self.portal.person_module.newContent(
portal_type='Person',
title="Test person %s" % new_id
)
person.validate()
self.createFinalInvoice(person)
self.tic()
alarm = self.portal.portal_alarms.\
slapos_crm_create_regularisation_request
self._test_alarm(alarm, person, "Person_checkToCreateRegularisationRequest")
self._test_alarm(
self.portal.portal_alarms.slapos_crm_create_regularisation_request,
person,
'Person_checkToCreateRegularisationRequest'
)
def test_createRegularisationRequest_not_validated(self):
def test_Person_checkToCreateRegularisationRequest_alarm_started(self):
new_id = self.generateNewId()
person = self.portal.person_module.newContent(
portal_type='Person',
title="Test person %s" % new_id
)
person.validate()
self.createFinalInvoice(person)
person.invalidate()
self.createFinalInvoice(person, is_stopped=False)
self.tic()
alarm = self.portal.portal_alarms.\
slapos_crm_create_regularisation_request
self._test_alarm_not_visited(alarm, person, "Person_checkToCreateRegularisationRequest")
self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_crm_create_regularisation_request,
person,
'Person_checkToCreateRegularisationRequest'
)
def test_createRegularisationRequest_payment_stopped(self):
def test_Person_checkToCreateRegularisationRequest_alarm_lettered(self):
new_id = self.generateNewId()
person = self.portal.person_module.newContent(
portal_type='Person',
title="Test person %s" % new_id
)
person.validate()
current_invoice = self.createFinalInvoice(person)
payment_template = self.portal.restrictedTraverse(
self.portal.portal_preferences.getPreferredDefaultPrePaymentTemplate())
payment = payment_template.Base_createCloneDocument(batch_mode=1)
for line in payment.contentValues():
if line.getSource() == "account_module/payment_to_encash":
line.setQuantity(-1)
elif line.getSource() == "account_module/receivable":
line.setQuantity(1)
payment.confirm()
payment.start()
payment.setCausalityValue(current_invoice)
payment.setDestinationSectionValue(person)
payment.stop()
self.createFinalInvoice(person, grouping_reference="foobar")
self.tic()
self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_crm_create_regularisation_request,
person,
'Person_checkToCreateRegularisationRequest'
)
def test_Person_checkToCreateRegularisationRequest_alarm_noLedger(self):
new_id = self.generateNewId()
person = self.portal.person_module.newContent(
portal_type='Person',
title="Test person %s" % new_id
)
person.validate()
self.createFinalInvoice(person, ledger=None)
self.tic()
alarm = self.portal.portal_alarms.\
slapos_crm_create_regularisation_request
self._test_alarm_not_visited(alarm, person, "Person_checkToCreateRegularisationRequest")
self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_crm_create_regularisation_request,
person,
'Person_checkToCreateRegularisationRequest'
)
def test_createRegularisationRequest_payment_started(self):
def test_Person_checkToCreateRegularisationRequest_alarm_noReceivable(self):
new_id = self.generateNewId()
person = self.portal.person_module.newContent(
portal_type='Person',
title="Test person %s" % new_id
)
person.validate()
self.createFinalInvoice(person, source="account_module/bank")
self.tic()
self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_crm_create_regularisation_request,
person,
'Person_checkToCreateRegularisationRequest'
)
current_invoice = self.createFinalInvoice(person)
payment_template = self.portal.restrictedTraverse(
self.portal.portal_preferences.getPreferredDefaultPrePaymentTemplate())
payment = payment_template.Base_createCloneDocument(batch_mode=1)
for line in payment.contentValues():
if line.getSource() == "account_module/payment_to_encash":
line.setQuantity(-1)
elif line.getSource() == "account_module/receivable":
line.setQuantity(1)
payment.confirm()
payment.start()
payment.setCausalityValue(current_invoice)
payment.setDestinationSectionValue(person)
def test_Person_checkToCreateRegularisationRequest_alarm_notValidatedPerson(self):
new_id = self.generateNewId()
person = self.portal.person_module.newContent(
portal_type='Person',
title="Test person %s" % new_id
)
person.validate()
person.invalidate()
self.createFinalInvoice(person)
self.tic()
self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_crm_create_regularisation_request,
person,
'Person_checkToCreateRegularisationRequest'
)
def test_Person_checkToCreateRegularisationRequest_alarm_noInvoice(self):
new_id = self.generateNewId()
person = self.portal.person_module.newContent(
portal_type='Person',
title="Test person %s" % new_id
)
person.validate()
self.tic()
alarm = self.portal.portal_alarms.\
slapos_crm_create_regularisation_request
self._test_alarm(alarm, person, "Person_checkToCreateRegularisationRequest")
self._test_alarm_not_visited(
self.portal.portal_alarms.slapos_crm_create_regularisation_request,
person,
'Person_checkToCreateRegularisationRequest'
)
# XXX couscous
class TestSlapOSCrmInvalidateSuspendedRegularisationRequest(SlapOSTestCaseMixinWithAbort):
......@@ -488,7 +488,7 @@ class TestSlapOSCrmMonitoringCheckComputeNodeState(SlapOSTestCaseMixinWithAbort)
def _test_alarm_check_compute_node_state_selected(self, allocation_scope,
monitor_scope=None):
self._makeComputeNode()
self._makeComputeNode(self.addProject())
self.compute_node.edit(allocation_scope=allocation_scope)
self.tic()
if monitor_scope is not None:
......@@ -557,16 +557,13 @@ class TestSlapOSCrmMonitoringCheckComputeNodeSoftwareInstallation(SlapOSTestCase
self._makeComputeNode(self.addProject())
self.compute_node.edit(allocation_scope=allocation_scope)
self.tic()
if monitor_scope is not None:
self.compute_node.edit(monitor_scope=monitor_scope)
self.tic()
alarm = self.portal.portal_alarms.\
slapos_crm_check_software_installation_state
self._test_alarm_not_visited(alarm, self.compute_node, "ComputeNode_checkSoftwareInstallationState")
def _test_alarm_run_on_close(self, allocation_scope,):
self._makeComputeNode()
def _test_alarm_run_on_close(self, allocation_scope):
self._makeComputeNode(self.addProject())
self.compute_node.edit(allocation_scope=allocation_scope)
self.tic()
......
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