Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Romain Courteaud
slapos.core
Commits
1b159fab
Commit
1b159fab
authored
Apr 04, 2023
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos_subscription_request: create Subscription Request from orphaned Instance Tree
parent
fde623c2
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
399 additions
and
1 deletion
+399
-1
master/bt5/slapos_subscription_request/PathTemplateItem/portal_alarms/slapos_subscription_request_create_from_orphaned_item.xml
...slapos_subscription_request_create_from_orphaned_item.xml
+97
-0
master/bt5/slapos_subscription_request/SkinTemplateItem/portal_skins/slapos_subscription_request/Alarm_createSubscriptionRequestFromOrphanedItem.py
...equest/Alarm_createSubscriptionRequestFromOrphanedItem.py
+20
-0
master/bt5/slapos_subscription_request/SkinTemplateItem/portal_skins/slapos_subscription_request/Alarm_createSubscriptionRequestFromOrphanedItem.xml
...quest/Alarm_createSubscriptionRequestFromOrphanedItem.xml
+62
-0
master/bt5/slapos_subscription_request/SkinTemplateItem/portal_skins/slapos_subscription_request/Item_createSubscriptionRequest.py
...os_subscription_request/Item_createSubscriptionRequest.py
+156
-0
master/bt5/slapos_subscription_request/SkinTemplateItem/portal_skins/slapos_subscription_request/Item_createSubscriptionRequest.xml
...s_subscription_request/Item_createSubscriptionRequest.xml
+62
-0
master/bt5/slapos_subscription_request/bt/template_path_list
master/bt5/slapos_subscription_request/bt/template_path_list
+2
-1
No files found.
master/bt5/slapos_subscription_request/PathTemplateItem/portal_alarms/slapos_subscription_request_create_from_orphaned_item.xml
0 → 100644
View file @
1b159fab
<?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_createSubscriptionRequestFromOrphanedItem
</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_subscription_request_create_from_orphaned_item
</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>
2
</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=
"_reconstructor"
module=
"copy_reg"
/>
</klass>
<tuple>
<global
name=
"DateTime"
module=
"DateTime.DateTime"
/>
<global
name=
"object"
module=
"__builtin__"
/>
<none/>
</tuple>
<state>
<tuple>
<float>
1677632460.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>
Create Subscription Request from orphaned item
</string>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
master/bt5/slapos_subscription_request/SkinTemplateItem/portal_skins/slapos_subscription_request/Alarm_createSubscriptionRequestFromOrphanedItem.py
0 → 100644
View file @
1b159fab
portal
=
context
.
getPortalObject
()
# XXX if there is a non Subscription Request with such aggregate link
# it will lead to not creating the Subscription Request
# TODO find a way to check the portal type
select_dict
=
{
'aggregate__related__uid'
:
None
}
kw
=
{}
kw
[
'select_dict'
]
=
select_dict
kw
[
'left_join_list'
]
=
select_dict
.
keys
()
kw
[
'aggregate__related__uid'
]
=
None
portal
.
portal_catalog
.
searchAndActivate
(
method_id
=
'Item_createSubscriptionRequest'
,
# Project are created only from UI for now
portal_type
=
[
"Instance Tree"
],
activate_kw
=
{
'tag'
:
tag
},
**
kw
)
context
.
activate
(
after_tag
=
tag
).
getId
()
master/bt5/slapos_subscription_request/SkinTemplateItem/portal_skins/slapos_subscription_request/Alarm_createSubscriptionRequestFromOrphanedItem.xml
0 → 100644
View file @
1b159fab
<?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_createSubscriptionRequestFromOrphanedItem
</string>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
master/bt5/slapos_subscription_request/SkinTemplateItem/portal_skins/slapos_subscription_request/Item_createSubscriptionRequest.py
0 → 100644
View file @
1b159fab
from
zExceptions
import
Unauthorized
if
REQUEST
is
not
None
:
raise
Unauthorized
item
=
context
portal
=
context
.
getPortalObject
()
tag
=
'%s_%s'
%
(
item
.
getUid
(),
script
.
id
)
activate_kw
=
{
'tag'
:
tag
}
if
0
<
portal
.
portal_activities
.
countMessageWithTag
(
tag
):
# nothing to do
return
def
storeWorkflowComment
(
document
,
comment
):
portal_workflow
=
document
.
portal_workflow
last_workflow_item
=
portal_workflow
.
getInfoFor
(
ob
=
document
,
name
=
'comment'
,
wf_id
=
'edit_workflow'
)
if
last_workflow_item
!=
comment
:
portal_workflow
.
doActionFor
(
document
,
action
=
'edit_action'
,
comment
=
comment
)
# Search an existing related subscription
subscription_request
=
portal
.
portal_catalog
.
getResultValue
(
portal_type
=
'Subscription Request'
,
aggregate__uid
=
item
.
getUid
()
)
if
subscription_request
is
not
None
:
return
#################################################################
# Find matching Service
service
=
None
source_decision_value
=
None
project_value
=
None
resource_vcl
=
[]
if
item
.
getPortalType
()
==
'Instance Tree'
:
service
,
software_release
,
software_type
=
item
.
InstanceTree_getSoftwareProduct
()
source_decision_value
=
item
.
getDestinationSectionValue
(
portal_type
=
"Person"
)
project_value
=
item
.
getFollowUpValue
(
portal_type
=
"Project"
)
if
service
is
not
None
:
resource_vcl
=
[
'software_release/%s'
%
software_release
.
getRelativeUrl
(),
'software_type/%s'
%
software_type
.
getRelativeUrl
()
]
resource_vcl
.
sort
()
else
:
raise
ValueError
(
'Unsupported portal type: %s (%s)'
%
(
item
.
getPortalType
(),
item
.
getRelativeUrl
()))
# service = self.portal.restrictedTraverse('service_module/slapos_virtual_master_subscription')
if
service
is
None
:
storeWorkflowComment
(
item
,
'Can not find a matching Service to generate the Subscription Request'
)
return
if
source_decision_value
is
None
:
storeWorkflowComment
(
item
,
'Can not find the person to contact to generate the Subscription Request'
)
return
#################################################################
# Find Sale Trade Condition and price
source_section_value
=
source_decision_value
.
getCareerSubordinationValue
(
source_decision_value
)
source_section_value
=
source_decision_value
.
getCareerSubordinationValue
(
source_decision_value
)
# Create a temp Sale Order to calculate the real price and find the trade condition
now
=
DateTime
()
module
=
portal
.
sale_order_module
#aggregate_value_list = []
tmp_sale_order
=
module
.
newContent
(
portal_type
=
'Sale Order'
,
temp_object
=
True
,
#effective_date=now+1,
start_date
=
now
,
# Ensure stop date value is higher than start date
# it will be updated by OpenSaleOrder_updatePeriod
# stop_date=now + 2,
destination_value
=
source_decision_value
,
destination_section_value
=
source_section_value
,
#destination_decision_value=source_decision_value,
destination_project_value
=
project_value
,
ledger_value
=
portal
.
portal_categories
.
ledger
.
automated
,
# XXX XXX destination_project_value=instance_tree.getFollowUpValue(),
)
tmp_sale_order
.
SaleOrder_applySaleTradeCondition
(
batch_mode
=
1
,
force
=
1
)
if
tmp_sale_order
.
getSpecialise
(
None
)
is
None
:
storeWorkflowComment
(
item
,
'Can not find a trade condition to generate the Subscription Request'
)
return
# If no accounting is needed, no need to check the price
if
tmp_sale_order
.
getSourceSection
(
None
)
==
tmp_sale_order
.
getDestinationSection
(
None
):
price
=
0
else
:
# Add line
tmp_order_line
=
tmp_sale_order
.
newContent
(
portal_type
=
'Sale Order Line'
,
temp_object
=
True
,
resource_value
=
service
,
variation_category_list
=
resource_vcl
,
quantity_unit
=
service
.
getQuantityUnit
(),
base_contribution_list
=
service
.
getBaseContributionList
(),
use
=
service
.
getUse
(),
quantity
=
1
)
if
resource_vcl
:
base_id
=
'movement'
cell_key
=
list
(
tmp_order_line
.
getCellKeyList
(
base_id
=
base_id
))[
0
]
tmp_order_cell
=
tmp_order_line
.
newCell
(
base_id
=
base_id
,
portal_type
=
'Sale Order Cell'
,
temp_object
=
True
,
*
cell_key
)
tmp_order_cell
.
edit
(
mapped_value_property_list
=
[
'price'
,
'quantity'
],
quantity
=
1
,
predicate_category_list
=
cell_key
,
variation_category_list
=
cell_key
)
price
=
tmp_order_cell
.
getPrice
(
0
)
else
:
price
=
tmp_order_line
.
getPrice
(
0
)
if
not
price
:
storeWorkflowComment
(
item
,
'Can not find a price to generate the Subscription Request'
)
return
# Prevent concurrent transactions which could create the Subscription Request
item
.
serialize
()
subscription_request
=
portal
.
subscription_request_module
.
newContent
(
portal_type
=
'Subscription Request'
,
source_value
=
source_decision_value
,
source_section_value
=
source_section_value
,
source_decision_value
=
source_decision_value
,
start_date
=
now
,
effective_date
=
now
,
resource_value
=
service
,
variation_category_list
=
resource_vcl
,
aggregate_value
=
item
,
quantity_unit
=
tmp_order_line
.
getQuantityUnit
(),
quantity
=
1
,
ledger
=
"automated"
,
specialise_value
=
tmp_sale_order
.
getSpecialiseValue
(),
destination
=
tmp_sale_order
.
getSource
(),
destination_section
=
tmp_sale_order
.
getSourceSection
(),
price_currency
=
tmp_sale_order
.
getPriceCurrency
(),
price
=
price
,
)
subscription_request
.
submit
()
if
len
(
subscription_request
.
checkConsistency
())
!=
0
:
raise
NotImplementedError
(
subscription_request
.
checkConsistency
())
return
subscription_request
master/bt5/slapos_subscription_request/SkinTemplateItem/portal_skins/slapos_subscription_request/Item_createSubscriptionRequest.xml
0 → 100644
View file @
1b159fab
<?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>
REQUEST=None
</string>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
<value>
<string>
Item_createSubscriptionRequest
</string>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
master/bt5/slapos_subscription_request/bt/template_path_list
View file @
1b159fab
...
...
@@ -6,6 +6,7 @@ accounting_module/template_pre_payment_subscription_sale_invoice_transaction
accounting_module/template_pre_payment_subscription_sale_invoice_transaction/**
accounting_module/template_wechat_pre_payment_subscription_sale_invoice_transaction
accounting_module/template_wechat_pre_payment_subscription_sale_invoice_transaction/**
portal_alarms/slapos_subscription_request_create_from_orphaned_item
portal_alarms/slapos_subscription_request_process_**
portal_alarms/slapos_update_subscription_request_consistency_state
service_module/slapos_reservation_fee_2
service_module/slapos_reservation_fee_2
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment