Commit 31324c9f authored by Romain Courteaud's avatar Romain Courteaud

slapos_*: let's try to extend the list of trade condition search

parent dd5bac43
......@@ -9,8 +9,8 @@ root_trade_condition_uid_list = [
trade_condition_uid_list.extend(root_trade_condition_uid_list)
trade_condition_uid_list.extend([
i.uid for i in portal.portal_catalog(
specialise__uid=root_trade_condition_uid_list,
i.uid for i in portal.ERP5Site_searchRelatedInheritedSpecialiseList(
specialise_uid=root_trade_condition_uid_list,
validation_state="validated")])
portal.portal_catalog.searchAndActivate(
......
......@@ -16,11 +16,18 @@ def getAccountingDate(accounting_date):
accounting_date = params.get('accounting_date', DateTime().earliestTime())
portal = context.getPortalObject()
trade_condition_uid_list = [portal.restrictedTraverse(portal.portal_preferences.getPreferredAggregatedSaleTradeCondition()).getUid()]
trade_condition_uid_list.extend([
i.uid for i in portal.ERP5Site_searchRelatedInheritedSpecialiseList(
specialise_uid=trade_condition_uid_list,
validation_state="validated")])
portal.portal_catalog.searchAndActivate(
portal_type='Sale Packing List',
simulation_state='confirmed',
causality_state='solved',
specialise_uid=portal.restrictedTraverse(portal.portal_preferences.getPreferredAggregatedSaleTradeCondition()).getUid(),
specialise_uid=trade_condition_uid_list,
method_id='Delivery_startConfirmedAggregatedSalePackingList',
activate_kw={'tag': tag},
**{'delivery.start_date': Query(range="max",
......
......@@ -12,9 +12,9 @@ root_trade_condition_uid = root_trade_condition_value.getUid()
trade_condition_uid_list.append(root_trade_condition_uid)
trade_condition_uid_list.extend([
i.uid for i in portal.portal_catalog(
i.uid for i in portal.ERP5Site_searchRelatedInheritedSpecialiseList(
portal_type=root_trade_condition_value.getPortalType(),
specialise__uid=root_trade_condition_uid,
specialise_uid=root_trade_condition_uid,
validation_state="validated")])
portal.portal_catalog.searchAndActivate(
......
......@@ -12,9 +12,9 @@ root_trade_condition_uid_list = [
trade_condition_uid_list.extend(root_trade_condition_uid_list)
trade_condition_uid_list.extend([
i.uid for i in portal.portal_catalog(
i.uid for i in portal.ERP5Site_searchRelatedInheritedSpecialiseList(
portal_type="Sale Trade Condition",
specialise__uid=root_trade_condition_uid_list,
specialise_uid=root_trade_condition_uid_list,
validation_state="validated")])
portal.portal_catalog.searchAndActivate(
......
......@@ -13,7 +13,7 @@ specialise_uid = [
]
return context.getSpecialiseUid() in [
i.uid for i in portal.portal_catalog(
i.uid for i in portal.ERP5Site_searchRelatedInheritedSpecialiseList(
portal_type="Sale Trade Condition",
specialise__uid=specialise_uid,
specialise_uid=specialise_uid,
validation_state="validated")]
......@@ -21,8 +21,8 @@ if context.getSimulationState() == 'started' \
trade_condition_uid_list.extend(root_trade_condition_uid_list)
trade_condition_uid_list.extend([
i.uid for i in portal.portal_catalog(
specialise__uid=root_trade_condition_uid_list,
i.uid for i in portal.ERP5Site_searchRelatedInheritedSpecialiseList(
specialise_uid=root_trade_condition_uid_list,
validation_state="validated")])
if context.getSpecialiseUid() not in trade_condition_uid_list:
......
......@@ -24,8 +24,8 @@ if context.getSimulationState() == 'confirmed' \
trade_condition_uid_list.extend(root_trade_condition_uid_list)
trade_condition_uid_list.extend([
i.uid for i in portal.portal_catalog(
specialise__uid=root_trade_condition_uid_list,
i.uid for i in portal.ERP5Site_searchRelatedInheritedSpecialiseList(
specialise_uid=root_trade_condition_uid_list,
validation_state="validated")])
if context.getSpecialiseUid() not in trade_condition_uid_list:
......
......@@ -21,9 +21,9 @@ if context.getSimulationState() == 'confirmed'\
trade_condition_uid_list.extend(root_trade_condition_uid_list)
trade_condition_uid_list.extend([
i.uid for i in portal.portal_catalog(
i.uid for i in portal.ERP5Site_searchRelatedInheritedSpecialiseList(
portal_type="Sale Trade Condition",
specialise__uid=root_trade_condition_uid_list,
specialise_uid=root_trade_condition_uid_list,
validation_state="validated")])
if context.getSpecialiseUid() not in trade_condition_uid_list:
......
portal = context
result_list = []
if specialise_uid is None:
current_uid_list = []
elif same_type(specialise_uid, []) or same_type(specialise_uid, ()):
current_uid_list = list(specialise_uid)
else:
current_uid_list = [specialise_uid]
search_kw = {}
if portal_type is not None:
search_kw['portal_type'] = portal_type
if validation_state is not None:
search_kw['validation_state'] = validation_state
if destination_section__uid is not None:
search_kw['destination_section__uid'] = destination_section__uid
# This is REALLY INEFFICIENT.
# Keep it simple for now, as the goal is probably to drop all this script usage
while (current_uid_list):
specialise__uid = current_uid_list
current_uid_list = []
for sql_result in portal.portal_catalog(
specialise__uid=specialise__uid,
**search_kw
):
current_uid_list.append(sql_result.uid)
result_list.append(sql_result)
return result_list
<?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>_params</string> </key>
<value> <string>specialise_uid, portal_type=None, validation_state=None, destination_section__uid=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_searchRelatedInheritedSpecialiseList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -35,6 +35,7 @@ def newOpenOrder():
return new_open_sale_order
if instance_tree.getCausalityState() == 'diverged':
open_order = None
person = instance_tree.getDestinationSectionValue(portal_type="Person")
# Template document does not have person relation
if person is not None:
......
......@@ -10,10 +10,10 @@ business_process_uid_list = [
portal.business_process_module.slapos_reservation_refound_business_process.getUid(),
portal.business_process_module.slapos_subscription_business_process.getUid()]
specialise_uid_list = [q.getUid() for q in portal.portal_catalog(
specialise_uid_list = [q.getUid() for q in portal.ERP5Site_searchRelatedInheritedSpecialiseList(
specialise_uid=business_process_uid_list, portal_type='Sale Trade Condition')]
consumption_specialise_uid_list = [q.getUid() for q in portal.portal_catalog(
consumption_specialise_uid_list = [q.getUid() for q in portal.ERP5Site_searchRelatedInheritedSpecialiseList(
specialise_uid=portal.business_process_module.slapos_consumption_business_process.getUid(),
portal_type='Sale Trade Condition')]
......
......@@ -19,7 +19,7 @@ def newPackingList(movement, causality, message):
delivery.confirm(message)
return delivery
consumption_specialise_uid_list = [q.getUid() for q in portal.portal_catalog(
consumption_specialise_uid_list = [q.getUid() for q in portal.ERP5Site_searchRelatedInheritedSpecialiseList(
specialise_uid=portal.business_process_module.slapos_consumption_business_process.getUid(),
portal_type='Sale Trade Condition')]
......
......@@ -8,12 +8,18 @@ if root_trade_condition is None:
root_trade_condition_value = portal.restrictedTraverse(root_trade_condition)
trade_condition = portal.portal_catalog.getResultValue(
trade_condition = portal.portal_catalog.ERP5Site_searchRelatedInheritedSpecialiseList(
portal_type=root_trade_condition_value.getPortalType(),
specialise__uid=root_trade_condition_value.getUid(),
specialise_uid=root_trade_condition_value.getUid(),
validation_state=root_trade_condition_value.getValidationState(),
destination_section__uid=context.getUid()
)
if len(trade_condition) == 1:
trade_condition = trade_condition[0].getObject()
elif len(trade_condition) == 0:
trade_condition = None
else:
raise NotImplementedError('Too many trade aggregated subscription trade condition for %s' % context.getRelativeUrl())
if trade_condition is not None:
return trade_condition.getRelativeUrl()
......
......@@ -4,7 +4,7 @@ portal = context.getPortalObject()
business_process_uid_list = [
portal.business_process_module.slapos_subscription_business_process.getUid()]
subscription_delivery_specialise_uid_list = [q.getUid() for q in portal.portal_catalog(
subscription_delivery_specialise_uid_list = [q.getUid() for q in portal.ERP5Site_searchRelatedInheritedSpecialiseList(
specialise_uid=business_process_uid_list, portal_type='Sale Trade Condition')]
search_kw = {
......
......@@ -5,27 +5,26 @@ restrictedTraverse = portal.restrictedTraverse
person = context.getDestination()
reference = context.getReference()
business_process_uid_list = [
portal.business_process_module.slapos_reservation_refound_business_process.getUid(),
portal.business_process_module.slapos_subscription_business_process.getUid()]
business_process_list = [
portal.business_process_module.slapos_reservation_refound_business_process,
portal.business_process_module.slapos_subscription_business_process]
business_process_uid_list = [x.getUid() for x in business_process_list]
specialise_list = [q.getRelativeUrl() for q in portal.portal_catalog(
specialise_list = [q.getRelativeUrl() for q in portal.ERP5Site_searchRelatedInheritedSpecialiseList(
specialise_uid=business_process_uid_list, portal_type='Sale Trade Condition')]
consumption_specialise_list = [q.getRelativeUrl() for q in portal.portal_catalog(
consumption_specialise_list = [q.getRelativeUrl() for q in portal.ERP5Site_searchRelatedInheritedSpecialiseList(
specialise_uid=portal.business_process_module.slapos_consumption_business_process.getUid(),
portal_type='Sale Trade Condition')]
subscription_request_specialise = portal.portal_preferences.getPreferredAggregatedSubscriptionSaleTradeCondition()
consumption_specialise = portal.portal_preferences.getPreferredAggregatedConsumptionSaleTradeCondition()
trade_condition = context.getSpecialise()
specialise_filter_list = consumption_specialise_list + specialise_list
if trade_condition == consumption_specialise:
if trade_condition in consumption_specialise_list:
specialise_filter_list = consumption_specialise_list
elif trade_condition == subscription_request_specialise:
elif trade_condition in specialise_list:
specialise_filter_list = specialise_list
else:
specialise_filter_list = consumption_specialise_list + specialise_list
def test_for_subscription(movement, causality):
instance_tree = movement.getAggregateValue(portal_type="Instance Tree")
......
......@@ -594,9 +594,15 @@ class DefaultScenarioMixin(TestSlapOSSecurityMixin):
aggregated_delivery_list = self.portal.portal_catalog(
portal_type='Sale Packing List',
default_destination_section_uid=person.getUid(),
specialise_uid=self.portal.restrictedTraverse(self.portal\
specialise_uid=[self.portal.restrictedTraverse(self.portal\
.portal_preferences.getPreferredAggregatedSaleTradeCondition()\
).getUid()
] + [
i.uid for i in self.portal.ERP5Site_searchRelatedInheritedSpecialiseList(
specialise_uid=self.portal.restrictedTraverse(self.portal
.portal_preferences.getPreferredAggregatedSaleTradeCondition()
).getUid())
]
)
if len(subscription_list) == 0:
......
......@@ -10,7 +10,7 @@ else:
business_process_uid_list = [
portal.business_process_module.slapos_subscription_business_process.getUid()]
subscription_delivery_specialise_uid_list = [q.getUid() for q in portal.portal_catalog(
subscription_delivery_specialise_uid_list = [q.getUid() for q in portal.ERP5Site_searchRelatedInheritedSpecialiseList(
specialise_uid=business_process_uid_list, portal_type='Sale Trade Condition')]
# Recover all Aggregated Sale Packing Lists
......
......@@ -12,9 +12,9 @@ specialise_uid = portal.restrictedTraverse(
trade_condition_uid_list = [specialise_uid]
trade_condition_uid_list.extend([
i.uid for i in portal.portal_catalog(
i.uid for i in portal.ERP5Site_searchRelatedInheritedSpecialiseList(
portal_type="Sale Trade Condition",
specialise__uid=specialise_uid,
specialise_uid=specialise_uid,
validation_state="validated")])
# This is normally one, but we navegate in case
......
......@@ -1167,6 +1167,10 @@ return dict(vads_url_already_registered="%s/already_registered" % (payment_trans
person_uid = subscription_request.getDestinationSectionValue().getUid()
specialise_uid = self.portal.restrictedTraverse(
"sale_trade_condition_module/slapos_subscription_trade_condition").getUid()
specialise_uid = [specialise_uid] + [
i.uid for i in self.portal.ERP5Site_searchRelatedInheritedSpecialiseList(
specialise_uid=specialise_uid)
]
return self.portal.portal_catalog(
portal_type='Sale Packing List',
......
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