Commit 8a31bd2d authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_accounting: Drop API Usage accounting related

The computation of the API usage is been removed. There is no reason to invoice the API usage anymore.

The consumption should be based on computer resource consumption or by time based subscriptions.
parent a676a610
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Alarm" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>active_sense_method_id</string> </key>
<value> <string>Alarm_searchDivergedInstanceList</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>slapos_instance_invoicing</string> </value>
</item>
<item>
<key> <string>periodicity_day_frequency</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>periodicity_hour</string> </key>
<value>
<tuple>
<int>2</int>
</tuple>
</value>
</item>
<item>
<key> <string>periodicity_hour_frequency</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>periodicity_minute</string> </key>
<value>
<tuple>
<int>0</int>
</tuple>
</value>
</item>
<item>
<key> <string>periodicity_minute_frequency</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>periodicity_month</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_month_day</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_start_date</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>0.0</float>
<string>GMT</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>periodicity_week</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Alarm</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Instance Invoicing</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -19,14 +19,6 @@
<type>Sale Packing List</type>
<workflow>slapos_accounting_interaction_workflow</workflow>
</chain>
<chain>
<type>Slave Instance</type>
<workflow>slapos_accounting_interaction_workflow, slapos_api_invoicing_workflow</workflow>
</chain>
<chain>
<type>Software Instance</type>
<workflow>slapos_accounting_interaction_workflow, slapos_api_invoicing_workflow</workflow>
</chain>
<chain>
<type>Subscription Item Root Simulation Rule</type>
<workflow>edit_workflow, rule_validation_workflow</workflow>
......
portal = context.getPortalObject()
portal.portal_catalog.searchAndActivate(
portal_type=["Slave Instance", "Software Instance"],
causality_state="diverged",
method_id='Instance_solveInvoicingGeneration',
activate_kw={'tag': tag},
packet_size=1, # Separate calls to many transactions (calculation can take time)
activity_count=1,
)
context.activate(after_tag=tag).getId()
<?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>tag, fixit, params</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Alarm_searchDivergedInstanceList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
instance = context
portal = instance.getPortalObject()
portal_workflow = portal.portal_workflow
if portal_workflow.isTransitionPossible(instance, 'converge'):
instance.converge()
slap_state = instance.getSlapState()
if slap_state == 'draft':
# Nothing to do except converging
pass
else:
started = "start_requested"
stopped = "stop_requested"
destroyed = "destroy_requested"
assert slap_state in [started, stopped, destroyed]
previous_length = instance.getInvoicingSynchronizationPointer(1)
history_list = portal_workflow.getInfoFor(ob=instance, name='history', wf_id='instance_slap_interface_workflow')
history_length = len(history_list)
history_entry = history_list[previous_length-1]
# no divergence if no new history entry
if (history_length != 1):
assert previous_length != history_length
setup_quantity = 0
update_quantity = 0
destroy_quantity = 0
current_delivery = instance.getCausalityValue()
if current_delivery is None:
# No previous packing list, so, one setup should be created
# Drop all useless draft line
i_in_draft_state = True
i = 0
while i_in_draft_state:
checking_history_entry = history_list[i]
previous_state = checking_history_entry['slap_state']
if previous_state != 'draft':
i_in_draft_state = False
previous_length = i
else:
setup_quantity += 1
i += 1
if slap_state == destroyed:
# Check if previous pointer was already in destroyed state
previous_state = history_entry['slap_state']
if previous_state != destroyed:
# Let's create destroyed packing list
destroy_quantity = 1
# 1 = entry to set document in draft state
update_quantity = history_length - previous_length - setup_quantity - destroy_quantity
# Time to create the PL
delivery_template = portal.restrictedTraverse(
portal.portal_preferences.getPreferredInstanceDeliveryTemplate())
delivery = delivery_template.Base_createCloneDocument(batch_mode=1)
hosting_subscription = instance.getSpecialiseValue(portal_type="Hosting Subscription")
person = hosting_subscription.getDestinationSectionValue(portal_type="Person")
delivery.edit(
title="%s API usage" % instance.getReference(),
destination=person.getRelativeUrl(),
destination_decision=person.getRelativeUrl(),
start_date=history_entry['time'],
stop_date=portal_workflow.getInfoFor(ob=instance, name='time', wf_id='instance_slap_interface_workflow'),
)
line_edit_kw = {
'aggregate_value_list': [instance, hosting_subscription],
}
if setup_quantity:
delivery_line_template = portal.restrictedTraverse(
portal.portal_preferences.getPreferredInstanceSetupMovementTemplate())
line = delivery_line_template.Base_createCloneDocument(batch_mode=1,
destination=delivery)
line.edit(
quantity=1,
title="%s setup %s" % (instance.getReference(), setup_quantity),
**line_edit_kw
)
if update_quantity > 0:
delivery_line_template = portal.restrictedTraverse(
portal.portal_preferences.getPreferredInstanceUpdateMovementTemplate())
line = delivery_line_template.Base_createCloneDocument(batch_mode=1,
destination=delivery)
line.edit(
quantity=update_quantity,
title="%s updated %i times" % (instance.getReference(), update_quantity),
**line_edit_kw
)
if destroy_quantity:
delivery_line_template = portal.restrictedTraverse(
portal.portal_preferences.getPreferredInstanceDestroyMovementTemplate())
line = delivery_line_template.Base_createCloneDocument(batch_mode=1,
destination=delivery)
line.edit(
quantity=destroy_quantity,
title="%s destroyed" % instance.getReference(),
**line_edit_kw
)
delivery.confirm()
delivery.start()
delivery.stop()
delivery.deliver()
delivery.startBuilding()
instance.edit(
invoicing_synchronization_pointer=history_length,
causality_value=delivery,
)
<?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>Instance_solveInvoicingGeneration</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="InteractionDefinition" module="Products.ERP5.Interaction"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>actbox_category</string> </key>
<value> <string>workflow</string> </value>
</item>
<item>
<key> <string>actbox_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>actbox_url</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>activate_script_name</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>after_script_name</string> </key>
<value>
<list>
<string>Base_diverge</string>
</list>
</value>
</item>
<item>
<key> <string>before_commit_script_name</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>guard</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Instance_changePromiseState</string> </value>
</item>
<item>
<key> <string>method_id</string> </key>
<value>
<list>
<string>requestStart</string>
<string>requestStop</string>
<string>requestDestroy</string>
<string>bang</string>
</list>
</value>
</item>
<item>
<key> <string>once_per_transaction</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>portal_type_filter</string> </key>
<value>
<list>
<string>Slave Instance</string>
<string>Software Instance</string>
</list>
</value>
</item>
<item>
<key> <string>script_name</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>temporary_document_disallowed</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>trigger_type</string> </key>
<value> <int>2</int> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -26,7 +26,6 @@ organisation_module/slapos/bank_account
portal_alarms/slapos_accounting_generate_packing_list_from_tioxml
portal_alarms/slapos_contract_request_validation_payment
portal_alarms/slapos_deliver_started_aggregated_sale_packing_list
portal_alarms/slapos_instance_invoicing
portal_alarms/slapos_manage_building_calculating_delivery
portal_alarms/slapos_reindex_open_sale_order
portal_alarms/slapos_remove_bogus_delivery_link
......
......@@ -7,10 +7,6 @@ Hosting Subscription | slapos_accounting_interaction_workflow
Hosting Subscription | slapos_api_invoicing_workflow
Sale Invoice Transaction | slapos_accounting_interaction_workflow
Sale Packing List | slapos_accounting_interaction_workflow
Slave Instance | slapos_accounting_interaction_workflow
Slave Instance | slapos_api_invoicing_workflow
Software Instance | slapos_accounting_interaction_workflow
Software Instance | slapos_api_invoicing_workflow
Subscription Item Root Simulation Rule | edit_workflow
Subscription Item Root Simulation Rule | rule_validation_workflow
User Consumption HTML File | document_conversion_interaction_workflow
......
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