Commit a50f389b authored by Rafael Monnerat's avatar Rafael Monnerat Committed by Alain Takoudjou

slapos_accounting: Use a specific trade condition to SPL from Consumption

This is only for when subscription request is present, as consumption is normally irrelevant from accounting point of view.

This preserves the previous approach from non-subscriptions hosting subscriptions.
parent 615ec1d0
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Sale Trade Condition" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Access_contents_information_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Author</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Add_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Author</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Author</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>_View_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Author</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>_count</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>_identity_criterion</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>_mt_index</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>_range_criterion</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAU=</string> </persistent>
</value>
</item>
<item>
<key> <string>_tree</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAY=</string> </persistent>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>specialise/business_process_module/slapos_aggregated_business_process</string>
</tuple>
</value>
</item>
<item>
<key> <string>comment</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>slapos_aggregated_consumption_trade_condition</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>slapos_aggregated_consumption_trade_condition</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Sale Trade Condition</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>SlapOS Aggregated Consumption Trade Condition</string> </value>
</item>
<item>
<key> <string>version</string> </key>
<value>
<none/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Length" module="BTrees.Length"/>
</pickle>
<pickle> <int>0</int> </pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="OOBTree" module="BTrees.OOBTree"/>
</pickle>
<pickle>
<none/>
</pickle>
</record>
<record id="5" aka="AAAAAAAAAAU=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>start_date</string> </key>
<value>
<tuple>
<none/>
<none/>
</tuple>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="6" aka="AAAAAAAAAAY=">
<pickle>
<global name="OOBTree" module="BTrees.OOBTree"/>
</pickle>
<pickle>
<none/>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Trade Model Line" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_identity_criterion</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>_range_criterion</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>resource/service_module/slapos_tax</string>
<string>base_application/base_amount/invoicing/taxable</string>
<string>trade_phase/slapos/tax</string>
</tuple>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>VAT</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>1</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Trade Model Line</string> </value>
</item>
<item>
<key> <string>price</string> </key>
<value> <float>0.2</float> </value>
</item>
<item>
<key> <string>quantity</string> </key>
<value> <float>1.0</float> </value>
</item>
<item>
<key> <string>target_delivery</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>VAT</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Standard Property" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>elementary_type/string</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>preferred_aggregated_consumption_sale_trade_condition_property</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Standard Property</string> </value>
</item>
<item>
<key> <string>preference</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>write_permission</string> </key>
<value> <string>Manage properties</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -6,19 +6,23 @@ from Products.ZSQLCatalog.SQLCatalog import Query, NegatedQuery, ComplexQuery ...@@ -6,19 +6,23 @@ from Products.ZSQLCatalog.SQLCatalog import Query, NegatedQuery, ComplexQuery
portal = context.getPortalObject() portal = context.getPortalObject()
business_process_uid_list = [ business_process_uid_list = [
portal.business_process_module.slapos_consumption_business_process.getUid(),
portal.business_process_module.slapos_reservation_refound_business_process.getUid(), portal.business_process_module.slapos_reservation_refound_business_process.getUid(),
portal.business_process_module.slapos_subscription_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.portal_catalog(
specialise_uid=business_process_uid_list, portal_type='Sale Trade Condition')] specialise_uid=business_process_uid_list, portal_type='Sale Trade Condition')]
consumption_specialise_uid_list = [q.getUid() for q in portal.portal_catalog(
specialise_uid=portal.business_process_module.slapos_consumption_business_process.getUid(),
portal_type='Sale Trade Condition')]
select_dict= {'default_aggregate_portal_type': None} select_dict= {'default_aggregate_portal_type': None}
select_kw.update( select_kw.update(
limit=10000, # just take a bit limit=10, # just take a bit
portal_type='Sale Packing List Line', portal_type='Sale Packing List Line',
simulation_state='delivered', simulation_state='delivered',
parent_specialise_uid=specialise_uid_list, parent_specialise_uid=specialise_uid_list+consumption_specialise_uid_list,
select_dict=select_dict, select_dict=select_dict,
left_join_list=select_dict.keys(), left_join_list=select_dict.keys(),
default_aggregate_portal_type=ComplexQuery(NegatedQuery(Query(default_aggregate_portal_type='Computer')), default_aggregate_portal_type=ComplexQuery(NegatedQuery(Query(default_aggregate_portal_type='Computer')),
...@@ -30,6 +34,8 @@ movement_list = portal.portal_catalog(**select_kw) ...@@ -30,6 +34,8 @@ movement_list = portal.portal_catalog(**select_kw)
specialise = portal.portal_preferences.getPreferredAggregatedSaleTradeCondition() specialise = portal.portal_preferences.getPreferredAggregatedSaleTradeCondition()
subscription_request_specialise = portal.portal_preferences.getPreferredAggregatedSubscriptionSaleTradeCondition() subscription_request_specialise = portal.portal_preferences.getPreferredAggregatedSubscriptionSaleTradeCondition()
consumption_specialise = portal.portal_preferences.getPreferredAggregatedConsumptionSaleTradeCondition()
temp_movement_list = [] temp_movement_list = []
for movement in movement_list: for movement in movement_list:
if movement.getGroupingReference() is not None: if movement.getGroupingReference() is not None:
...@@ -46,6 +52,8 @@ for movement in movement_list: ...@@ -46,6 +52,8 @@ for movement in movement_list:
specialise=specialise, specialise=specialise,
price_currency=movement.getPriceCurrency() price_currency=movement.getPriceCurrency()
) )
# XXX Shamefully hardcoded values
if movement.getResource() == 'service_module/slapos_instance_subscription': if movement.getResource() == 'service_module/slapos_instance_subscription':
# reduce tax from there directly # reduce tax from there directly
temp_movement.edit(price=movement.getPrice(0.0)/1.2) temp_movement.edit(price=movement.getPrice(0.0)/1.2)
...@@ -55,16 +63,21 @@ for movement in movement_list: ...@@ -55,16 +63,21 @@ for movement in movement_list:
temp_movement.edit(price=0.0) temp_movement.edit(price=0.0)
hosting_subscription = movement.getAggregateValue(portal_type="Hosting Subscription") hosting_subscription = movement.getAggregateValue(portal_type="Hosting Subscription")
specialise_to_set = subscription_request_specialise
if movement.getSpecialiseUid() in consumption_specialise_uid_list:
specialise_to_set = consumption_specialise
if hosting_subscription is not None: if hosting_subscription is not None:
subscription = hosting_subscription.getAggregateRelated(portal_type="Subscription Request") subscription = hosting_subscription.getAggregateRelated(portal_type="Subscription Request")
if subscription is not None: if subscription is not None:
temp_movement.edit( temp_movement.edit(
specialise=subscription_request_specialise, specialise=specialise_to_set,
causality=subscription) causality=subscription)
elif movement.getCausality(portal_type="Subscription Request") is not None: elif movement.getCausality(portal_type="Subscription Request") is not None:
temp_movement.edit( temp_movement.edit(
specialise=subscription_request_specialise, specialise=specialise_to_set,
causality=movement.getCausality(portal_type="Subscription Request")) causality=movement.getCausality(portal_type="Subscription Request"))
temp_movement_list.append(temp_movement) temp_movement_list.append(temp_movement)
......
...@@ -70,6 +70,8 @@ portal_solvers/Automatic Quantity Adopt Solver/** ...@@ -70,6 +70,8 @@ portal_solvers/Automatic Quantity Adopt Solver/**
sale_packing_list_module/slapos_accounting_instance_delivery_line_template sale_packing_list_module/slapos_accounting_instance_delivery_line_template
sale_packing_list_module/slapos_accounting_instance_delivery_line_template/** sale_packing_list_module/slapos_accounting_instance_delivery_line_template/**
sale_packing_list_module/slapos_accounting_instance_delivery_template sale_packing_list_module/slapos_accounting_instance_delivery_template
sale_trade_condition_module/slapos_aggregated_consumption_trade_condition
sale_trade_condition_module/slapos_aggregated_consumption_trade_condition/**
sale_trade_condition_module/slapos_aggregated_subscription_trade_condition sale_trade_condition_module/slapos_aggregated_subscription_trade_condition
sale_trade_condition_module/slapos_aggregated_subscription_trade_condition/** sale_trade_condition_module/slapos_aggregated_subscription_trade_condition/**
sale_trade_condition_module/slapos_aggregated_trade_condition sale_trade_condition_module/slapos_aggregated_trade_condition
......
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