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):
)
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)
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
# dummy deliveries, we must borrow a few methods from DummyDelivery.
......
......@@ -120,7 +120,7 @@
</tuple>
<tuple>
<string>destination_section_title</string>
<string>Delivered To</string>
<string>Delivered to</string>
</tuple>
<tuple>
<string>delivery.start_date</string>
......
......@@ -121,3 +121,12 @@ class AccountingTransactionLine(DeliveryLine):
self._baseSetGroupingDate(value)
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):
security.declareProtected(Permissions.AccessContentsInformation,
'isAccountable')
def isAccountable(self):
"""
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
"""
"""To avoid duplicate docstring. Please read movement interface."""
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):
"""
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):
portal_type = self.getPortalMovementTypeList()
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' )
def getCellValueList(self, base_id='movement'):
"""
......
......@@ -213,6 +213,22 @@ class Movement(XMLObject, Amount, CompositionMixin, AmountGeneratorMixin):
def isMovement(self):
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
# _getPrice is defined in the order / delivery
# Pricing mehod
......
......@@ -23,7 +23,8 @@ getDestinationSectionUid\r\n
getResourceUid\r\n
getVariationText\r\n
getSimulationState\r\n
getAggregateUidList</string> </value>
getAggregateUidList\r\n
getMovedItemUidList</string> </value>
</item>
<item>
<key> <string>cache_time_</string> </key>
......@@ -75,10 +76,9 @@ WHERE\n
\n
<dtml-let movement_list="[]" uid_dict="{}">\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="movement_list.append(loop_item)">\n
\n
</dtml-if>\n
</dtml-in>\n
<dtml-if expr="_.len(movement_list) > 0">\n
......@@ -86,8 +86,8 @@ REPLACE INTO\n
item\n
VALUES\n
<dtml-in prefix="loop" expr="movement_list">\n
<dtml-in "getAggregateUidList[loop_item]">\n
\n
<dtml-in expr="getMovedItemUidList[loop_item]">\n
\n
( \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
......@@ -105,9 +105,7 @@ VALUES\n
<dtml-if sequence-end><dtml-else>,</dtml-if>\n
</dtml-in>\n
</dtml-if>\n
</dtml-let>\n
\n
</dtml-let>
]]></string> </value>
</item>
......
......@@ -254,3 +254,16 @@ class IMovement(IProductionMovement, IArrowBase):
Returns True if this movement should be indexed in the
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