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
0
Merge Requests
0
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
Titouan Soulard
slapos.core
Commits
c00ff151
Commit
c00ff151
authored
Apr 11, 2023
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos_subscription_request: create Subscription Requuest manually from a resource
parent
bc3e5d52
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
179 additions
and
102 deletions
+179
-102
master/bt5/slapos_subscription_request/SkinTemplateItem/portal_skins/slapos_subscription_request/Item_createSubscriptionRequest.py
...os_subscription_request/Item_createSubscriptionRequest.py
+5
-102
master/bt5/slapos_subscription_request/SkinTemplateItem/portal_skins/slapos_subscription_request/Resource_createSubscriptionRequest.py
...ubscription_request/Resource_createSubscriptionRequest.py
+112
-0
master/bt5/slapos_subscription_request/SkinTemplateItem/portal_skins/slapos_subscription_request/Resource_createSubscriptionRequest.xml
...bscription_request/Resource_createSubscriptionRequest.xml
+62
-0
No files found.
master/bt5/slapos_subscription_request/SkinTemplateItem/portal_skins/slapos_subscription_request/Item_createSubscriptionRequest.py
View file @
c00ff151
...
...
@@ -30,12 +30,10 @@ if subscription_request is not None:
# 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
(),
...
...
@@ -54,107 +52,12 @@ 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'
)
try
:
subscription_request
=
service
.
Resource_createSubscriptionRequest
(
source_decision_value
,
resource_vcl
)
except
AssertionError
,
error
:
storeWorkflowComment
(
item
,
str
(
error
))
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
subscription_request
.
setAggregateValue
(
item
)
# 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
,
activate_kw
=
activate_kw
)
subscription_request
.
submit
()
if
len
(
subscription_request
.
checkConsistency
())
!=
0
:
raise
NotImplementedError
(
subscription_request
.
checkConsistency
())
subscription_request
.
SubscriptionRequest_createOpenSaleOrder
()
subscription_request
.
validate
()
return
subscription_request
master/bt5/slapos_subscription_request/SkinTemplateItem/portal_skins/slapos_subscription_request/Resource_createSubscriptionRequest.py
0 → 100644
View file @
c00ff151
portal
=
context
.
getPortalObject
()
resource
=
context
if
subscriber_person_value
is
None
:
raise
AssertionError
(
'Can not find a person profile'
)
project_value
=
None
if
resource
.
getPortalType
()
==
"Software Product"
:
project_value
=
resource
.
getFollowUpValue
(
portal_type
=
"Project"
)
elif
resource
.
getPortalType
()
==
"Service"
:
if
resource
.
getRelativeUrl
()
!=
"service_module/slapos_virtual_master_subscription"
:
raise
NotImplementedError
(
'Unsupported resource: %s'
%
resource
.
getRelativeUrl
())
else
:
raise
NotImplementedError
(
'Unsupported resource: %s'
%
resource
.
getRelativeUrl
())
######################################################
# Find Sale Trade Condition and price
source_section
=
subscriber_person_value
.
getCareerSubordination
(
subscriber_person_value
.
getRelativeUrl
())
# Create a temp Sale Order to calculate the real price and find the trade condition
now
=
DateTime
()
module
=
portal
.
portal_trash
#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
=
subscriber_person_value
,
destination_section
=
source_section
,
#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
:
raise
AssertionError
(
'Can not find a trade condition to generate the Subscription Request'
)
# If no accounting is needed, no need to check the price
if
(
tmp_sale_order
.
getSourceSection
(
None
)
==
tmp_sale_order
.
getDestinationSection
(
None
))
or
\
(
tmp_sale_order
.
getSourceSection
(
None
)
is
None
):
price
=
0
else
:
# Add line
tmp_order_line
=
tmp_sale_order
.
newContent
(
portal_type
=
'Sale Order Line'
,
temp_object
=
True
,
resource_value
=
resource
,
variation_category_list
=
variation_category_list
,
quantity_unit
=
resource
.
getQuantityUnit
(),
base_contribution_list
=
resource
.
getBaseContributionList
(),
use
=
resource
.
getUse
(),
quantity
=
1
)
if
0
:
# XXX 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
:
raise
AssertionError
(
'Can not find a price to generate the Subscription Request'
)
subscription_request
=
portal
.
subscription_request_module
.
newContent
(
portal_type
=
'Subscription Request'
,
source_value
=
subscriber_person_value
,
source_section_value
=
source_section
,
source_decision_value
=
subscriber_person_value
,
start_date
=
now
,
effective_date
=
now
,
resource_value
=
resource
,
variation_category_list
=
variation_category_list
,
# XXX aggregate_value=item,
quantity_unit
=
resource
.
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
,
# XXX activate_kw=activate_kw
)
"""
if len(subscription_request.checkConsistency()) != 0:
raise NotImplementedError(subscription_request.checkConsistency())
"""
subscription_request
.
submit
()
return
subscription_request
master/bt5/slapos_subscription_request/SkinTemplateItem/portal_skins/slapos_subscription_request/Resource_createSubscriptionRequest.xml
0 → 100644
View file @
c00ff151
<?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>
subscriber_person_value, variation_category_list
</string>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
<value>
<string>
Resource_createSubscriptionRequest
</string>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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