Commit a755b923 authored by Romain Courteaud's avatar Romain Courteaud

Restore computer consumption report functionnality.

parent e1e0f54a
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ActionInformation" module="Products.CMFCore.ActionInformation"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>action</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/object_exchange</string>
</tuple>
</value>
</item>
<item>
<key> <string>category</string> </key>
<value> <string>object_exchange</string> </value>
</item>
<item>
<key> <string>condition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>icon</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>download</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
<value>
<tuple>
<string>View</string>
</tuple>
</value>
</item>
<item>
<key> <string>priority</string> </key>
<value> <float>3.0</float> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Download</string> </value>
</item>
<item>
<key> <string>visible</string> </key>
<value> <int>1</int> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Expression" module="Products.CMFCore.Expression"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>string:${object_url}/Base_download</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ActionInformation" module="Products.CMFCore.ActionInformation"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>action</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/object_view</string>
</tuple>
</value>
</item>
<item>
<key> <string>category</string> </key>
<value> <string>object_view</string> </value>
</item>
<item>
<key> <string>condition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>icon</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>view</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
<value>
<tuple>
<string>View</string>
</tuple>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Action Information</string> </value>
</item>
<item>
<key> <string>priority</string> </key>
<value> <float>1.0</float> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>View</string> </value>
</item>
<item>
<key> <string>visible</string> </key>
<value> <int>1</int> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Expression" module="Products.CMFCore.Expression"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>string:${object_url}/File_view</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ActionInformation" module="Products.CMFCore.ActionInformation"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>action</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/object_list</string>
</tuple>
</value>
</item>
<item>
<key> <string>category</string> </key>
<value> <string>object_list</string> </value>
</item>
<item>
<key> <string>condition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>icon</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>view</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
<value>
<tuple>
<string>View</string>
</tuple>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Action Information</string> </value>
</item>
<item>
<key> <string>priority</string> </key>
<value> <float>1.0</float> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>View</string> </value>
</item>
<item>
<key> <string>visible</string> </key>
<value> <int>1</int> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Expression" module="Products.CMFCore.Expression"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>string:${object_url}/ConsumptionDocumentModule_viewDocumentList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
###############################################################################
#
# Copyright (c) 2002-2013 Nexedi SA and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
##############################################################################
from lxml import etree
from zExceptions import Unauthorized
import pkg_resources
import StringIO
def ComputerConsumptionTioXMLFile_parseXml(self, REQUEST=None):
"""Call bang on self."""
if REQUEST is not None:
raise Unauthorized
xml = self.getData("")
computer_consumption_model = \
pkg_resources.resource_string(
'slapos.slap', 'doc/computer_consumption.xsd')
# Validate against the xsd
xsd_model = StringIO.StringIO(computer_consumption_model)
xmlschema_doc = etree.parse(xsd_model)
xmlschema = etree.XMLSchema(xmlschema_doc)
string_to_validate = StringIO.StringIO(xml)
try:
tree = etree.parse(string_to_validate)
except (etree.XMLSyntaxError, etree.DocumentInvalid) as e:
return None
if not xmlschema.validate(tree):
return None
# Get the title
title = \
tree.find('transaction').find('title').text or ""
title = title.encode("UTF-8")
movement_list = []
for movement in tree.find('transaction').findall('movement'):
movement_list.append({
'resource': (movement.find('resource').text or "").encode("UTF-8"),
'title': (movement.find('title').text or "").encode("UTF-8"),
'reference': (movement.find('reference').text or "").encode("UTF-8"),
'quantity': float(movement.find('quantity').text or "0"),
'category': (movement.find('category').text or "").encode("UTF-8"),
})
return {
'title': title,
'movement': movement_list,
}
<module>
<id>consumption_document_module</id>
<permission_list>
<permission type='tuple'>
<name>Access Transient Objects</name>
<role>Assignee</role>
<role>Assignor</role>
<role>Associate</role>
<role>Auditor</role>
<role>Author</role>
<role>Manager</role>
</permission>
<permission type='tuple'>
<name>Access contents information</name>
<role>Assignee</role>
<role>Assignor</role>
<role>Associate</role>
<role>Auditor</role>
<role>Author</role>
<role>Manager</role>
</permission>
<permission type='tuple'>
<name>Access session data</name>
<role>Assignee</role>
<role>Assignor</role>
<role>Associate</role>
<role>Auditor</role>
<role>Author</role>
<role>Manager</role>
</permission>
<permission type='tuple'>
<name>Add portal content</name>
<role>Assignor</role>
<role>Author</role>
<role>Manager</role>
</permission>
<permission type='tuple'>
<name>Add portal folders</name>
<role>Assignor</role>
<role>Author</role>
<role>Manager</role>
</permission>
<permission type='tuple'>
<name>Change local roles</name>
<role>Assignor</role>
<role>Manager</role>
</permission>
<permission type='tuple'>
<name>Copy or Move</name>
<role>Assignee</role>
<role>Assignor</role>
<role>Associate</role>
<role>Auditor</role>
<role>Author</role>
<role>Manager</role>
</permission>
<permission type='tuple'>
<name>Delete objects</name>
<role>Assignor</role>
<role>Manager</role>
</permission>
<permission type='tuple'>
<name>List folder contents</name>
<role>Assignee</role>
<role>Assignor</role>
<role>Associate</role>
<role>Auditor</role>
<role>Author</role>
<role>Manager</role>
</permission>
<permission type='tuple'>
<name>Modify portal content</name>
<role>Assignor</role>
<role>Manager</role>
</permission>
<permission type='tuple'>
<name>View</name>
<role>Assignee</role>
<role>Assignor</role>
<role>Associate</role>
<role>Auditor</role>
<role>Manager</role>
</permission>
<permission type='tuple'>
<name>View History</name>
<role>Assignee</role>
<role>Assignor</role>
<role>Associate</role>
<role>Auditor</role>
<role>Author</role>
<role>Manager</role>
</permission>
</permission_list>
<portal_type>Consumption Document Module</portal_type>
<title>Consumption Documents</title>
</module>
\ No newline at end of file
<?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_searchSubmittedConsumptionTioXMLFileList</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>slapos_accounting_generate_packing_list_from_tioxml</string> </value>
</item>
<item>
<key> <string>periodicity_day_frequency</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>periodicity_hour</string> </key>
<value>
<tuple>
<int>2</int>
</tuple>
</value>
</item>
<item>
<key> <string>periodicity_hour_frequency</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>periodicity_minute</string> </key>
<value>
<tuple>
<int>0</int>
</tuple>
</value>
</item>
<item>
<key> <string>periodicity_minute_frequency</string> </key>
<value>
<none/>
</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>0.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>Generate Packing List from TioXML</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
</item> </item>
<item> <item>
<key> <string>enabled</string> </key> <key> <string>enabled</string> </key>
<value> <int>1</int> </value> <value> <int>0</int> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
<allowed_content_type_list> <allowed_content_type_list>
<portal_type id="Consumption Document Module">
<item>Computer Consumption TioXML File</item>
</portal_type>
<portal_type id="Order Tool"> <portal_type id="Order Tool">
<item>SlapOS Accounting Quantity Updating Order Builder</item> <item>SlapOS Accounting Quantity Updating Order Builder</item>
</portal_type> </portal_type>
......
<base_category_list> <base_category_list>
<portal_type id="Consumption Document Module">
<item>business_application</item>
</portal_type>
<portal_type id="Slave Instance"> <portal_type id="Slave Instance">
<item>causality</item> <item>causality</item>
</portal_type> </portal_type>
......
<hidden_content_type_list>
<portal_type id="Consumption Document Module">
<item>Computer Consumption TioXML File</item>
</portal_type>
</hidden_content_type_list>
\ No newline at end of file
<property_sheet_list> <property_sheet_list>
<portal_type id="Computer Consumption TioXML File">
<item>SortIndex</item>
</portal_type>
<portal_type id="Hosting Subscription"> <portal_type id="Hosting Subscription">
<item>SlapOSAccountingHostingSubscriptionConstraint</item> <item>SlapOSAccountingHostingSubscriptionConstraint</item>
</portal_type> </portal_type>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Base Type" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>content_icon</string> </key>
<value> <string>file_icon.png</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>factory</string> </key>
<value> <string>addXMLObject</string> </value>
</item>
<item>
<key> <string>group_list</string> </key>
<value>
<tuple>
<string>document</string>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Computer Consumption TioXML File</string> </value>
</item>
<item>
<key> <string>init_script</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>permission</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Base Type</string> </value>
</item>
<item>
<key> <string>searchable_text_method_id</string> </key>
<value>
<tuple>
<string>as_text</string>
</tuple>
</value>
</item>
<item>
<key> <string>searchable_text_property_id</string> </key>
<value>
<tuple>
<string>title</string>
<string>description</string>
<string>reference</string>
<string>version</string>
<string>short_title</string>
<string>subject_list</string>
<string>filename</string>
<string>source_project_title</string>
</tuple>
</value>
</item>
<item>
<key> <string>type_class</string> </key>
<value> <string>File</string> </value>
</item>
<item>
<key> <string>type_interface</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>type_mixin</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Base Type" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_property_domain_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>content_icon</string> </key>
<value> <string>folder_icon.gif</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>factory</string> </key>
<value> <string>addFolder</string> </value>
</item>
<item>
<key> <string>group_list</string> </key>
<value>
<tuple>
<string>module</string>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Consumption Document Module</string> </value>
</item>
<item>
<key> <string>init_script</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>permission</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Base Type</string> </value>
</item>
<item>
<key> <string>type_class</string> </key>
<value> <string>Folder</string> </value>
</item>
<item>
<key> <string>type_interface</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>type_mixin</string> </key>
<value>
<tuple/>
</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>
<item>
<key> <string>short_title</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="TranslationInformation" module="Products.ERP5Type.TranslationProviderBase"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>domain_name</string> </key>
<value> <string>erp5_ui</string> </value>
</item>
<item>
<key> <string>property_name</string> </key>
<value> <string>short_title</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="TranslationInformation" module="Products.ERP5Type.TranslationProviderBase"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>domain_name</string> </key>
<value> <string>erp5_ui</string> </value>
</item>
<item>
<key> <string>property_name</string> </key>
<value> <string>title</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<workflow_chain> <workflow_chain>
<chain>
<type>Computer Consumption TioXML File</type>
<workflow>document_conversion_interaction_workflow, document_publication_workflow, edit_workflow</workflow>
</chain>
<chain> <chain>
<type>Hosting Subscription</type> <type>Hosting Subscription</type>
<workflow>slapos_accounting_interaction_workflow, slapos_api_invoicing_workflow</workflow> <workflow>slapos_accounting_interaction_workflow, slapos_api_invoicing_workflow</workflow>
......
<?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 = context.getPortalObject()\n
\n
portal.portal_catalog.searchAndActivate(\n
portal_type="Computer Consumption TioXML File",\n
validation_state="submitted",\n
method_id=\'ComputerConsumptionTioXMLFile_solveInvoicingGeneration\',\n
activity_count=1,\n
packet_size=1,\n
activate_kw={\'tag\': tag}\n
)\n
\n
context.activate(after_tag=tag).getId()\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_searchSubmittedConsumptionTioXMLFileList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Folder" module="OFS.Folder"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_local_properties</string> </key>
<value>
<tuple>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>business_template_skin_layer_priority</string> </value>
</item>
<item>
<key> <string>type</string> </key>
<value> <string>float</string> </value>
</item>
</dictionary>
</tuple>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>business_template_skin_layer_priority</string> </key>
<value> <float>60.0</float> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>slapos_consumption</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ExternalMethod" module="Products.ExternalMethod.ExternalMethod"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_function</string> </key>
<value> <string>ComputerConsumptionTioXMLFile_parseXml</string> </value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>SlapOSAccounting</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ComputerConsumptionTioXMLFile_parseXml</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></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>from zExceptions import Unauthorized\n
if REQUEST is not None:\n
raise Unauthorized\n
\n
document = context\n
portal = document.getPortalObject()\n
result = []\n
\n
tioxml_dict = document.ComputerConsumptionTioXMLFile_parseXml()\n
if tioxml_dict is None:\n
document.reject(comment="Not usable TioXML data")\n
else:\n
packing_list_dict = {}\n
for movement_dict in tioxml_dict["movement"]:\n
reference = movement_dict[\'reference\']\n
if reference in packing_list_dict:\n
packing_list_dict[reference].append(movement_dict)\n
else:\n
packing_list_dict[reference] = [movement_dict]\n
\n
computer = context.getContributorValue(portal_type="Computer")\n
for reference, movement_list in packing_list_dict.items():\n
\n
# Time to create the PL\n
delivery_template = portal.restrictedTraverse(\n
portal.portal_preferences.getPreferredInstanceDeliveryTemplate())\n
delivery = delivery_template.Base_createCloneDocument(batch_mode=1)\n
\n
# Find the partition / software instance / user\n
partition = portal.portal_catalog.getResultValue(\n
parent_uid=computer.getUid(),\n
reference=reference,\n
portal_type="Computer Partition",\n
validation_state="validated")\n
assert partition.getSlapState() == \'busy\'\n
\n
instance = portal.portal_catalog.getResultValue(\n
default_aggregate_uid=partition.getUid(),\n
portal_type="Software Instance",\n
validation_state="validated")\n
\n
subscription = instance.getSpecialiseValue(\n
portal_type="Hosting Subscription")\n
\n
person = subscription.getDestinationSectionValue(\n
portal_type="Person")\n
\n
delivery.edit(\n
title="%s Consumption Usage" % instance.getReference(),\n
destination=person.getRelativeUrl(),\n
destination_decision=person.getRelativeUrl(),\n
start_date=context.getCreationDate(),\n
)\n
\n
result.append(delivery.getRelativeUrl())\n
\n
for movement in movement_list:\n
service = portal.restrictedTraverse(movement[\'resource\'])\n
delivery.newContent(\n
portal_type="Sale Packing List Line",\n
title=movement[\'title\'],\n
quantity=movement[\'quantity\'],\n
aggregate_value_list=[partition, instance, subscription],\n
resource_value=service,\n
quantity_unit=service.getQuantityUnit(),\n
)\n
delivery.confirm(comment="Created from %s" % context.getRelativeUrl())\n
delivery.start()\n
delivery.stop()\n
delivery.deliver()\n
delivery.startBuilding()\n
\n
document.share(comment="Created packing list: %s" % result)\n
\n
return result\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ComputerConsumptionTioXMLFile_solveInvoicingGeneration</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>from zExceptions import Unauthorized\n
if REQUEST is not None:\n
raise Unauthorized\n
\n
portal = context.getPortalObject()\n
computer = context\n
\n
reference = "TIOCONS-%s-%s" % (computer.getReference(), source_reference)\n
version = "%s" % context.getPortalObject().portal_ids.generateNewId(\n
id_group=(\'slap_tioxml_consumption_reference\', reference), default=1)\n
\n
document = portal.consumption_document_module.newContent(\n
portal_type="Computer Consumption TioXML File",\n
source_reference=source_reference,\n
title="%s consumption (%s)" % (computer.getReference(), source_reference),\n
reference=reference,\n
version=version,\n
data=consumption_xml,\n
classification="personal",\n
publication_section="other",\n
contributor_value=computer,\n
)\n
document.submit()\n
return document.getRelativeUrl()\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>source_reference, consumption_xml, REQUEST=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Computer_reportComputerConsumption</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ERP5Form" module="Products.ERP5Form.Form"/>
</pickle>
<pickle>
<dictionary>
<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/>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>action</string> </key>
<value> <string>Base_doSelect</string> </value>
</item>
<item>
<key> <string>encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>enctype</string> </key>
<value> <string>multipart/form-data</string> </value>
</item>
<item>
<key> <string>group_list</string> </key>
<value>
<list>
<string>bottom</string>
<string>hidden</string>
</list>
</value>
</item>
<item>
<key> <string>groups</string> </key>
<value>
<dictionary>
<item>
<key> <string>bottom</string> </key>
<value>
<list>
<string>listbox</string>
</list>
</value>
</item>
<item>
<key> <string>hidden</string> </key>
<value>
<list>
<string>listbox_thumbnail</string>
<string>listbox_creation_date</string>
<string>listbox_modification_date</string>
</list>
</value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ConsumptionDocumentModule_viewDocumentList</string> </value>
</item>
<item>
<key> <string>method</string> </key>
<value> <string>POST</string> </value>
</item>
<item>
<key> <string>name</string> </key>
<value> <string>DocumentModule_viewDocumentList</string> </value>
</item>
<item>
<key> <string>pt</string> </key>
<value> <string>form_list</string> </value>
</item>
<item>
<key> <string>rid</string> </key>
<value> <int>-1722436574</int> </value>
</item>
<item>
<key> <string>row_length</string> </key>
<value> <int>4</int> </value>
</item>
<item>
<key> <string>stored_encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Document List</string> </value>
</item>
<item>
<key> <string>unicode_mode</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>update_action</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -1994,3 +1994,59 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by O ...@@ -1994,3 +1994,59 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by O
self.assertNotEqual( self.assertNotEqual(
'Visited by OpenSaleOrder_reindexIfIndexedBeforeLine', 'Visited by OpenSaleOrder_reindexIfIndexedBeforeLine',
open_order.workflow_history['edit_workflow'][-1]['comment']) open_order.workflow_history['edit_workflow'][-1]['comment'])
class TestSlapOSGeneratePackingListFromTioXML(testSlapOSMixin):
def createTioXMLFile(self):
document = self.portal.consumption_document_module.newContent(
title=self.generateNewId(),
reference="TESTTIOCONS-%s" % self.generateNewId(),
)
return document
def _simulateComputerConsumptionTioXMLFile_solveInvoicingGeneration(self):
script_name = 'ComputerConsumptionTioXMLFile_solveInvoicingGeneration'
if script_name in self.portal.portal_skins.custom.objectIds():
raise ValueError('Precondition failed: %s exists in custom' % script_name)
createZODBPythonScript(self.portal.portal_skins.custom,
script_name,
'*args, **kwargs',
'# Script body\n'
"""portal_workflow = context.portal_workflow
portal_workflow.doActionFor(context, action='edit_action', comment='Visited by ComputerConsumptionTioXMLFile_solveInvoicingGeneration') """ )
transaction.commit()
def _dropComputerConsumptionTioXMLFile_solveInvoicingGeneration(self):
script_name = 'ComputerConsumptionTioXMLFile_solveInvoicingGeneration'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
transaction.commit()
def test_alarm(self):
document = self.createTioXMLFile()
document.submit()
self.tic()
self._simulateComputerConsumptionTioXMLFile_solveInvoicingGeneration()
try:
self.portal.portal_alarms.\
slapos_accounting_generate_packing_list_from_tioxml.activeSense()
self.tic()
finally:
self._dropComputerConsumptionTioXMLFile_solveInvoicingGeneration()
self.assertEqual(
'Visited by ComputerConsumptionTioXMLFile_solveInvoicingGeneration',
document.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_not_submitted(self):
document = self.createTioXMLFile()
self.tic()
self._simulateComputerConsumptionTioXMLFile_solveInvoicingGeneration()
try:
self.portal.portal_alarms.\
slapos_accounting_generate_packing_list_from_tioxml.activeSense()
self.tic()
finally:
self._dropComputerConsumptionTioXMLFile_solveInvoicingGeneration()
self.assertNotEqual(
'Visited by ComputerConsumptionTioXMLFile_solveInvoicingGeneration',
document.workflow_history['edit_workflow'][-1]['comment'])
...@@ -4,4 +4,5 @@ erp5_accounting_l10n_fr ...@@ -4,4 +4,5 @@ erp5_accounting_l10n_fr
erp5_open_trade erp5_open_trade
erp5_simplified_invoicing erp5_simplified_invoicing
erp5_tiosafe_core erp5_tiosafe_core
slapos_cloud slapos_cloud
\ No newline at end of file erp5_dms
\ No newline at end of file
255 256
\ No newline at end of file \ No newline at end of file
Computer Consumption TioXML File | download
Computer Consumption TioXML File | view
Consumption Document Module | view
Hosting Subscription | periodicity Hosting Subscription | periodicity
SlapOS Accounting Quantity Updating Order Builder | view SlapOS Accounting Quantity Updating Order Builder | view
SlapOS Accounting Quantity Updating Order Builder | view_predicate_group SlapOS Accounting Quantity Updating Order Builder | view_predicate_group
......
SlapOSAccounting
\ No newline at end of file
...@@ -5,4 +5,5 @@ sale_packing_list_module/slapos_accounting_instance_delivery_line_template/** ...@@ -5,4 +5,5 @@ sale_packing_list_module/slapos_accounting_instance_delivery_line_template/**
service_module/slapos_instance_cleanup service_module/slapos_instance_cleanup
service_module/slapos_instance_setup service_module/slapos_instance_setup
service_module/slapos_instance_update service_module/slapos_instance_update
service_module/slapos_instance_subscription service_module/slapos_instance_subscription
\ No newline at end of file service_module/slapos_netdrive_consumption
\ No newline at end of file
...@@ -3,6 +3,7 @@ service_module/slapos_instance_subscription ...@@ -3,6 +3,7 @@ service_module/slapos_instance_subscription
service_module/slapos_instance_cleanup service_module/slapos_instance_cleanup
service_module/slapos_instance_setup service_module/slapos_instance_setup
service_module/slapos_instance_update service_module/slapos_instance_update
service_module/slapos_netdrive_consumption
account_module/bank account_module/bank
account_module/capital account_module/capital
account_module/coll_vat account_module/coll_vat
......
consumption_document_module
\ No newline at end of file
...@@ -21,6 +21,7 @@ open_sale_order_module/slapos_accounting_open_sale_order_line_template/slapos_ac ...@@ -21,6 +21,7 @@ open_sale_order_module/slapos_accounting_open_sale_order_line_template/slapos_ac
open_sale_order_module/slapos_accounting_open_sale_order_template open_sale_order_module/slapos_accounting_open_sale_order_template
organisation_module/slapos organisation_module/slapos
organisation_module/slapos/bank_account organisation_module/slapos/bank_account
portal_alarms/slapos_accounting_generate_packing_list_from_tioxml
portal_alarms/slapos_deliver_started_aggregated_sale_packing_list portal_alarms/slapos_deliver_started_aggregated_sale_packing_list
portal_alarms/slapos_instance_invoicing portal_alarms/slapos_instance_invoicing
portal_alarms/slapos_manage_building_calculating_delivery portal_alarms/slapos_manage_building_calculating_delivery
...@@ -73,4 +74,5 @@ service_module/slapos_instance_setup ...@@ -73,4 +74,5 @@ service_module/slapos_instance_setup
service_module/slapos_instance_subscription service_module/slapos_instance_subscription
service_module/slapos_instance_subscription/default_ssl service_module/slapos_instance_subscription/default_ssl
service_module/slapos_instance_update service_module/slapos_instance_update
service_module/slapos_netdrive_consumption
service_module/slapos_tax service_module/slapos_tax
\ No newline at end of file
Consumption Document Module | Computer Consumption TioXML File
Order Tool | SlapOS Accounting Quantity Updating Order Builder Order Tool | SlapOS Accounting Quantity Updating Order Builder
Rule Tool | Subscription Item Root Simulation Rule Rule Tool | Subscription Item Root Simulation Rule
SlapOS Accounting Quantity Updating Order Builder | Base Variant Movement Group SlapOS Accounting Quantity Updating Order Builder | Base Variant Movement Group
......
Consumption Document Module | business_application
Slave Instance | causality Slave Instance | causality
Software Instance | causality Software Instance | causality
\ No newline at end of file
Consumption Document Module | Computer Consumption TioXML File
\ No newline at end of file
Computer Consumption TioXML File
Consumption Document Module
SlapOS Accounting Quantity Updating Order Builder SlapOS Accounting Quantity Updating Order Builder
Subscription Item Root Simulation Rule Subscription Item Root Simulation Rule
\ No newline at end of file
Computer Consumption TioXML File | SortIndex
Hosting Subscription | SlapOSAccountingHostingSubscriptionConstraint Hosting Subscription | SlapOSAccountingHostingSubscriptionConstraint
Sale Invoice Transaction | SlapOSAccountingSaleInvoiceTransactionConstraint Sale Invoice Transaction | SlapOSAccountingSaleInvoiceTransactionConstraint
Sale Packing List Line | SlapOSAccountingSalePackingListLineConstraint Sale Packing List Line | SlapOSAccountingSalePackingListLineConstraint
......
Computer Consumption TioXML File | document_conversion_interaction_workflow
Computer Consumption TioXML File | document_publication_workflow
Computer Consumption TioXML File | edit_workflow
Hosting Subscription | slapos_accounting_interaction_workflow Hosting Subscription | slapos_accounting_interaction_workflow
Hosting Subscription | slapos_api_invoicing_workflow Hosting Subscription | slapos_api_invoicing_workflow
Sale Invoice Transaction | slapos_accounting_interaction_workflow Sale Invoice Transaction | slapos_accounting_interaction_workflow
......
slapos_accounting slapos_accounting
slapos_consumption
slapos_simulation slapos_simulation
\ No newline at end of file
testSlapOSAccountingSkins testSlapOSAccountingSkins
testSlapOSConsumptionSkins
testSlapOSAccountingAlarm testSlapOSAccountingAlarm
testSlapOSAccountingBuilder testSlapOSAccountingBuilder
testSlapOSAccountingConstraint testSlapOSAccountingConstraint
......
<local_roles_item>
<local_roles>
<role id='G-COMPANY'>
<item>Auditor</item>
<item>Author</item>
</role>
<role id='R-COMPUTER'>
<item>Author</item>
</role>
<role id='zope'>
<item>Owner</item>
</role>
</local_roles>
</local_roles_item>
\ No newline at end of file
<local_roles_item>
<local_roles>
<role id='G-COMPANY'>
<item>Assignor</item>
</role>
<role id='R-MEMBER'>
<item>Auditor</item>
</role>
<role id='zope'>
<item>Owner</item>
</role>
</local_roles>
</local_roles_item>
\ No newline at end of file
<type_roles>
<role id='Assignor'>
<property id='title'>Group company</property>
<multi_property id='category'>group/company</multi_property>
<multi_property id='base_category'>group</multi_property>
</role>
</type_roles>
\ No newline at end of file
<type_roles>
<role id='Author'>
<property id='title'>Computer reports consumption</property>
<multi_property id='category'>role/computer</multi_property>
</role>
<role id='Author; Auditor'>
<property id='title'>Group company</property>
<multi_property id='category'>group/company</multi_property>
<multi_property id='base_category'>group</multi_property>
</role>
</type_roles>
\ No newline at end of file
...@@ -2001,3 +2001,23 @@ class TestOneTimeRestrictedAccessToken(TestSlapOSGroupRoleSecurityMixin): ...@@ -2001,3 +2001,23 @@ class TestOneTimeRestrictedAccessToken(TestSlapOSGroupRoleSecurityMixin):
['G-COMPANY', self.user_id], False) ['G-COMPANY', self.user_id], False)
self.assertRoles(product, 'G-COMPANY', ['Assignor']) self.assertRoles(product, 'G-COMPANY', ['Assignor'])
self.assertRoles(product, self.user_id, ['Owner']) self.assertRoles(product, self.user_id, ['Owner'])
class TestConsumptionDocumentModule(TestSlapOSGroupRoleSecurityMixin):
def test(self):
module = self.portal.consumption_document_module
self.assertSecurityGroup(module,
['R-COMPUTER', 'zope', 'G-COMPANY'], False)
self.assertRoles(module, 'R-COMPUTER', ['Author'])
self.assertRoles(module, 'G-COMPANY', ['Author', 'Auditor'])
self.assertRoles(module, 'zope', ['Owner'])
class TestComputerConsumptionTioXMLFile(TestSlapOSGroupRoleSecurityMixin):
def test_GroupCompany(self):
text = self.portal.consumption_document_module.newContent(
portal_type='Computer Consumption TioXML File')
self.assertSecurityGroup(text,
['G-COMPANY', self.user_id],
False)
self.assertRoles(text, 'G-COMPANY', ['Assignor'])
self.assertRoles(text, self.user_id, ['Owner'])
...@@ -117,6 +117,7 @@ slapos_administration ...@@ -117,6 +117,7 @@ slapos_administration
slapos_cache slapos_cache
slapos_cloud slapos_cloud
slapos_cloud_promise slapos_cloud_promise
slapos_consumption
slapos_core slapos_core
slapos_crm slapos_crm
slapos_hypermedia slapos_hypermedia
...@@ -221,6 +222,7 @@ slapos_administration ...@@ -221,6 +222,7 @@ slapos_administration
slapos_cache slapos_cache
slapos_cloud slapos_cloud
slapos_cloud_promise slapos_cloud_promise
slapos_consumption
slapos_core slapos_core
slapos_crm slapos_crm
slapos_hypermedia slapos_hypermedia
...@@ -321,6 +323,7 @@ slapos_administration ...@@ -321,6 +323,7 @@ slapos_administration
slapos_cache slapos_cache
slapos_cloud slapos_cloud
slapos_cloud_promise slapos_cloud_promise
slapos_consumption
slapos_core slapos_core
slapos_crm slapos_crm
slapos_hypermedia slapos_hypermedia
...@@ -422,6 +425,7 @@ slapos_administration ...@@ -422,6 +425,7 @@ slapos_administration
slapos_cache slapos_cache
slapos_cloud slapos_cloud
slapos_cloud_promise slapos_cloud_promise
slapos_consumption
slapos_core slapos_core
slapos_crm slapos_crm
slapos_hypermedia slapos_hypermedia
...@@ -520,6 +524,7 @@ slapos_administration ...@@ -520,6 +524,7 @@ slapos_administration
slapos_cache slapos_cache
slapos_cloud slapos_cloud
slapos_cloud_promise slapos_cloud_promise
slapos_consumption
slapos_core slapos_core
slapos_crm slapos_crm
slapos_hypermedia slapos_hypermedia
...@@ -619,6 +624,7 @@ slapos_administration ...@@ -619,6 +624,7 @@ slapos_administration
slapos_cache slapos_cache
slapos_cloud slapos_cloud
slapos_cloud_promise slapos_cloud_promise
slapos_consumption
slapos_core slapos_core
slapos_crm slapos_crm
slapos_hypermedia slapos_hypermedia
...@@ -717,6 +723,7 @@ slapos_administration ...@@ -717,6 +723,7 @@ slapos_administration
slapos_cache slapos_cache
slapos_cloud slapos_cloud
slapos_cloud_promise slapos_cloud_promise
slapos_consumption
slapos_core slapos_core
slapos_crm slapos_crm
slapos_hypermedia slapos_hypermedia
...@@ -815,6 +822,7 @@ slapos_administration ...@@ -815,6 +822,7 @@ slapos_administration
slapos_cache slapos_cache
slapos_cloud slapos_cloud
slapos_cloud_promise slapos_cloud_promise
slapos_consumption
slapos_core slapos_core
slapos_crm slapos_crm
slapos_hypermedia slapos_hypermedia
...@@ -913,6 +921,7 @@ slapos_administration ...@@ -913,6 +921,7 @@ slapos_administration
slapos_cache slapos_cache
slapos_cloud slapos_cloud
slapos_cloud_promise slapos_cloud_promise
slapos_consumption
slapos_core slapos_core
slapos_crm slapos_crm
slapos_hypermedia slapos_hypermedia
...@@ -1013,6 +1022,7 @@ slapos_administration ...@@ -1013,6 +1022,7 @@ slapos_administration
slapos_cache slapos_cache
slapos_cloud slapos_cloud
slapos_cloud_promise slapos_cloud_promise
slapos_consumption
slapos_core slapos_core
slapos_crm slapos_crm
slapos_hypermedia slapos_hypermedia
......
172 173
\ No newline at end of file \ No newline at end of file
...@@ -21,6 +21,7 @@ component_module ...@@ -21,6 +21,7 @@ component_module
computer_model_module computer_model_module
computer_module computer_module
computer_network_module computer_network_module
consumption_document_module
credential_update_module credential_update_module
currency_module currency_module
currency_module/EUR currency_module/EUR
...@@ -57,6 +58,7 @@ sale_trade_condition_module ...@@ -57,6 +58,7 @@ sale_trade_condition_module
service_module service_module
service_module/slapos_discount service_module/slapos_discount
service_module/slapos_instance_subscription service_module/slapos_instance_subscription
service_module/slapos_netdrive_consumption
service_module/slapos_tax service_module/slapos_tax
software_installation_module software_installation_module
software_instance_module software_instance_module
......
...@@ -21,6 +21,7 @@ component_module ...@@ -21,6 +21,7 @@ component_module
computer_model_module computer_model_module
computer_module computer_module
computer_network_module computer_network_module
consumption_document_module
credential_update_module credential_update_module
currency_module currency_module
currency_module/EUR currency_module/EUR
...@@ -58,6 +59,7 @@ service_module ...@@ -58,6 +59,7 @@ service_module
service_module/slapos_discount service_module/slapos_discount
service_module/slapos_instance_subscription service_module/slapos_instance_subscription
service_module/slapos_tax service_module/slapos_tax
service_module/slapos_netdrive_consumption
software_installation_module software_installation_module
software_instance_module software_instance_module
software_product_module software_product_module
......
...@@ -16,12 +16,14 @@ Cash Register ...@@ -16,12 +16,14 @@ Cash Register
Component Component
Component Module Component Module
Computer Computer
Computer Consumption TioXML File
Computer Model Computer Model
Computer Model Module Computer Model Module
Computer Module Computer Module
Computer Network Computer Network
Computer Network Module Computer Network Module
Computer Partition Computer Partition
Consumption Document Module
Contribution Tool Contribution Tool
Credential Update Module Credential Update Module
Credit Card Credit Card
......
Access Token Module Access Token Module
One Time Restricted Access Token
Account Account
Account Module Account Module
Accounting Period Accounting Period
...@@ -17,12 +16,14 @@ Cash Register ...@@ -17,12 +16,14 @@ Cash Register
Component Component
Component Module Component Module
Computer Computer
Computer Consumption TioXML File
Computer Model Computer Model
Computer Model Module Computer Model Module
Computer Module Computer Module
Computer Network Computer Network
Computer Network Module Computer Network Module
Computer Partition Computer Partition
Consumption Document Module
Contribution Tool Contribution Tool
Credential Update Module Credential Update Module
Credit Card Credit Card
...@@ -56,6 +57,7 @@ Meeting Module ...@@ -56,6 +57,7 @@ Meeting Module
Note Note
Notification Message Notification Message
Notification Message Module Notification Message Module
One Time Restricted Access Token
Open Sale Order Open Sale Order
Open Sale Order Module Open Sale Order Module
Organisation Organisation
......
...@@ -673,6 +673,109 @@ class TestSlapOSSlapToolComputerAccess(TestSlapOSSlapToolMixin): ...@@ -673,6 +673,109 @@ class TestSlapOSSlapToolComputerAccess(TestSlapOSSlapToolMixin):
self.assertEqual(expected_xml, got_xml, self.assertEqual(expected_xml, got_xml,
'\n'.join([q for q in difflib.unified_diff(expected_xml.split('\n'), got_xml.split('\n'))])) '\n'.join([q for q in difflib.unified_diff(expected_xml.split('\n'), got_xml.split('\n'))]))
def test_useComputer_wrong_xml(self):
self.login(self.computer_id)
response = self.portal_slap.useComputer(
self.computer_id, "foobar")
self.assertEqual(400, response.status)
self.assertEqual("", response.body)
def assertReportComputerConsumption(self, args, kwargs):
stored = eval(open(self.computer_use_computer_simulator).read())
# do the same translation magic as in workflow
self.assertEqual(stored,
[{'recargs': args, 'reckwargs': kwargs,
'recmethod': 'Computer_reportComputerConsumption'}])
def test_useComputer_expected_xml(self):
self.computer_use_computer_simulator = tempfile.mkstemp()[1]
try:
self.login(self.computer_id)
self.computer.Computer_reportComputerConsumption = Simulator(
self.computer_use_computer_simulator,
'Computer_reportComputerConsumption')
consumption_xml = """<?xml version='1.0' encoding='utf-8'?>
<journal>
<transaction type="Sale Packing List">
<title>Resource consumptions</title>
<start_date></start_date>
<stop_date></stop_date>
<reference>testusagé</reference>
<currency></currency>
<payment_mode></payment_mode>
<category></category>
<arrow type="Administration">
<source></source>
<destination></destination>
</arrow>
<movement>
<resource>CPU Consumption</resource>
<title>Title Sale Packing List Line 1</title>
<reference>slappart0</reference>
<quantity>42.42</quantity>
<price>0.00</price>
<VAT>None</VAT>
<category>None</category>
</movement>
</transaction>
</journal>"""
response = self.portal_slap.useComputer(
self.computer_id, consumption_xml)
self.assertEqual(200, response.status)
self.assertEqual("OK", response.body)
self.assertReportComputerConsumption(
("testusagé", consumption_xml,), {})
finally:
if os.path.exists(self.computer_use_computer_simulator):
os.unlink(self.computer_use_computer_simulator)
def test_useComputer_empty_reference(self):
self.computer_use_computer_simulator = tempfile.mkstemp()[1]
try:
self.login(self.computer_id)
self.computer.Computer_reportComputerConsumption = Simulator(
self.computer_use_computer_simulator,
'Computer_reportComputerConsumption')
consumption_xml = """<?xml version='1.0' encoding='utf-8'?>
<journal>
<transaction type="Sale Packing List">
<title>Resource consumptions</title>
<start_date></start_date>
<stop_date></stop_date>
<reference></reference>
<currency></currency>
<payment_mode></payment_mode>
<category></category>
<arrow type="Administration">
<source></source>
<destination></destination>
</arrow>
<movement>
<resource>CPU Consumption</resource>
<title>Title Sale Packing List Line 1</title>
<reference>slappart0</reference>
<quantity>42.42</quantity>
<price>0.00</price>
<VAT>None</VAT>
<category>None</category>
</movement>
</transaction>
</journal>"""
response = self.portal_slap.useComputer(
self.computer_id, consumption_xml)
self.assertEqual(200, response.status)
self.assertEqual("OK", response.body)
self.assertReportComputerConsumption(
("", consumption_xml,), {})
finally:
if os.path.exists(self.computer_use_computer_simulator):
os.unlink(self.computer_use_computer_simulator)
class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin): class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
def test_getComputerPartitionCertificate(self): def test_getComputerPartitionCertificate(self):
self._makeComplexComputer() self._makeComplexComputer()
......
slapos_cloud slapos_cloud
\ No newline at end of file slapos_accounting
\ No newline at end of file
29 30
\ No newline at end of file \ No newline at end of file
...@@ -524,31 +524,28 @@ class SlapTool(BaseTool): ...@@ -524,31 +524,28 @@ class SlapTool(BaseTool):
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'useComputer') 'useComputer')
def useComputer(self, computer_id, use_string): def useComputer(self, computer_id, use_string):
"""Entry point to reporting usage of a computer.""" """
#We retrieve XSD model Entry point to reporting usage of a computer.
try: """
computer_consumption_model = \ computer_consumption_model = \
pkg_resources.resource_string( pkg_resources.resource_string(
'slapos.slap', 'slapos.slap',
'doc/computer_consumption.xsd') 'doc/computer_consumption.xsd')
except IOError:
computer_consumption_model = \
pkg_resources.resource_string(
__name__,
'../../../../slapos/slap/doc/computer_consumption.xsd')
if self._validateXML(use_string, computer_consumption_model): if self._validateXML(use_string, computer_consumption_model):
vifib_conduit_instance = VifibConduit.VifibConduit() computer = self._getComputerDocument(computer_id)
tree = etree.fromstring(use_string)
#We create the SPL source_reference = \
vifib_conduit_instance.addNode( tree.find('transaction').find('reference').text or ""
object=self, source_reference = source_reference.encode("UTF-8")
xml=use_string, computer.Computer_reportComputerConsumption(
computer_id=computer_id) source_reference,
use_string)
return "OK"
else: else:
raise NotImplementedError("XML file sent by the node is not valid !") self.REQUEST.response.setStatus(400)
self.REQUEST.response.setBody("")
return 'Content properly posted.' return self.REQUEST.response
@convertToREST @convertToREST
def _computerBang(self, computer_id, message): def _computerBang(self, computer_id, message):
...@@ -1237,12 +1234,6 @@ class SlapTool(BaseTool): ...@@ -1237,12 +1234,6 @@ class SlapTool(BaseTool):
parent_uid=self._getComputerUidByReference( parent_uid=self._getComputerUidByReference(
computer_reference)) computer_reference))
def _getUsageReportServiceDocument(self):
service_document = self.Base_getUsageReportServiceDocument()
if service_document is not None:
return service_document
raise Unauthorized
def _getSoftwareInstallationForComputer(self, url, computer_document): def _getSoftwareInstallationForComputer(self, url, computer_document):
software_installation_list = self.getPortalObject().portal_catalog.unrestrictedSearchResults( software_installation_list = self.getPortalObject().portal_catalog.unrestrictedSearchResults(
portal_type='Software Installation', portal_type='Software Installation',
...@@ -1372,100 +1363,6 @@ class SlapTool(BaseTool): ...@@ -1372,100 +1363,6 @@ class SlapTool(BaseTool):
software_release_list.append(software_release_response) software_release_list.append(software_release_response)
return software_release_list return software_release_list
def _reportComputerUsage(self, computer, usage):
"""Stores usage report of a computer."""
usage_report_portal_type = 'Usage Report'
usage_report_module = \
self.getPortalObject().getDefaultModule(usage_report_portal_type)
sale_packing_list_portal_type = 'Sale Packing List'
sale_packing_list_module = \
self.getPortalObject().getDefaultModule(sale_packing_list_portal_type)
sale_packing_list_line_portal_type = 'Sale Packing List Line'
software_release_portal_type = 'Software Release'
hosting_subscription_portal_type = 'Hosting Subscription'
software_instance_portal_type = 'Software Instance'
# We get the whole computer usage in one time
# We unmarshall it, then we create a single packing list,
# each line is a computer partition
unmarshalled_usage = xml_marshaller.xml_marshaller.loads(usage)
# Creates the Packing List
usage_report_sale_packing_list_document = \
sale_packing_list_module.newContent(
portal_type = sale_packing_list_portal_type,
)
usage_report_sale_packing_list_document.confirm()
usage_report_sale_packing_list_document.start()
# Adds a new SPL line for each Computer Partition
for computer_partition_usage in unmarshalled_usage\
.computer_partition_usage_list:
#Get good packing list line for a computer_partition
computer_partition_document = self.\
_getComputerPartitionDocument(
computer.getReference(),
computer_partition_usage.getId()
)
instance_setup_sale_packing_line = \
self._getDocument(
portal_type='Sale Packing List Line',
simulation_state='stopped',
aggregate_relative_url=computer_partition_document\
.getRelativeUrl(),
resource_relative_url=self.portal_preferences\
.getPreferredInstanceSetupResource()
)
# Fetching documents
software_release_document = \
self.getPortalObject().restrictedTraverse(
instance_setup_sale_packing_line.getAggregateList(
portal_type=software_release_portal_type
)[0]
)
hosting_subscription_document = \
self.getPortalObject().restrictedTraverse(
instance_setup_sale_packing_line.getAggregateList(
portal_type=hosting_subscription_portal_type
)[0]
)
software_instance_document = \
self.getPortalObject().restrictedTraverse(
instance_setup_sale_packing_line.getAggregateList(
portal_type=software_instance_portal_type
)[0]
)
# Creates the usage document
usage_report_document = usage_report_module.newContent(
portal_type = usage_report_portal_type,
text_content = computer_partition_usage.usage,
causality_value = computer_partition_document
)
usage_report_document.validate()
# Creates the line
usage_report_sale_packing_list_document.newContent(
portal_type = sale_packing_list_line_portal_type,
# We assume that "Usage Report" is an existing service document
resource_value = self._getUsageReportServiceDocument(),
aggregate_value_list = [usage_report_document, \
computer_partition_document, software_release_document, \
hosting_subscription_document, software_instance_document
]
)
def _reportUsage(self, computer_partition, usage):
"""Warning : deprecated method."""
portal_type = 'Usage Report'
module = self.getPortalObject().getDefaultModule(portal_type)
usage_report = module.newContent(
portal_type=portal_type,
text_content=usage,
causality_value=computer_partition
)
usage_report.validate()
@convertToREST @convertToREST
def _softwareReleaseError(self, url, computer_id, error_log): def _softwareReleaseError(self, url, computer_id, error_log):
""" """
......
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