Commit 2a9621f1 authored by Łukasz Nowak's avatar Łukasz Nowak

Rebrand expanding.

Drop Sale Order expanding, as no Sale Orders are going to be present.

Switch alarm to expand *and* solve causality state in same moment. See
9d1b92cc which is changing causality state
on delivery state change.

Update test to reflect the change.
parent 9d1b92cc
......@@ -8,7 +8,7 @@
<dictionary>
<item>
<key> <string>active_sense_method_id</string> </key>
<value> <string>Alarm_updateCausalityState</string> </value>
<value> <string>Alarm_manageBuildingCalculatingDelivery</string> </value>
</item>
<item>
<key> <string>description</string> </key>
......@@ -22,7 +22,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>slapos_update_delivery_causality_state</string> </value>
<value> <string>slapos_manage_building_calculating_delivery</string> </value>
</item>
<item>
<key> <string>periodicity_hour</string> </key>
......@@ -83,7 +83,7 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Updates delivery\'s causality state</string> </value>
<value> <string>Operates on building and calculating deliveries</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -58,7 +58,7 @@ portal.portal_catalog.searchAndActivate(\n
portal_type=portal.getPortalDeliveryTypeList(),\n
causality_state=(\'building\', \'calculating\'),\n
activate_kw=activate_kw,\n
method_id=\'Delivery_updateCausalityState\'\n
method_id=\'Delivery_manageBuildingCalculatingDelivery\'\n
)\n
context.activate(after_tag=tag).getId()\n
</string> </value>
......@@ -69,7 +69,7 @@ context.activate(after_tag=tag).getId()\n
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Alarm_updateCausalityState</string> </value>
<value> <string>Alarm_manageBuildingCalculatingDelivery</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -57,7 +57,9 @@ path = delivery.getPath()\n
portal_activities = context.getPortalObject().portal_activities\n
if portal_activities.countMessage(path=path) == 0 \\\n
and portal_activities.countMessageWithTag(\'%s_solve\' % path) == 0:\n
delivery.serialize()\n
delivery.updateCausalityState(solve_automatically=False)\n
delivery.updateSimulation(expand_root=1, expand_related=1)\n
</string> </value>
</item>
<item>
......@@ -66,7 +68,7 @@ if portal_activities.countMessage(path=path) == 0 \\\n
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Delivery_updateCausalityState</string> </value>
<value> <string>Delivery_manageBuildingCalculatingDelivery</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -42,10 +42,10 @@ class Simulator:
open(self.outfile, 'w').write(repr(l))
return self.to_return
def simulateDelivery_updateCausalityState(func):
def simulateDelivery_manageBuildingCalculatingDelivery(func):
@functools.wraps(func)
def wrapped(self, *args, **kwargs):
script_name = 'Delivery_updateCausalityState'
script_name = 'Delivery_manageBuildingCalculatingDelivery'
if script_name in self.portal.portal_skins.custom.objectIds():
raise ValueError('Precondition failed: %s exists in custom' % script_name)
createZODBPythonScript(self.portal.portal_skins.custom,
......@@ -53,8 +53,8 @@ def simulateDelivery_updateCausalityState(func):
'*args, **kwargs',
'# Script body\n'
"""portal_workflow = context.portal_workflow
if context.getTitle() == 'Not visited by Delivery_updateCausalityState':
context.setTitle('Visited by Delivery_updateCausalityState')
if context.getTitle() == 'Not visited by Delivery_manageBuildingCalculatingDelivery':
context.setTitle('Visited by Delivery_manageBuildingCalculatingDelivery')
""" )
transaction.commit()
try:
......@@ -66,74 +66,87 @@ if context.getTitle() == 'Not visited by Delivery_updateCausalityState':
return wrapped
class TestAlarm(testSlapOSMixin):
@simulateDelivery_updateCausalityState
@simulateDelivery_manageBuildingCalculatingDelivery
def _test(self, state, message):
delivery = self.portal.sale_packing_list_module.newContent(
title='Not visited by Delivery_updateCausalityState',
title='Not visited by Delivery_manageBuildingCalculatingDelivery',
portal_type='Sale Packing List')
self.portal.portal_workflow._jumpToStateFor(delivery, state)
self.tic()
self.portal.portal_alarms.slapos_update_delivery_causality_state\
self.portal.portal_alarms.slapos_manage_building_calculating_delivery\
.activeSense()
self.tic()
self.assertEqual(message, delivery.getTitle())
def test_building(self):
self._test('building', 'Visited by Delivery_updateCausalityState')
self._test('building', 'Visited by Delivery_manageBuildingCalculatingDelivery')
def test_calculating(self):
self._test('calculating', 'Visited by Delivery_updateCausalityState')
self._test('calculating', 'Visited by Delivery_manageBuildingCalculatingDelivery')
def test_diverged(self):
self._test('diverged', 'Not visited by Delivery_updateCausalityState')
self._test('diverged', 'Not visited by Delivery_manageBuildingCalculatingDelivery')
def test_solved(self):
self._test('solved', 'Not visited by Delivery_updateCausalityState')
self._test('solved', 'Not visited by Delivery_manageBuildingCalculatingDelivery')
@withAbort
def _test_Delivery_updateCausalityState(self, state, empty=False):
def _test_Delivery_manageBuildingCalculatingDelivery(self, state, empty=False):
delivery = self.portal.sale_packing_list_module.newContent(
title='Not visited by Delivery_updateCausalityState',
title='Not visited by Delivery_manageBuildingCalculatingDelivery',
portal_type='Sale Packing List')
self.portal.portal_workflow._jumpToStateFor(delivery, state)
updateCausalityState_simulator = tempfile.mkstemp()[1]
updateSimulation_simulator = tempfile.mkstemp()[1]
try:
from Products.ERP5.Document.Delivery import Delivery
Delivery.original_updateCausalityState = Delivery\
.updateCausalityState
Delivery.updateCausalityState = Simulator(
updateCausalityState_simulator, 'updateCausalityState')
Delivery.updateSimulation = Simulator(
updateSimulation_simulator, 'updateSimulation')
delivery.Delivery_updateCausalityState()
delivery.Delivery_manageBuildingCalculatingDelivery()
value = eval(open(updateCausalityState_simulator).read())
updateCausalityState_value = eval(open(updateCausalityState_simulator).read())
updateSimulation_value = eval(open(updateSimulation_simulator).read())
if empty:
self.assertEqual([], value)
self.assertEqual([], updateCausalityState_value)
self.assertEqual([], updateSimulation_value)
else:
self.assertEqual([{
'recmethod': 'updateCausalityState',
'recargs': (),
'reckwargs': {'solve_automatically': False}}],
value
updateCausalityState_value
)
self.assertEqual([{
'recmethod': 'updateSimulation',
'recargs': (),
'reckwargs': {'expand_root': 1, 'expand_related': 1}}],
updateSimulation_value
)
finally:
Delivery.updateCausalityState = Delivery.original_updateCausalityState
delattr(Delivery, 'original_updateCausalityState')
if os.path.exists(updateCausalityState_simulator):
os.unlink(updateCausalityState_simulator)
if os.path.exists(updateSimulation_simulator):
os.unlink(updateSimulation_simulator)
def test_Delivery_updateCausalityState_calculating(self):
self._test_Delivery_updateCausalityState('calculating')
def test_Delivery_manageBuildingCalculatingDelivery_calculating(self):
self._test_Delivery_manageBuildingCalculatingDelivery('calculating')
def test_Delivery_updateCausalityState_building(self):
self._test_Delivery_updateCausalityState('building')
def test_Delivery_manageBuildingCalculatingDelivery_building(self):
self._test_Delivery_manageBuildingCalculatingDelivery('building')
def test_Delivery_updateCausalityState_solved(self):
self._test_Delivery_updateCausalityState('solved', True)
def test_Delivery_manageBuildingCalculatingDelivery_solved(self):
self._test_Delivery_manageBuildingCalculatingDelivery('solved', True)
def test_Delivery_updateCausalityState_diverged(self):
self._test_Delivery_updateCausalityState('diverged', True)
def test_Delivery_manageBuildingCalculatingDelivery_diverged(self):
self._test_Delivery_manageBuildingCalculatingDelivery('diverged', True)
43
\ No newline at end of file
44
\ No newline at end of file
......@@ -18,9 +18,9 @@ open_sale_order_module/slapos_accounting_open_sale_order_template
open_sale_order_module/template_open_sale_order
organisation_module/slapos
organisation_module/slapos/bank_account
portal_alarms/slapos_manage_building_calculating_delivery
portal_alarms/slapos_request_update_hosting_subscription_open_sale_order
portal_alarms/slapos_trigger_build
portal_alarms/slapos_update_delivery_causality_state
portal_categories/trade_phase/slapos
portal_categories/trade_phase/slapos/**
portal_deliveries/slapos_sale_packing_list_builder
......
testSlapOSAccountingConstraint
testSlapOSAccountingHostingSubscriptionSimulation
testSlapOSAccountingSlapOSManageBuildingCalculatingDelivery
testSlapOSAccountingSlapOSRequestUpdateHostingSubscriptionOpenSaleOrderAlarm
testSlapOSAccountingSlapOSTriggerBuildAlarm
testSlapOSAccountingSlapOSUpdateDeliveryCausalityStateAlarm
\ No newline at end of file
testSlapOSAccountingSlapOSTriggerBuildAlarm
\ No newline at end of file
<?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_expandConfirmedSaleOrder</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>vifib_expand_confirmed_sale_order</string> </value>
</item>
<item>
<key> <string>periodicity_day_frequency</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>periodicity_hour</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_minute</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_minute_frequency</string> </key>
<value> <int>1</int> </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>575131320.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>Expands Confirmed Sale Orders</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?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_expandDeliveryLine</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>vifib_expand_delivery_line</string> </value>
</item>
<item>
<key> <string>periodicity_hour</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_minute</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_minute_frequency</string> </key>
<value> <int>1</int> </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>306081720.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>Expands delivery lines, which need to be expanded</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?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>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
portal = context.getPortalObject()\n
activate_kw = {\n
\'tag\': tag\n
}\n
path_list = [q.getPath() for q in portal.Base_getNotCategoryRelatedList(\n
portal_type_list=[\'Sale Order Line\'],\n
simulation_state_list=[\'confirmed\'],\n
base_category_uid=portal.portal_categories.delivery.getUid())]\n
\n
if len(path_list) > 0:\n
portal.portal_catalog.searchAndActivate(\n
path=path_list,\n
activate_kw=activate_kw,\n
packet_size=1, # Separate calls to many transactions\n
method_id=\'DeliveryLine_updateAppliedRule\',\n
method_kw={\'activate_kw\': activate_kw, \'kw\': {\'activate_kw\': activate_kw}},\n
)\n
\n
# register activity on alarm object waiting for own tag in order to have only one alarm\n
# running in same time\n
context.activate(after_tag=tag).getId()\n
]]></string> </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_expandConfirmedSaleOrder</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?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>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
portal = context.getPortalObject()\n
\n
activate_kw = {\n
\'tag\': tag\n
}\n
simulation_state_list = portal.getPortalCurrentInventoryStateList() + \\\n
portal.getPortalTransitInventoryStateList() + portal.getPortalPlannedOrderStateList() + \\\n
portal.getPortalReservedInventoryStateList() + portal.getPortalFutureInventoryStateList()\n
kw = dict(\n
portal_type_list=[\'Sale Packing List Line\', \'Invoice Line\', \'Accounting Transaction Line\', \'Sale Invoice Transaction Line\'],\n
simulation_state_list=simulation_state_list,\n
base_category_uid=portal.portal_categories.delivery.getUid()\n
)\n
path_list = set()\n
\n
for q in portal.Base_getNotCategoryRelatedList(**kw):\n
path_list.add(q.getPath())\n
\n
for q in portal.Base_getNotSynchronisedSimulationStateCategoryRelatedList(**kw):\n
path_list.add(q.getPath())\n
\n
# and all invoice lines and and transcation lines in confirmed state\n
# XXX: We do simple version, and in Vifib confirmed ones can be often expanded, as it is short living state\n
\n
for q in portal.portal_catalog(portal_type=\'Invoice Line\', simulation_state=\'confirmed\'):\n
if q.getSimulationState() == \'confirmed\':\n
path_list.add(q.getPath())\n
path_list = list(path_list)\n
\n
if len(path_list) > 0:\n
portal.portal_catalog.searchAndActivate(\n
path=path_list,\n
packet_size=1, # Separate calls to many transactions\n
activate_kw=activate_kw,\n
method_id=\'DeliveryLine_updateAppliedRule\',\n
method_kw={\'activate_kw\': activate_kw, \'kw\': {\'activate_kw\': activate_kw}},\n
)\n
\n
# register activity on alarm object waiting for own tag in order to have only one alarm\n
# running in same time\n
context.activate(after_tag=tag).getId()\n
]]></string> </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_expandDeliveryLine</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?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>_body</string> </key>
<value> <string>delivery = context.getParentValue()\n
if context.getPortalObject().portal_activities.countMessage(path=delivery.getPath()) == 0:\n
delivery.serialize()\n
delivery.updateSimulation(expand_root=1, expand_related=1)\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>activate_kw, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>DeliveryLine_updateAppliedRule</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
516
\ No newline at end of file
517
\ No newline at end of file
portal_alarms/vifib_expand_confirmed_sale_order
portal_alarms/vifib_expand_delivery_line
portal_alarms/vifib_solve_automatically
\ No newline at end of file
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