Commit 505d155f authored by Jérome Perrin's avatar Jérome Perrin

Item tracking and movements in started state

After that change, when there is a movement from A to B in **started** state, `Item_getCurrentSiteValue` will consider that this movement has already reached B.

Before this change, `Item_getCurrentSiteValue` was returning None, which somehow makes sense because started movement is in transit state, so the item has left A but not yet reached B, so it is in an unknown location.
Low level current tracking list API ( getCurrentTrackingList ) does not return items for started movements.
Honestly, I do not know if this is by design. ( @all anybody knows ? )

I will work on adding missing tests, but please tell me if I am wrong in thinking it should return None.

@gabriel @rafael @tb @tc do you remember why this change was introduced ? Maybe that behaviour of returning None should be only at the level of `Item_get*` scripts ? 

/reviewed-on !70
parents 7fe887d2 fed71e1e
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>at_date=None, fallback_on_future=True, **kw</string> </value>
<value> <string>at_date=None, fallback_on_future=False, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -160,6 +160,14 @@ class DeliveryCell(MappedValue, Movement, ImmobilisationMovement):
def isMovement(self):
return 1
security.declareProtected(Permissions.AccessContentsInformation,
'isMovingItem')
def isMovingItem(self, item):
type_based_script = self._getTypeBasedMethod('isMovingItem')
if type_based_script:
return type_based_script(item)
return self.isAccountable()
# Override getQuantityUnitXXX to negate same methods defined in
# Amount class. Because cell must acquire quantity unit from line
# not from resource.
......
......@@ -113,6 +113,7 @@ class TestItemMixin(TestSaleInvoiceMixin):
title = "PPL%s" % pac_list.getId(),
start_date = self.datetime + 20,
stop_date = self.datetime + 10,
specialise_value = portal.business_process_module.erp5_default_business_process,
)
if organisation is not None:
......@@ -904,7 +905,6 @@ class TestItem(TestItemMixin, ERP5TypeTestCase):
self.assertEqual(12, packing_list_line.getQuantity())
@newSimulationExpectedFailure
def test_select_item_dialog_variation(self):
organisation = self.createOrganisation(title='Organisation IV')
resource = self.createVariatedResource()
......@@ -980,6 +980,7 @@ class TestItemScripts(ERP5TypeTestCase):
def getBusinessTemplateList(self):
return ('erp5_base', 'erp5_pdm', 'erp5_simulation', 'erp5_trade',
'erp5_item', 'erp5_configurator_standard_solver',
'erp5_configurator_standard_trade_template',
'erp5_simulation_test')
def afterSetUp(self):
......@@ -1039,6 +1040,7 @@ class TestItemScripts(ERP5TypeTestCase):
source_section_value=self.mirror_section,
destination_value=self.node,
destination_section_value=self.section,
specialise_value=self.portal.business_process_module.erp5_default_business_process,
start_date=DateTime() - 1,)
line = packing_list.newContent(
portal_type='Sale Packing List Line',
......@@ -1051,7 +1053,6 @@ class TestItemScripts(ERP5TypeTestCase):
return line
# with line
@newSimulationExpectedFailure
def test_Item_getResourceValue(self):
self.assertEqual(None, self.item.Item_getResourceValue())
line = self._makeSalePackingListLine()
......@@ -1059,7 +1060,6 @@ class TestItemScripts(ERP5TypeTestCase):
self.assertEqual(None, self.item.Item_getResourceValue(
at_date=DateTime() - 2))
@newSimulationExpectedFailure
def test_Item_getResourceTitle(self):
self.assertEqual(None, self.item.Item_getResourceTitle())
line = self._makeSalePackingListLine()
......@@ -1067,7 +1067,6 @@ class TestItemScripts(ERP5TypeTestCase):
self.assertEqual(None, self.item.Item_getResourceTitle(
at_date=DateTime() - 2))
@newSimulationExpectedFailure
def test_Item_getCurrentOwnerValue(self):
self.assertEqual(None, self.item.Item_getCurrentOwnerValue())
line = self._makeSalePackingListLine()
......@@ -1075,7 +1074,6 @@ class TestItemScripts(ERP5TypeTestCase):
self.assertEqual(None,
self.item.Item_getCurrentOwnerValue(at_date=DateTime() - 2))
@newSimulationExpectedFailure
def test_Item_getCurrentOwnerTitle(self):
self.assertEqual(None, self.item.Item_getCurrentOwnerTitle())
line = self._makeSalePackingListLine()
......@@ -1083,7 +1081,6 @@ class TestItemScripts(ERP5TypeTestCase):
self.assertEqual(None,
self.item.Item_getCurrentOwnerTitle(at_date=DateTime() - 2))
@newSimulationExpectedFailure
def test_Item_getCurrentSiteValue(self):
self.assertEqual(None, self.item.Item_getCurrentSiteValue())
line = self._makeSalePackingListLine()
......@@ -1091,7 +1088,6 @@ class TestItemScripts(ERP5TypeTestCase):
self.assertEqual(None, self.item.Item_getCurrentSiteValue(
at_date=DateTime() - 2))
@newSimulationExpectedFailure
def test_Item_getCurrentSiteTitle(self):
self.assertEqual(None, self.item.Item_getCurrentSiteTitle())
line = self._makeSalePackingListLine()
......@@ -1099,6 +1095,56 @@ class TestItemScripts(ERP5TypeTestCase):
self.assertEqual(None,
self.item.Item_getCurrentSiteTitle(at_date=DateTime() - 2))
def test_item_current_location_and_transit_movement(self):
# a started packing list is still in transit, so we do not know its
# current location until it is delivered.
# https://lab.nexedi.com/nexedi/erp5/merge_requests/70
implicit_movement = self.portal.implicit_item_movement_module.newContent(
portal_type='Implicit Item Movement',
destination_value=self.mirror_node,
destination_section_value=self.mirror_section,
stop_date=DateTime() - 2,
aggregate_value=self.item,
)
implicit_movement.deliver()
packing_list = self.portal.sale_packing_list_module.newContent(
portal_type='Sale Packing List',
source_value=self.mirror_node,
source_section_value=self.mirror_section,
destination_value=self.node,
destination_section_value=self.section,
specialise_value=self.portal.business_process_module.erp5_default_business_process,
start_date=DateTime() - 1,)
line = packing_list.newContent(
portal_type='Sale Packing List Line',
quantity=1,
resource_value=self.product,
aggregate_value=self.item,)
packing_list.confirm()
self.tic()
self.assertEqual(self.mirror_node, self.item.Item_getCurrentSiteValue())
self.assertEqual('Mirror Node', self.item.Item_getCurrentSiteTitle())
self.assertEqual(self.mirror_section, self.item.Item_getCurrentOwnerValue())
self.assertEqual('Mirror Section', self.item.Item_getCurrentOwnerTitle())
packing_list.start()
self.tic()
# When movement is started, the item is still moving so we do not know it's location / ownership.
# In this case we just return None.
self.assertEqual(None, self.item.Item_getCurrentSiteValue())
self.assertEqual(None, self.item.Item_getCurrentSiteTitle())
self.assertEqual(None, self.item.Item_getCurrentOwnerValue())
self.assertEqual(None, self.item.Item_getCurrentOwnerTitle())
packing_list.stop()
self.tic()
self.assertEqual(self.node, self.item.Item_getCurrentSiteValue())
self.assertEqual('Node', self.item.Item_getCurrentSiteTitle())
self.assertEqual(self.section, self.item.Item_getCurrentOwnerValue())
self.assertEqual('Section', self.item.Item_getCurrentOwnerTitle())
# with cells
@reindex
def _makeSalePackingListCellWithVariation(self):
......@@ -1108,6 +1154,7 @@ class TestItemScripts(ERP5TypeTestCase):
source_section_value=self.mirror_section,
destination_value=self.node,
destination_section_value=self.section,
specialise_value=self.portal.business_process_module.erp5_default_business_process,
start_date=DateTime() - 1,)
line = packing_list.newContent(
portal_type='Sale Packing List Line',
......@@ -1124,7 +1171,6 @@ class TestItemScripts(ERP5TypeTestCase):
packing_list.deliver()
return cell
@newSimulationExpectedFailure
def test_Item_getVariationCategoryList(self):
self.assertEqual([], self.item.Item_getVariationCategoryList())
self._makeSalePackingListCellWithVariation()
......@@ -1132,7 +1178,6 @@ class TestItemScripts(ERP5TypeTestCase):
self.assertEqual([],
self.item.Item_getVariationCategoryList(at_date=DateTime() - 2))
@newSimulationExpectedFailure
def test_Item_getVariationRangeCategoryItemList(self):
self.assertEqual([], self.item.Item_getVariationRangeCategoryItemList())
self._makeSalePackingListCellWithVariation()
......
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