Commit 646d5bf5 authored by Romain Courteaud's avatar Romain Courteaud

slapos_crm: create regularisation request for organisations

Stop and delete b2b services
parent f8b48a03
Pipeline #39078 failed with stage
in 0 seconds
portal = context.getPortalObject() portal = context.getPortalObject()
person_uid_list = [] entity_uid_list = []
for (_, brain) in enumerate(portal.portal_simulation.getInventoryList( for (_, brain) in enumerate(portal.portal_simulation.getInventoryList(
simulation_state=('stopped', 'delivered'), simulation_state=('stopped', 'delivered'),
group_by_mirror_section=True, group_by_mirror_section=True,
...@@ -10,16 +10,16 @@ for (_, brain) in enumerate(portal.portal_simulation.getInventoryList( ...@@ -10,16 +10,16 @@ for (_, brain) in enumerate(portal.portal_simulation.getInventoryList(
grouping_reference=None grouping_reference=None
)): )):
section_uid = brain.getDestinationSectionUid(portal_type="Person") section_uid = brain.getDestinationSectionUid(portal_type=["Person", "Organisation"])
if section_uid is not None: if section_uid is not None:
person_uid_list.append(section_uid) entity_uid_list.append(section_uid)
if person_uid_list: if entity_uid_list:
portal.portal_catalog.searchAndActivate( portal.portal_catalog.searchAndActivate(
portal_type="Person", portal_type=["Person", "Organisation"],
validation_state="validated", validation_state="validated",
uid=person_uid_list, uid=entity_uid_list,
method_id='Person_checkToCreateRegularisationRequest', method_id='Entity_checkToCreateRegularisationRequest',
activate_kw={'tag': tag} activate_kw={'tag': tag}
) )
context.activate(after_tag=tag).getId() context.activate(after_tag=tag).getId()
portal = context.getPortalObject() portal = context.getPortalObject()
portal.portal_catalog.searchAndActivate( portal.portal_catalog.searchAndActivate(
portal_type="Regularisation Request", portal_type="Regularisation Request",
simulation_state=["suspended", "validated"], simulation_state=["suspended", "validated"],
method_id='RegularisationRequest_invalidateIfPersonBalanceIsOk', method_id='RegularisationRequest_invalidateIfEntityBalanceIsOk',
activate_kw={'tag': tag} activate_kw={'tag': tag}
) )
context.activate(after_tag=tag).getId() context.activate(after_tag=tag).getId()
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>Person_checkToCreateRegularisationRequest</string> </value> <value> <string>Entity_checkToCreateRegularisationRequest</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
...@@ -4,9 +4,9 @@ if REQUEST is not None: ...@@ -4,9 +4,9 @@ if REQUEST is not None:
ticket = context ticket = context
state = ticket.getSimulationState() state = ticket.getSimulationState()
person = ticket.getDestinationDecisionValue(portal_type="Person") entity = ticket.getDestinationDecisionValue(portal_type=["Person", "Organisation"])
if (state == 'suspended') and \ if (state == 'suspended') and \
(person is not None) and \ (entity is not None) and \
(ticket.getResource() == 'service_module/slapos_crm_delete_acknowledgement'): (ticket.getResource() == 'service_module/slapos_crm_delete_acknowledgement'):
portal = context.getPortalObject() portal = context.getPortalObject()
...@@ -14,16 +14,17 @@ if (state == 'suspended') and \ ...@@ -14,16 +14,17 @@ if (state == 'suspended') and \
ledger_uid = portal.portal_categories.ledger.automated.getUid() ledger_uid = portal.portal_categories.ledger.automated.getUid()
# Gather the list of not paid services # Gather the list of not paid services
for outstanding_amount in person.Entity_getOutstandingAmountList( for outstanding_amount in entity.Entity_getOutstandingAmountList(
ledger_uid=ledger_uid, ledger_uid=ledger_uid,
include_planned=True include_planned=True
): ):
for outstanding_invoice in person.Entity_getOutstandingAmountList( for outstanding_invoice in entity.Entity_getOutstandingAmountList(
section_uid=outstanding_amount.getSourceSectionUid(), section_uid=outstanding_amount.getSourceSectionUid(),
resource_uid=outstanding_amount.getPriceCurrencyUid(), resource_uid=outstanding_amount.getPriceCurrencyUid(),
ledger_uid=outstanding_amount.getLedgerUid(), ledger_uid=outstanding_amount.getLedgerUid(),
group_by_node=False group_by_node=False
): ):
person = outstanding_invoice.getDestinationValue(portal_type="Person")
subscribed_item = None subscribed_item = None
for invoice_line in outstanding_invoice.getMovementList( for invoice_line in outstanding_invoice.getMovementList(
portal_type=['Invoice Line', 'Invoice Cell'] portal_type=['Invoice Line', 'Invoice Cell']
......
...@@ -3,10 +3,10 @@ if REQUEST is not None: ...@@ -3,10 +3,10 @@ if REQUEST is not None:
raise Unauthorized raise Unauthorized
state = context.getSimulationState() state = context.getSimulationState()
person = context.getDestinationDecisionValue(portal_type="Person") entity = context.getDestinationDecisionValue(portal_type=["Person", "Organisation"])
if (state not in ('suspended', 'validated')) or \ if (state not in ('suspended', 'validated')) or \
(person is None): (entity is None):
return return
if not person.Entity_hasOutstandingAmount(ledger_uid=context.getPortalObject().portal_categories.ledger.automated.getUid()): if not entity.Entity_hasOutstandingAmount(ledger_uid=context.getPortalObject().portal_categories.ledger.automated.getUid()):
context.invalidate(comment="Automatically disabled as balance is ok") context.invalidate(comment="Automatically disabled as balance is ok")
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>RegularisationRequest_invalidateIfPersonBalanceIsOk</string> </value> <value> <string>RegularisationRequest_invalidateIfEntityBalanceIsOk</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
...@@ -4,19 +4,47 @@ if REQUEST is not None: ...@@ -4,19 +4,47 @@ if REQUEST is not None:
ticket = context ticket = context
state = ticket.getSimulationState() state = ticket.getSimulationState()
person = ticket.getDestinationDecisionValue(portal_type="Person") entity = ticket.getDestinationDecisionValue(portal_type=["Person", "Organisation"])
if (state == 'suspended') and \ if (state == 'suspended') and \
(person is not None) and \ (entity is not None) and \
(ticket.getResource() in ['service_module/slapos_crm_stop_acknowledgement', 'service_module/slapos_crm_delete_reminder', 'service_module/slapos_crm_delete_acknowledgement']): (ticket.getResource() in ['service_module/slapos_crm_stop_acknowledgement', 'service_module/slapos_crm_delete_reminder', 'service_module/slapos_crm_delete_acknowledgement']):
portal = context.getPortalObject() portal = context.getPortalObject()
portal.portal_catalog.searchAndActivate(
portal_type="Instance Tree", ledger_uid = portal.portal_categories.ledger.automated.getUid()
validation_state=["validated"], # Gather the list of not paid services
destination_section__uid=person.getUid(), for outstanding_amount in entity.Entity_getOutstandingAmountList(
method_id='InstanceTree_stopFromRegularisationRequest', ledger_uid=ledger_uid,
method_args=(person.getRelativeUrl(),), include_planned=True
activate_kw={'tag': tag} ):
) for outstanding_invoice in entity.Entity_getOutstandingAmountList(
section_uid=outstanding_amount.getSourceSectionUid(),
resource_uid=outstanding_amount.getPriceCurrencyUid(),
ledger_uid=outstanding_amount.getLedgerUid(),
group_by_node=False
):
person = outstanding_invoice.getDestinationValue(portal_type="Person")
subscribed_item = None
for invoice_line in outstanding_invoice.getMovementList(
portal_type=['Invoice Line', 'Invoice Cell']
):
hosting_subscription = invoice_line.getAggregateValue(portal_type='Hosting Subscription')
if hosting_subscription is not None:
subscribed_item = invoice_line.getAggregateValue(portal_type=[
'Project',
'Instance Tree',
'Compute Node'
])
if subscribed_item is None:
raise NotImplementedError('Unhandled invoice line %s' % invoice_line.getRelativeUrl())
if (subscribed_item.getPortalType() == 'Instance Tree'):
# change the slap state to stopped, to allow propagation of the state
# even on remote node
subscribed_item.InstanceTree_stopFromRegularisationRequest(person.getRelativeUrl())
if subscribed_item is None:
raise NotImplementedError('Unhandled invoice %s' % outstanding_invoice.getRelativeUrl())
return True return True
return False return False
...@@ -23,7 +23,7 @@ return context.RegularisationRequest_checkToTriggerNextEscalationStep( ...@@ -23,7 +23,7 @@ return context.RegularisationRequest_checkToTriggerNextEscalationStep(
comment='Stopping reminder.', comment='Stopping reminder.',
notification_message="slapos-crm.acknowledgment.escalation", notification_message="slapos-crm.acknowledgment.escalation",
substitution_method_parameter_dict={ substitution_method_parameter_dict={
'user_name': context.getDestinationSectionTitle(), 'user_name': context.getDestinationDecisionTitle(),
'days': ndays 'days': ndays
} }
) )
...@@ -23,7 +23,7 @@ return context.RegularisationRequest_checkToTriggerNextEscalationStep( ...@@ -23,7 +23,7 @@ return context.RegularisationRequest_checkToTriggerNextEscalationStep(
comment='Deleting acknowledgment.', comment='Deleting acknowledgment.',
notification_message="slapos-crm.delete.reminder.escalation", notification_message="slapos-crm.delete.reminder.escalation",
substitution_method_parameter_dict={ substitution_method_parameter_dict={
'user_name': context.getDestinationSectionTitle(), 'user_name': context.getDestinationDecisionTitle(),
'days': ndays 'days': ndays
} }
) )
...@@ -22,7 +22,7 @@ return context.RegularisationRequest_checkToTriggerNextEscalationStep( ...@@ -22,7 +22,7 @@ return context.RegularisationRequest_checkToTriggerNextEscalationStep(
comment='Deleting reminder.', comment='Deleting reminder.',
notification_message="slapos-crm.stop.acknowledgment.escalation", notification_message="slapos-crm.stop.acknowledgment.escalation",
substitution_method_parameter_dict={ substitution_method_parameter_dict={
'user_name': context.getDestinationSectionTitle(), 'user_name': context.getDestinationDecisionTitle(),
'days': ndays 'days': ndays
} }
) )
...@@ -23,7 +23,7 @@ return context.RegularisationRequest_checkToTriggerNextEscalationStep( ...@@ -23,7 +23,7 @@ return context.RegularisationRequest_checkToTriggerNextEscalationStep(
comment='Stopping acknowledgment.', comment='Stopping acknowledgment.',
notification_message="slapos-crm.stop.reminder.escalation", notification_message="slapos-crm.stop.reminder.escalation",
substitution_method_parameter_dict={ substitution_method_parameter_dict={
'user_name': context.getDestinationSectionTitle(), 'user_name': context.getDestinationDecisionTitle(),
'days': ndays 'days': ndays
} }
) )
...@@ -157,7 +157,9 @@ class TestSlapOSVirtualMasterScenarioMixin(DefaultScenarioMixin): ...@@ -157,7 +157,9 @@ class TestSlapOSVirtualMasterScenarioMixin(DefaultScenarioMixin):
# required to generate accounting report # required to generate accounting report
price_currency_value=currency, price_currency_value=currency,
# required to calculate the vat # required to calculate the vat
default_address_region='europe/west/france' default_address_region='europe/west/france',
# required email to send events
default_email_url_string='test@example.org'
) )
seller_bank_account = seller_organisation.newContent( seller_bank_account = seller_organisation.newContent(
portal_type="Bank Account", portal_type="Bank Account",
...@@ -553,7 +555,9 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin): ...@@ -553,7 +555,9 @@ class TestSlapOSVirtualMasterScenario(TestSlapOSVirtualMasterScenarioMixin):
portal_type='Organisation', portal_type='Organisation',
title='TestOrganisation Section %s' % self.generateNewId(), title='TestOrganisation Section %s' % self.generateNewId(),
default_address_region='europe/west/france', default_address_region='europe/west/france',
vat_code=self.generateNewId() vat_code=self.generateNewId(),
# required email to send events
default_email_url_string='test@example.org'
) )
customer_section_organisation.validate() customer_section_organisation.validate()
......
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