Commit 07918d75 authored by Romain Courteaud's avatar Romain Courteaud

slapos_accounting: add an alarm to close the open order

parent 8acc38fa
<?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_archiveOpenSaleOrderWithUnusedItem</string> </value>
</item>
<item>
<key> <string>automatic_solve</string> </key>
<value> <int>0</int> </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_archive_open_sale_order_with_unused_item</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>4</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>4</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="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="DateTime" module="DateTime.DateTime"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<tuple>
<float>-4861728000.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>Archive Open Sale Order</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal = context.getPortalObject()
portal.portal_catalog.searchAndActivate(
portal_type='Open Sale Order',
validation_state='validated',
ledger__uid=portal.portal_categories.ledger.automated.getUid(),
method_id='OpenSaleOrder_archiveIfUnusedItem',
activate_kw={'tag': tag}
)
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>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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_archiveOpenSaleOrderWithUnusedItem</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
open_sale_order = context
if open_sale_order.getValidationState() != 'validated':
return
if open_sale_order.getLedger() != 'automated':
raise ValueError('Can only archive automated open sale order')
for open_order_line in open_sale_order.contentValues(
portal_type='Open Sale Order Line'
):
content_list = open_order_line.contentValues()
if len(content_list) == 0:
content_list = [open_order_line]
for open_order_cell in content_list:
item = open_order_cell.getAggregateValue(portal_type=['Instance Tree', 'Compute Node', 'Project'])
if item is None:
raise AssertionError('No matching item on: %s' % open_order_cell.getRelativeUrl())
elif item.getPortalType() == 'Instance Tree':
if item.getSlapState() != 'destroy_requested':
# Do not touch if the instance is still started/stopped
return
elif item.getPortalType() == 'Compute Node':
# XXX TODO how to officially close a Compute Node
#raise NotImplementedError('what is the finished state for Compute Node')
return
elif item.getPortalType() == 'Project':
# Do not close project for now
return
else:
raise KeyError('Unexpected portal type: %s on %s' % (item.getPortalType(), open_order_cell.getRelativeUrl()))
# if the script didn't return before, we can archive the open sale order
now = DateTime()
open_sale_order.edit(stop_date=now)
open_sale_order.archive(comment='No item in used anymore')
return open_sale_order
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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>OpenSaleOrder_archiveIfUnusedItem</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -10,7 +10,7 @@
<key> <string>categories</string> </key>
<value>
<tuple>
<string>after_script/portal_workflow/slapos_accounting_interaction_workflow/script_Base_diverge</string>
<string>after_script/portal_workflow/slapos_accounting_interaction_workflow/script_Base_triggerArchiveOpenSaleOrderAlarm</string>
</tuple>
</value>
</item>
......@@ -31,7 +31,9 @@
<item>
<key> <string>portal_type_filter</string> </key>
<value>
<tuple/>
<tuple>
<string>Instance Tree</string>
</tuple>
</value>
</item>
<item>
......
document = state_change["object"]
if document.getPortalObject().portal_workflow.isTransitionPossible(document, 'diverge'):
document.diverge()
base = state_change['object']
portal = base.getPortalObject()
tag = script.id
base.reindexObject(activate_kw={'tag': tag})
context.Alarm_safeTrigger(portal.portal_alarms.slapos_archive_open_sale_order_with_unused_item, {'after_tag': tag})
......@@ -52,9 +52,15 @@
<key> <string>_params</string> </key>
<value> <string>state_change</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>script_Base_diverge</string> </value>
<value> <string>script_Base_triggerArchiveOpenSaleOrderAlarm</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
......
......@@ -16,6 +16,7 @@ business_process_module/slapos_ultimate_business_process/**
currency_module/CNY
currency_module/EUR
portal_alarms/slapos_accounting_generate_packing_list_from_tioxml
portal_alarms/slapos_archive_open_sale_order_with_unused_item
portal_alarms/slapos_cancel_sale_invoice_transaction_paied_payment_list
portal_alarms/slapos_contract_request_validation_payment
portal_alarms/slapos_manage_building_calculating_delivery
......
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