Commit 212192b0 authored by Łukasz Nowak's avatar Łukasz Nowak

Add alarm to manage person lock.

It checks all Persons and depending on thier balance and due date locks/unlocks.

Person is locked when thier balance is lower then configured one or when there
is ongoing payment older then accepted due period.

Person is unlocked when thier balance is higher then configured one and when
all ongoing payments are in acceptable time period.
parent 4f10b8a2
<?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_managePersonLock</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_manage_person_lock</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>5</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>946684800.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>Manages person locks</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>portal_catalog = context.getPortalObject().portal_catalog\n
from DateTime import DateTime\n
method_kw = {}\n
method_kw.update(\n
maximum_balance=context.portal_preferences.getPreferredMaximumBalance(),\n
maximum_due_date=(DateTime() - context.portal_preferences.getPreferredMaximumDueDay()).Date(),\n
simulation_state=context.getPortalCurrentInventoryStateList() + context.getPortalTransitInventoryStateList(),\n
ongoing_simulation_state=context.getPortalFutureInventoryStateList() + context.getPortalReservedInventoryStateList(),\n
section_uid=context.restrictedTraverse(\'organisation_module/vifib_internet\').getUid(), \n
)\n
portal_catalog.searchAndActivate(\n
method_id=\'Person_manageLockByBalance\',\n
portal_type=\'Person\',\n
activate_kw={\'tag\': tag},\n
method_kw=method_kw\n
)\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_managePersonLock</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[
locked = context.getSlapState() == \'locked\'\n
customer_uid = context.getUid()\n
balance = context.portal_simulation.getInventoryAssetPrice(\n
node_category=\'account_type/asset/receivable\',\n
simulation_state=simulation_state,\n
section_uid=section_uid,\n
mirror_section_uid=customer_uid)\n
\n
if maximum_balance > balance:\n
# customer reached his balance, shall be locked\n
if not locked:\n
context.lock()\n
return\n
\n
# check ongoing payments and check that date if is acceptable, if not lock\n
if context.portal_catalog.countResults(\n
portal_type=\'Payment Transaction\',\n
simulation_state=ongoing_simulation_state,\n
**{\n
\'delivery.destination_section_uid\': customer_uid,\n
\'delivery.start_date\': \'<= %s\' % maximum_due_date\n
})[0][0] > 0:\n
# there are ongoing old payments, shall be locked\n
if not locked:\n
context.lock()\n
else:\n
# there are no ongoing payments and balance is acceptable\n
if locked:\n
context.unlock()\n
]]></string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>maximum_balance, maximum_due_date, simulation_state, section_uid, ongoing_simulation_state</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Person_manageLockByBalance</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
522 523
\ No newline at end of file \ No newline at end of file
...@@ -2,6 +2,7 @@ portal_alarms/confirm_ordered_sale_order ...@@ -2,6 +2,7 @@ portal_alarms/confirm_ordered_sale_order
portal_alarms/stop_planned_sale_invoice_transaction portal_alarms/stop_planned_sale_invoice_transaction
portal_alarms/vifib_check_consistency portal_alarms/vifib_check_consistency
portal_alarms/vifib_lock_software_instance portal_alarms/vifib_lock_software_instance
portal_alarms/vifib_manage_person_lock
portal_alarms/vifib_trigger_build portal_alarms/vifib_trigger_build
portal_alarms/vifib_unlock_software_instance portal_alarms/vifib_unlock_software_instance
portal_alarms/vifib_update_open_sale_order_line portal_alarms/vifib_update_open_sale_order_line
\ 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