Commit e29e5b35 authored by Gabriel Monnerat's avatar Gabriel Monnerat

Movement: Add isMovingItem method to be possible check if the object is moving physically or not

erp5_mysql_innodb_catalog : Use isMovingItem instead of isAccountable to be possible index only movements that are moving physically

Movement: by default Movement should returns false. Otherwise it will index not expected objects in item table

erp5_mysql_innodb_catalog: check if there are movement items instead of aggregated uids
parent fa24a5da
...@@ -55,9 +55,15 @@ class DummyMovement(Movement): ...@@ -55,9 +55,15 @@ class DummyMovement(Movement):
) )
def isAccountable(self): def isAccountable(self):
"""Our dummy movement are always accountable.""" """Our dummy movements are always accountable, unless is_accountable
attribute is set."""
return getattr(self, 'is_accountable', 1) return getattr(self, 'is_accountable', 1)
def isMovingItem(self, item):
"""Our dummy movements are always moving items, unless is_moving_item
attribute is set."""
return getattr(self, 'is_moving_item', 1)
# In order to make tests work with dummy movements that are not contained in # In order to make tests work with dummy movements that are not contained in
# dummy deliveries, we must borrow a few methods from DummyDelivery. # dummy deliveries, we must borrow a few methods from DummyDelivery.
......
...@@ -120,7 +120,7 @@ ...@@ -120,7 +120,7 @@
</tuple> </tuple>
<tuple> <tuple>
<string>destination_section_title</string> <string>destination_section_title</string>
<string>Delivered To</string> <string>Delivered to</string>
</tuple> </tuple>
<tuple> <tuple>
<string>delivery.start_date</string> <string>delivery.start_date</string>
......
...@@ -121,3 +121,12 @@ class AccountingTransactionLine(DeliveryLine): ...@@ -121,3 +121,12 @@ class AccountingTransactionLine(DeliveryLine):
self._baseSetGroupingDate(value) self._baseSetGroupingDate(value)
self.reindexObject() self.reindexObject()
security.declareProtected(Permissions.AccessContentsInformation,
'isMovingItem')
def isMovingItem(self, item):
"""
We often like to aggregate items to Accounting Transaction Line
for traceability, but this movements does not physically move the item
to the destination of this account.
"""
return False
...@@ -102,13 +102,14 @@ class DeliveryLine(Movement, XMLObject, XMLMatrix, ImmobilisationMovement): ...@@ -102,13 +102,14 @@ class DeliveryLine(Movement, XMLObject, XMLMatrix, ImmobilisationMovement):
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'isAccountable') 'isAccountable')
def isAccountable(self): def isAccountable(self):
""" """To avoid duplicate docstring. Please read movement interface."""
Returns 1 if this needs to be accounted
Only account movements which are not associated to a delivery
Whenever delivery is there, delivery has priority
"""
return self.getParentValue().isAccountable() and (not self.hasCellContent()) return self.getParentValue().isAccountable() and (not self.hasCellContent())
security.declareProtected(Permissions.AccessContentsInformation,
'isMovingItem')
def isMovingItem(self, item):
return self.isAccountable()
def _getTotalPrice(self, default=0.0, context=None, fast=0): def _getTotalPrice(self, default=0.0, context=None, fast=0):
""" """
Returns the total price for this line, this line contains, or the cells it contains. Returns the total price for this line, this line contains, or the cells it contains.
...@@ -210,6 +211,13 @@ class DeliveryLine(Movement, XMLObject, XMLMatrix, ImmobilisationMovement): ...@@ -210,6 +211,13 @@ class DeliveryLine(Movement, XMLObject, XMLMatrix, ImmobilisationMovement):
portal_type = self.getPortalMovementTypeList() portal_type = self.getPortalMovementTypeList()
return len(self.contentValues(filter={'portal_type': portal_type})) == 0 return len(self.contentValues(filter={'portal_type': portal_type})) == 0
security.declareProtected(Permissions.AccessContentsInformation, 'getMovedItemUidList')
def getMovedItemUidList(self):
"""This method returns an uid list of items
"""
return [item.getUid() for item in self.getAggregateValueList() \
if self.isMovingItem(item)]
security.declareProtected( Permissions.AccessContentsInformation, 'getCellValueList' ) security.declareProtected( Permissions.AccessContentsInformation, 'getCellValueList' )
def getCellValueList(self, base_id='movement'): def getCellValueList(self, base_id='movement'):
""" """
......
...@@ -213,6 +213,22 @@ class Movement(XMLObject, Amount, CompositionMixin, AmountGeneratorMixin): ...@@ -213,6 +213,22 @@ class Movement(XMLObject, Amount, CompositionMixin, AmountGeneratorMixin):
def isMovement(self): def isMovement(self):
return 1 return 1
security.declareProtected(Permissions.AccessContentsInformation, 'isAccountable')
def isAccountable(self):
return True
security.declareProtected(Permissions.AccessContentsInformation,
'isMovingItem')
def isMovingItem(self, item):
return False
security.declareProtected(Permissions.AccessContentsInformation, 'getMovedItemUidList')
def getMovedItemUidList(self):
"""This method returns an uid list of items
"""
return [item.getUid() for item in self.getAggregateValueList() \
if self.isMovingItem(item)]
# Pricing methods # Pricing methods
# _getPrice is defined in the order / delivery # _getPrice is defined in the order / delivery
# Pricing mehod # Pricing mehod
......
...@@ -23,7 +23,8 @@ getDestinationSectionUid\r\n ...@@ -23,7 +23,8 @@ getDestinationSectionUid\r\n
getResourceUid\r\n getResourceUid\r\n
getVariationText\r\n getVariationText\r\n
getSimulationState\r\n getSimulationState\r\n
getAggregateUidList</string> </value> getAggregateUidList\r\n
getMovedItemUidList</string> </value>
</item> </item>
<item> <item>
<key> <string>cache_time_</string> </key> <key> <string>cache_time_</string> </key>
...@@ -75,10 +76,9 @@ WHERE\n ...@@ -75,10 +76,9 @@ WHERE\n
\n \n
<dtml-let movement_list="[]" uid_dict="{}">\n <dtml-let movement_list="[]" uid_dict="{}">\n
<dtml-in prefix="loop" expr="_.range(_.len(uid))">\n <dtml-in prefix="loop" expr="_.range(_.len(uid))">\n
<dtml-if "isMovement[loop_item] and isAccountable[loop_item] and getAggregateUidList[loop_item]">\n <dtml-if "isMovement[loop_item] and isAccountable[loop_item] and getMovedItemUidList[loop_item]">\n
<dtml-call expr="uid_dict.update({uid[loop_item]: uid_dict.get(uid[loop_item], -1) + 1})">\n <dtml-call expr="uid_dict.update({uid[loop_item]: uid_dict.get(uid[loop_item], -1) + 1})">\n
<dtml-call expr="movement_list.append(loop_item)">\n <dtml-call expr="movement_list.append(loop_item)">\n
\n
</dtml-if>\n </dtml-if>\n
</dtml-in>\n </dtml-in>\n
<dtml-if expr="_.len(movement_list) > 0">\n <dtml-if expr="_.len(movement_list) > 0">\n
...@@ -86,8 +86,8 @@ REPLACE INTO\n ...@@ -86,8 +86,8 @@ REPLACE INTO\n
item\n item\n
VALUES\n VALUES\n
<dtml-in prefix="loop" expr="movement_list">\n <dtml-in prefix="loop" expr="movement_list">\n
<dtml-in "getAggregateUidList[loop_item]">\n <dtml-in expr="getMovedItemUidList[loop_item]">\n
\n \n
( \n ( \n
<dtml-call expr="uid_dict.update({uid[loop_item]: uid_dict.get(uid[loop_item], -1) + 1})">\n <dtml-call expr="uid_dict.update({uid[loop_item]: uid_dict.get(uid[loop_item], -1) + 1})">\n
<dtml-sqlvar expr="uid[loop_item]" type="int">,\n <dtml-sqlvar expr="uid[loop_item]" type="int">,\n
...@@ -105,9 +105,7 @@ VALUES\n ...@@ -105,9 +105,7 @@ VALUES\n
<dtml-if sequence-end><dtml-else>,</dtml-if>\n <dtml-if sequence-end><dtml-else>,</dtml-if>\n
</dtml-in>\n </dtml-in>\n
</dtml-if>\n </dtml-if>\n
</dtml-let>\n </dtml-let>
\n
]]></string> </value> ]]></string> </value>
</item> </item>
......
...@@ -254,3 +254,16 @@ class IMovement(IProductionMovement, IArrowBase): ...@@ -254,3 +254,16 @@ class IMovement(IProductionMovement, IArrowBase):
Returns True if this movement should be indexed in the Returns True if this movement should be indexed in the
stock table of the catalog, False else. stock table of the catalog, False else.
""" """
def isAccountable():
"""
Returns True if this movement impacts the stock levels of source and
destination.
"""
def isMovingItem(item):
"""
Returns True if this movement physically move the item from a tracking
point of view.
"""
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