Commit 1cd6b9fe authored by Jérome Perrin's avatar Jérome Perrin

Fixed the fact that IventoryBrain.getExplanationText cannot find the

explanation for "Virtual" Inventory movements. 



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@7570 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0b203cf5
...@@ -62,7 +62,8 @@ class Inventory(Delivery): ...@@ -62,7 +62,8 @@ class Inventory(Delivery):
security.declarePublic('alternateReindexObject') security.declarePublic('alternateReindexObject')
def alternateReindexObject(self, **kw): def alternateReindexObject(self, **kw):
"""This method is called when an inventory object is included in a group of catalogged objects. """This method is called when an inventory object is included in a
group of catalogged objects.
""" """
return self.immediateReindexObject(**kw) return self.immediateReindexObject(**kw)
......
...@@ -162,10 +162,15 @@ class InventoryListBrain(ZSQLBrain): ...@@ -162,10 +162,15 @@ class InventoryListBrain(ZSQLBrain):
def getListItemUrl(self, cname_id, selection_index, selection_name): def getListItemUrl(self, cname_id, selection_index, selection_name):
# XXX FIXME can catch to many exceptions # XXX FIXME can catch to many exceptions
try: try:
if cname_id in ('getExplanationText','getExplanation', ): if cname_id in ('getExplanationText', 'getExplanation', ):
o = self.getObject() o = self.getObject()
if o is not None: if o is not None:
if not getattr(o, 'isDelivery', 0):
explanation = o.getExplanationValue() explanation = o.getExplanationValue()
else:
# Additional inventory movements are catalogged in stock table
# with the inventory's uid. Then they are their own explanation.
explanation = o
if explanation is not None: if explanation is not None:
return '%s/%s/view' % ( return '%s/%s/view' % (
self.portal_url.getPortalObject().absolute_url(), self.portal_url.getPortalObject().absolute_url(),
...@@ -238,7 +243,12 @@ class InventoryListBrain(ZSQLBrain): ...@@ -238,7 +243,12 @@ class InventoryListBrain(ZSQLBrain):
if o is not None: if o is not None:
N_ = lambda msg, **kw: o.Localizer.translate('ui', msg, **kw) N_ = lambda msg, **kw: o.Localizer.translate('ui', msg, **kw)
# Get the delivery/order # Get the delivery/order
if not getattr(o, 'isDelivery', 0):
delivery = o.getExplanationValue() delivery = o.getExplanationValue()
else:
# Additional inventory movements are catalogged in stock table
# with the inventory's uid. Then they are their own explanation.
delivery = o
if delivery is not None: if delivery is not None:
mapping = { mapping = {
'delivery_portal_type' : delivery.getTranslatedPortalType(), 'delivery_portal_type' : delivery.getTranslatedPortalType(),
......
...@@ -42,17 +42,9 @@ os.environ['EVENT_LOG_SEVERITY'] = '-300' ...@@ -42,17 +42,9 @@ os.environ['EVENT_LOG_SEVERITY'] = '-300'
from Testing import ZopeTestCase from Testing import ZopeTestCase
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from AccessControl.SecurityManagement import newSecurityManager, \
noSecurityManager
from DateTime import DateTime from DateTime import DateTime
from Acquisition import aq_base, aq_inner
from zLOG import LOG from zLOG import LOG
from Products.ERP5Type.DateUtils import addToDate
from Products.ERP5Type.tests.Sequence import Sequence, SequenceList from Products.ERP5Type.tests.Sequence import Sequence, SequenceList
import time
import os
from Products.ERP5Type import product_path
from Products.CMFCore.utils import getToolByName
from testOrder import TestOrderMixin from testOrder import TestOrderMixin
class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase): class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
...@@ -162,8 +154,8 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase): ...@@ -162,8 +154,8 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
resource_value = resource) resource_value = resource)
return inventory return inventory
def stepCreateFirstNotVariatedInventory(self, sequence=None, sequence_list=None, \ def stepCreateFirstNotVariatedInventory(self, sequence=None,
**kw): sequence_list=None, **kw):
""" """
We will put default values for an inventory We will put default values for an inventory
""" """
...@@ -175,8 +167,8 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase): ...@@ -175,8 +167,8 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
self.createNotVariatedInventoryLine(sequence=sequence, self.createNotVariatedInventoryLine(sequence=sequence,
quantity=quantity) quantity=quantity)
def stepCreateSecondNotVariatedInventory(self, sequence=None, sequence_list=None, \ def stepCreateSecondNotVariatedInventory(self, sequence=None,
**kw): sequence_list=None, **kw):
""" """
We will put default values for an inventory We will put default values for an inventory
""" """
...@@ -198,11 +190,12 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase): ...@@ -198,11 +190,12 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
self.assertEquals(self.default_quantity,quantity) self.assertEquals(self.default_quantity,quantity)
def stepCheckSecondNotVariatedInventory(self, start_date=None,quantity=None, def stepCheckSecondNotVariatedInventory(self, start_date=None,quantity=None,
sequence=None,**kw): sequence=None, **kw):
node_uid = sequence.get('organisation1').getUid() node_uid = sequence.get('organisation1').getUid()
resource_url = sequence.get('resource').getRelativeUrl() resource_url = sequence.get('resource').getRelativeUrl()
date = DateTime(self.view_stock_date) date = DateTime(self.view_stock_date)
LOG('CheckSecondNotVariatedInventory',0, self.getSimulationTool().getInventory(node_uid=node_uid, LOG('CheckSecondNotVariatedInventory', 0,
self.getSimulationTool().getInventory(node_uid=node_uid,
resource=resource_url, resource=resource_url,
to_date=date,src__=1)) to_date=date,src__=1))
quantity = self.getSimulationTool().getInventory(node_uid=node_uid, quantity = self.getSimulationTool().getInventory(node_uid=node_uid,
...@@ -223,22 +216,22 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase): ...@@ -223,22 +216,22 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
sequence_list = SequenceList() sequence_list = SequenceList()
# Test with a simple inventory without cell # Test with a simple inventory without cell
sequence_string = 'CreateNotVariatedResource \ sequence_string = 'stepCreateNotVariatedResource \
CreateOrganisation1 \ stepCreateOrganisation1 \
CreateInitialMovements \ stepCreateInitialMovements \
Tic \ stepTic \
CreateFirstNotVariatedInventory \ stepCreateFirstNotVariatedInventory \
Tic \ stepTic \
CheckFirstNotVariatedInventory \ stepCheckFirstNotVariatedInventory \
CreateSecondNotVariatedInventory \ stepCreateSecondNotVariatedInventory \
Tic \ stepTic \
CheckSecondNotVariatedInventory' stepCheckSecondNotVariatedInventory'
sequence_list.addSequenceString(sequence_string) sequence_list.addSequenceString(sequence_string)
sequence_list.play(self) sequence_list.play(self)
def createVariatedInventoryLine(self, sequence=None, sequence_list=None, def createVariatedInventoryLine(self, sequence=None, sequence_list=None,
start_date=None,quantity=None,item_list=None, start_date=None, quantity=None, item_list=None,
**kw): **kw):
""" """
We will put default values for an inventory We will put default values for an inventory
...@@ -250,7 +243,8 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase): ...@@ -250,7 +243,8 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
portal_type=self.inventory_line_portal_type) portal_type=self.inventory_line_portal_type)
inventory_line.edit(resource_value = resource) inventory_line.edit(resource_value = resource)
resource_vcl = list(resource.getVariationCategoryList( resource_vcl = list(resource.getVariationCategoryList(
omit_individual_variation=1,omit_option_base_category=1)) omit_individual_variation=1,
omit_option_base_category=1))
resource_vcl.sort() resource_vcl.sort()
self.assertEquals(len(resource_vcl),2) self.assertEquals(len(resource_vcl),2)
inventory_line.setVariationCategoryList(resource_vcl) inventory_line.setVariationCategoryList(resource_vcl)
...@@ -259,8 +253,9 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase): ...@@ -259,8 +253,9 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
cell_key_list.sort() cell_key_list.sort()
price = 100 price = 100
for cell_key in cell_key_list: for cell_key in cell_key_list:
cell = inventory_line.newCell(base_id=base_id, \ cell = inventory_line.newCell(base_id=base_id,
portal_type=self.inventory_cell_portal_type, *cell_key) portal_type=self.inventory_cell_portal_type,
*cell_key)
cell.edit(mapped_value_property_list=['price','inventory'], cell.edit(mapped_value_property_list=['price','inventory'],
price=price, inventory=quantity, price=price, inventory=quantity,
predicate_category_list=cell_key, predicate_category_list=cell_key,
...@@ -299,7 +294,8 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase): ...@@ -299,7 +294,8 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
""" """
We will put default values for an inventory We will put default values for an inventory
""" """
inventory = self.createNotVariatedInventory(sequence=sequence,start_date=start_date) inventory = self.createNotVariatedInventory(sequence=sequence,
start_date=start_date)
resource = sequence.get('resource_list')[0] resource = sequence.get('resource_list')[0]
organisation = sequence.get('organisation1') organisation = sequence.get('organisation1')
inventory = self.getInventoryModule().newContent() inventory = self.getInventoryModule().newContent()
...@@ -357,16 +353,16 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase): ...@@ -357,16 +353,16 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
sequence_list = SequenceList() sequence_list = SequenceList()
# Test with a variated inventory # Test with a variated inventory
sequence_string = 'CreateVariatedResource \ sequence_string = 'stepCreateVariatedResource \
CreateOrganisation1 \ stepCreateOrganisation1 \
CreateInitialMovements \ stepCreateInitialMovements \
Tic \ stepTic \
CreateFirstVariatedInventory \ stepCreateFirstVariatedInventory \
Tic \ stepTic \
CheckFirstVariatedInventory \ stepCheckFirstVariatedInventory \
CreateSecondVariatedInventory \ stepCreateSecondVariatedInventory \
Tic \ stepTic \
CheckSecondVariatedInventory' stepCheckSecondVariatedInventory'
sequence_list.addSequenceString(sequence_string) sequence_list.addSequenceString(sequence_string)
sequence_list.play(self) sequence_list.play(self)
...@@ -409,8 +405,8 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase): ...@@ -409,8 +405,8 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
relative_url_text = '\n'.join(relative_url_list) relative_url_text = '\n'.join(relative_url_list)
return relative_url_text return relative_url_text
def stepCheckFirstVariatedAggregatedInventory(self, start_date=None,quantity=None, def stepCheckFirstVariatedAggregatedInventory(self, start_date=None,
sequence=None,**kw): quantity=None, sequence=None, **kw):
node_uid = sequence.get('organisation1').getUid() node_uid = sequence.get('organisation1').getUid()
resource_url = sequence.get('resource').getRelativeUrl() resource_url = sequence.get('resource').getRelativeUrl()
date = DateTime(self.view_stock_date) date = DateTime(self.view_stock_date)
...@@ -437,8 +433,27 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase): ...@@ -437,8 +433,27 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
sub_variation_text=sub_variation_text) sub_variation_text=sub_variation_text)
self.assertEquals(total_quantity,quantity) self.assertEquals(total_quantity,quantity)
def stepCreateSecondVariatedAggregatedInventory(self, sequence=None, sequence_list=None, \ def stepCheckExplanationTextInInventoryList(self, start_date=None,
**kw): quantity=None, sequence=None, **kw):
"""Tests getExplanationText from InventoryBrain
"""
# this is rather a test for InventoryBrain
node_uid = sequence.get('organisation1').getUid()
resource_url = sequence.get('resource').getRelativeUrl()
date = DateTime(self.view_stock_date)
for inventory_brain in self.getSimulationTool().getInventoryList(
node_uid=node_uid,
resource=resource_url,
to_date=date):
self.assertNotEquals(inventory_brain.getExplanationText(),
'Unknown')
self.assertNotEquals(inventory_brain.getListItemUrl(
'getExplanationText',
0,
'dummy_selection_name'), '')
def stepCreateSecondVariatedAggregatedInventory(self, sequence=None,
sequence_list=None, **kw):
""" """
We will put default values for an inventory We will put default values for an inventory
- size/Child/32 89 item1,item2 - size/Child/32 89 item1,item2
...@@ -458,8 +473,8 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase): ...@@ -458,8 +473,8 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
sequence=sequence, quantity=quantity, sequence=sequence, quantity=quantity,
item_list=item_list) item_list=item_list)
def stepCheckSecondVariatedAggregatedInventory(self, start_date=None,quantity=None, def stepCheckSecondVariatedAggregatedInventory(self, start_date=None,
sequence=None,**kw): quantity=None, sequence=None, **kw):
node_uid = sequence.get('organisation1').getUid() node_uid = sequence.get('organisation1').getUid()
resource_url = sequence.get('resource').getRelativeUrl() resource_url = sequence.get('resource').getRelativeUrl()
date = DateTime(self.view_stock_date) date = DateTime(self.view_stock_date)
...@@ -476,7 +491,8 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase): ...@@ -476,7 +491,8 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
to_date=date,simulation_state='delivered') to_date=date,simulation_state='delivered')
self.assertEquals(total_quantity,quantity) self.assertEquals(total_quantity,quantity)
# Also check when we look stock for a particular aggregate # Also check when we look stock for a particular aggregate
sub_variation_text = self.getAggregateRelativeUrlText(sequence.get('item_list')) sub_variation_text = self.getAggregateRelativeUrlText(
sequence.get('item_list'))
total_quantity = 0 total_quantity = 0
quantity = self.getSimulationTool().getInventory(node_uid=node_uid, quantity = self.getSimulationTool().getInventory(node_uid=node_uid,
resource=resource_url, resource=resource_url,
...@@ -484,7 +500,8 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase): ...@@ -484,7 +500,8 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
sub_variation_text=sub_variation_text, sub_variation_text=sub_variation_text,
simulation_state='delivered') simulation_state='delivered')
self.assertEquals(total_quantity,quantity) self.assertEquals(total_quantity,quantity)
sub_variation_text = self.getAggregateRelativeUrlText(sequence.get('item_list')[:1]) sub_variation_text = self.getAggregateRelativeUrlText(
sequence.get('item_list')[:1])
def test_03_VariatedAggregatedInventory(self, run=run_all_test): def test_03_VariatedAggregatedInventory(self, run=run_all_test):
""" """
...@@ -496,18 +513,46 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase): ...@@ -496,18 +513,46 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
sequence_list = SequenceList() sequence_list = SequenceList()
# Test with a variated inventory with some aggregate # Test with a variated inventory with some aggregate
sequence_string = 'CreateVariatedResource \ sequence_string = 'stepCreateVariatedResource \
CreateOrganisation1 \ stepCreateOrganisation1 \
CreateInitialMovements \ stepCreateInitialMovements \
Tic \ stepTic \
CreateItem \ stepCreateItem \
CreateItem \ stepCreateItem \
CreateFirstVariatedAggregatedInventory \ stepCreateFirstVariatedAggregatedInventory \
Tic \ stepTic \
CheckFirstVariatedAggregatedInventory \ stepCheckFirstVariatedAggregatedInventory \
CreateSecondVariatedAggregatedInventory \ stepCreateSecondVariatedAggregatedInventory \
Tic \ stepTic \
CheckSecondVariatedAggregatedInventory' stepCheckSecondVariatedAggregatedInventory'
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
def test_04_VariatedAggregatedInventoryGetInventoryList(self, run=run_all_test):
"""
Same thing as test_03 with testing getInventoryList columns
"""
if not run: return
self.logMessage('Test getInventoryList and Variated Aggregated Inventory')
sequence_list = SequenceList()
# Test with a variated inventory with some aggregate
sequence_string = 'stepCreateVariatedResource \
stepCreateOrganisation1 \
stepCreateInitialMovements \
stepTic \
stepCreateItem \
stepCreateItem \
stepCreateFirstVariatedAggregatedInventory \
stepTic \
stepCheckFirstVariatedAggregatedInventory \
stepCheckExplanationTextInInventoryList \
stepCreateSecondVariatedAggregatedInventory \
stepTic \
stepCheckSecondVariatedAggregatedInventory \
stepCheckExplanationTextInInventoryList'
sequence_list.addSequenceString(sequence_string) sequence_list.addSequenceString(sequence_string)
sequence_list.play(self) sequence_list.play(self)
......
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