Commit cfa08898 authored by Xiaowu Zhang's avatar Xiaowu Zhang

erp5_trade: show calculation steps

parent 3b239e0f
if url_dict:
jio_key = '/'.join(context.movement_url.split('/')[-2:])
return {
'command': 'push_history',
'options': {
'jio_key': jio_key
'jio_key': context.movement_url
},
}
else:
return context.movement_url
return "%s/%s" % (context.getPortalObject().absolute_url(), context.movement_url)
......@@ -8,7 +8,9 @@ getMovementHistoryList = portal.portal_simulation.getMovementHistoryList
current_date_kw = kw.copy()
kw.pop('valuation_method', None)
kw['sort_on'] =(('date','ascending'),)
kw['sort_on'] =(('stock.date','ascending'),)
kw['simulation_state'] = portal.getPortalCurrentInventoryStateList() + portal.getPortalTransitInventoryStateList()
movement_dict = OrderedDict()
current_id = 1
......@@ -22,11 +24,18 @@ for date, value_list in movement_dict.iteritems():
same_date_length = len(value_list)
for index in range(same_date_length):
if index < same_date_length - 1:
current_date_kw['uid'] = NegatedQuery(SimpleQuery(uid=[x.getUid() for x in value_list[index+1:]]))
exclude_uid_list = [x.getUid() for x in value_list[index+1:]]
current_date_kw['uid'] = NegatedQuery(SimpleQuery(uid=exclude_uid_list))
else:
exclude_uid_list = []
current_date_kw.pop('uid', None)
total_asset_price = getCurrentInventoryAssetPrice(**current_date_kw)
movement = value_list[index]
# same date internal order, calculate asset price later
if movement.getUid() in exclude_uid_list:
total_asset_price = ''
else:
total_asset_price = getCurrentInventoryAssetPrice(**current_date_kw) or 0
if not getattr(movement, 'isDelivery', 0):
explanation = movement.getExplanationValue()
else:
......@@ -36,7 +45,7 @@ for date, value_list in movement_dict.iteritems():
id = format(current_id, '07d'),
portal_type='Inventory Report Cell',
date = movement.date,
movement_url = explanation.absolute_url(),
movement_url = explanation.getRelativeUrl(),
explanation_text = movement.getExplanationText(),
node_title = movement.node_title,
section_title = movement.section_title,
......
......@@ -52,6 +52,14 @@
<key> <string>_params</string> </key>
<value> <string>**kw</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
<value>
<tuple>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>InventoryReportLine_createMovementHistoryCellList</string> </value>
......
......@@ -93,6 +93,7 @@
<list>
<string>listbox_date</string>
<string>listbox_total_quantity</string>
<string>listbox_total_asset_price</string>
</list>
</value>
</item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>default</string>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>listbox_total_asset_price</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_view_mode_total_price</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewTradeFieldLibrary</string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Total Asset Price</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -449,7 +449,7 @@ class TestInventoryReportModule(TestOrderMixin, SecurityTestCase):
pl.stop()
pl.deliver()
self.tic()
def stepSetResourceUnit(self, sequence=None,
sequence_list=None, **kw):
resource_list = sequence.get('resource_list')
......@@ -527,8 +527,8 @@ class TestInventoryReportModule(TestOrderMixin, SecurityTestCase):
self.assertEqual(inventory_report_line_list[3].total_asset_price, 0)
self.assertEqual(inventory_report_line_list[4].total_quantity, 45-14)
self.assertAlmostEqual(inventory_report_line_list[4].total_asset_price, (45-14)*80*0.13)
inventory_report = self.getInventoryReportModule().newContent(portal_type='Inventory Report')
inventory_report.edit(
destination_value = sequence.get('organisation_euro'),
......@@ -682,6 +682,45 @@ class TestInventoryReportModule(TestOrderMixin, SecurityTestCase):
self.assertAlmostEqual(inventory_report_line_list[4].total_asset_price, 51*201*0.14)
def stepTestCalculateStep(self, sequence=None, sequence_list=None, **kw):
inventory_report = self.getInventoryReportModule().newContent(portal_type='Inventory Report')
inventory_report.edit(
destination_section_value = sequence.get('organisation_euro'),
valuation_method = 'Fifo'
)
self.tic()
inventory_report.InventoryReport_calculateProductStock(batch_mode=True)
self.assertEqual(inventory_report.getSimulationState(), 'calculating')
self.tic()
self.assertEqual(inventory_report.getSimulationState(), 'recorded')
self.tic()
inventory_report_line_list = inventory_report.contentValues(portal_type='Inventory Report Line')
self.assertEqual(len(inventory_report_line_list), 1)
inventory_report_line = inventory_report_line_list[0]
inventory_report_cell_list = inventory_report_line.contentValues(portal_type='Inventory Report Cell')
self.assertEqual(len(inventory_report_cell_list), 5)
inventory_report_cell_list.sort(key=lambda x: x.id)
self.assertEqual(inventory_report_cell_list[0].total_asset_price, 832)
self.assertEqual(inventory_report_cell_list[1].total_asset_price, 1664)
self.assertEqual(inventory_report_cell_list[2].total_asset_price, 1144)
self.assertEqual(inventory_report_cell_list[3].total_asset_price, '')
self.assertEqual(inventory_report_cell_list[4].total_asset_price, 1222.40)
self.assertEqual(inventory_report_cell_list[0].running_total_quantity, 80)
self.assertEqual(inventory_report_cell_list[1].running_total_quantity, 160)
self.assertEqual(inventory_report_cell_list[2].running_total_quantity, 110)
self.assertTrue(inventory_report_cell_list[3].running_total_quantity in [124, 96])
self.assertEqual(inventory_report_cell_list[4].running_total_quantity, 110)
self.assertEqual(inventory_report_cell_list[0].total_quantity, 80)
self.assertEqual(inventory_report_cell_list[1].total_quantity, 80)
self.assertEqual(inventory_report_cell_list[2].total_quantity, -50)
self.assertTrue(inventory_report_cell_list[3].total_quantity in [-14, 14])
self.assertTrue(inventory_report_cell_list[4].total_quantity in [-14, 14])
def test_01_workflowAndAccessPermission(self, run=run_all_test):
"""
"""
......@@ -854,6 +893,33 @@ class TestInventoryReportModule(TestOrderMixin, SecurityTestCase):
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
def test_03_checkCalculateStep(self, run=run_all_test):
if not run: return
sequence_list = SequenceList()
sequence_string = 'CreateNotVariatedResource \
stepCreateThreeCurrencys \
stepSetResourceUnit \
stepCreateThreeOrganisations \
stepCreateTwoWarehouse \
stepTic \
stepCreatePurchasePackingListFromRMBToEURO \
stepDeliverPackingList \
stepTic \
stepCreatePurchasePackingListFromRMBToEURO \
stepDeliverPackingList \
stepTic \
stepCreateSalesPackingListEUROToUSD \
stepDeliverPackingList \
stepTic \
stepCreateInternalPackingListFromEUROWarehouseEuroToEuroWarehouseB \
stepDeliverPackingList \
stepTic \
stepTestCalculateStep \
'
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
def _test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestInventoryReportModule))
......
......@@ -6,6 +6,12 @@
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>testInventoryReportModule</string> </value>
......@@ -53,13 +59,28 @@
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</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>
......@@ -72,7 +93,7 @@
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
</dictionary>
......@@ -81,7 +102,7 @@
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
......
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