Commit 029be6db authored by Titouan Soulard's avatar Titouan Soulard

erp5_core: Inventory Lines and Cells are not Delivery Lines and Cells

Inventories now contains Offset Lines and Cells which are the actual inventory
movements. Old Lines and Cells are simply a report from which offset is
calculated.
parent dd1e8057
...@@ -26,15 +26,14 @@ ...@@ -26,15 +26,14 @@
# #
############################################################################## ##############################################################################
from Acquisition import aq_base
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Acquisition import aq_base
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.Accessor.Constant import PropertyGetter as ConstantGetter
from erp5.component.document.DeliveryCell import DeliveryCell from erp5.component.document.Amount import Amount
class InventoryCell(DeliveryCell): class InventoryCell(Amount):
""" """
An InventoryCell allows to define specific inventory An InventoryCell allows to define specific inventory
for each variation of a resource in an inventory line. for each variation of a resource in an inventory line.
...@@ -42,7 +41,6 @@ class InventoryCell(DeliveryCell): ...@@ -42,7 +41,6 @@ class InventoryCell(DeliveryCell):
meta_type = 'ERP5 Inventory Cell' meta_type = 'ERP5 Inventory Cell'
portal_type = 'Inventory Cell' portal_type = 'Inventory Cell'
add_permission = Permissions.AddPortalContent add_permission = Permissions.AddPortalContent
isInventoryMovement = ConstantGetter('isInventoryMovement', value=True)
# Declarative security # Declarative security
security = ClassSecurityInfo() security = ClassSecurityInfo()
...@@ -50,25 +48,25 @@ class InventoryCell(DeliveryCell): ...@@ -50,25 +48,25 @@ class InventoryCell(DeliveryCell):
# Declarative properties # Declarative properties
property_sheets = ( PropertySheet.Base property_sheets = ( PropertySheet.Base
, PropertySheet.XMLObject
, PropertySheet.CategoryCore , PropertySheet.CategoryCore
, PropertySheet.Amount , PropertySheet.Amount
, PropertySheet.InventoryMovement , PropertySheet.InventoryMovement
, PropertySheet.Task , PropertySheet.Task
, PropertySheet.Movement
, PropertySheet.Price , PropertySheet.Price
, PropertySheet.Predicate
, PropertySheet.MappedValue
, PropertySheet.ItemAggregation , PropertySheet.ItemAggregation
) )
security.declareProtected(Permissions.AccessContentsInformation, 'getTotalInventory') security.declareProtected(Permissions.AccessContentsInformation,
def getTotalInventory(self): 'hasCellContent')
def hasCellContent(self, base_id="movement"):
""" """
Returns the inventory, as cells are not supposed to contain more cells. A cell cannot contain other Cells.
""" """
return self.getInventory() return False
security.declareProtected(Permissions.AccessContentsInformation, 'getQuantity') security.declareProtected(Permissions.AccessContentsInformation,
'getQuantity')
def getQuantity(self): def getQuantity(self):
""" """
Computes a quantity which allows to reach inventory Computes a quantity which allows to reach inventory
...@@ -79,12 +77,20 @@ class InventoryCell(DeliveryCell): ...@@ -79,12 +77,20 @@ class InventoryCell(DeliveryCell):
if quantity not in (0.0, 0, None): if quantity not in (0.0, 0, None):
return quantity return quantity
# Make sure inventory is defined somewhere (here or parent) # Make sure inventory is defined somewhere (here or parent)
if getattr(aq_base(self), 'inventory', None) is None: inventory = getattr(aq_base(self), 'inventory', None)
return 0.0 # No inventory defined, so no quantity if inventory is not None:
return self.getInventory() return inventory
return quantity
else: else:
return None return None
security.declareProtected(Permissions.AccessContentsInformation, 'getTotalInventory')
def getTotalInventory(self):
"""
Returns the inventory, as cells are not supposed to contain more cells.
"""
return self.getInventory()
# Inventory cataloging # Inventory cataloging
security.declareProtected(Permissions.AccessContentsInformation, 'getConvertedInventory') security.declareProtected(Permissions.AccessContentsInformation, 'getConvertedInventory')
def getConvertedInventory(self): def getConvertedInventory(self):
...@@ -93,12 +99,3 @@ class InventoryCell(DeliveryCell): ...@@ -93,12 +99,3 @@ class InventoryCell(DeliveryCell):
no inventory was defined. no inventory was defined.
""" """
return self.getInventory() # XXX quantity unit is missing return self.getInventory() # XXX quantity unit is missing
def reindexObject(self, *args, **kw):
"""
Reindex Inventory too
"""
DeliveryCell.reindexObject(self, *args, **kw)
# No need to reindex recursively as Delivery does, so call
# _reindexObject() directly
self.getRootDeliveryValue()._reindexObject(*args, **kw)
...@@ -30,18 +30,18 @@ from AccessControl import ClassSecurityInfo ...@@ -30,18 +30,18 @@ from AccessControl import ClassSecurityInfo
from Acquisition import aq_base from Acquisition import aq_base
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
from erp5.component.document.DeliveryLine import DeliveryLine from Products.ERP5Type.XMLMatrix import XMLMatrix
from erp5.component.document.Movement import Movement from erp5.component.document.Movement import Movement
from Products.ERP5Type.Accessor.Constant import PropertyGetter as ConstantGetter from erp5.component.document.Amount import Amount
class InventoryLine(DeliveryLine): class InventoryLine(XMLMatrix, Amount):
""" """
An Inventory Line describe the inventory of a resource, by variations. An Inventory Line describe the inventory of a resource, by variations.
""" """
meta_type = 'ERP5 Inventory Line' meta_type = 'ERP5 Inventory Line'
portal_type = 'Inventory Line' portal_type = 'Inventory Line'
add_permission = Permissions.AddPortalContent add_permission = Permissions.AddPortalContent
isInventoryMovement = ConstantGetter('isInventoryMovement', value=True)
# Declarative security # Declarative security
security = ClassSecurityInfo() security = ClassSecurityInfo()
...@@ -54,25 +54,20 @@ class InventoryLine(DeliveryLine): ...@@ -54,25 +54,20 @@ class InventoryLine(DeliveryLine):
, PropertySheet.Amount , PropertySheet.Amount
, PropertySheet.InventoryMovement , PropertySheet.InventoryMovement
, PropertySheet.Task , PropertySheet.Task
, PropertySheet.Price
, PropertySheet.Arrow , PropertySheet.Arrow
, PropertySheet.Movement
, PropertySheet.VariationRange , PropertySheet.VariationRange
, PropertySheet.ItemAggregation , PropertySheet.ItemAggregation
) )
security.declareProtected(Permissions.AccessContentsInformation, 'getTotalInventory') security.declareProtected(Permissions.AccessContentsInformation,
def getTotalInventory(self): 'hasCellContent')
def hasCellContent(self, base_id="movement"):
""" """
Returns the inventory if no cell or the total inventory if cells Returns True is the line contains cells.
""" """
if not self.hasCellContent(): cell_range = XMLMatrix.getCellRange(self, base_id=base_id)
return self.getInventory() return (cell_range is not None and len(cell_range) > 0)
else:
total_quantity = 0.0
for cell in self.getCellValueList(base_id='movement'):
if cell.getInventory() is not None:
total_quantity += cell.getInventory()
return total_quantity
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getQuantity') 'getQuantity')
...@@ -83,7 +78,7 @@ class InventoryLine(DeliveryLine): ...@@ -83,7 +78,7 @@ class InventoryLine(DeliveryLine):
if not self.hasCellContent(): if not self.hasCellContent():
# First check if quantity already exists # First check if quantity already exists
quantity = self._baseGetQuantity() quantity = self._baseGetQuantity()
if quantity not in (0.0,0,None): if quantity not in (0.0, 0, None):
return quantity return quantity
# Make sure inventory is defined somewhere (here or parent) # Make sure inventory is defined somewhere (here or parent)
inventory = getattr(aq_base(self), 'inventory', None) inventory = getattr(aq_base(self), 'inventory', None)
...@@ -93,6 +88,34 @@ class InventoryLine(DeliveryLine): ...@@ -93,6 +88,34 @@ class InventoryLine(DeliveryLine):
else: else:
return None return None
security.declareProtected(Permissions.AccessContentsInformation, 'getTotalInventory')
def getTotalInventory(self):
"""
Returns the inventory if no cell or the total inventory if cells
"""
if not self.hasCellContent():
return self.getInventory()
else:
total_quantity = 0.0
for cell in self.getCellValueList(base_id='movement'):
if cell.getInventory() is not None:
total_quantity += cell.getInventory()
return total_quantity
security.declareProtected(Permissions.AccessContentsInformation, 'getTotalPrice')
def getTotalPrice(self):
"""
Returns the price if no cell or the total price if cells
"""
if not self.hasCellContent():
return self.getPrice()
else:
total_price = 0.0
for cell in self.getCellValueList(base_id='movement'):
if cell.getPrice() is not None:
total_price += cell.getPrice()
return total_price
# Inventory cataloging # Inventory cataloging
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getConvertedInventory') 'getConvertedInventory')
...@@ -111,12 +134,3 @@ class InventoryLine(DeliveryLine): ...@@ -111,12 +134,3 @@ class InventoryLine(DeliveryLine):
Take into account efficiency in converted target quantity Take into account efficiency in converted target quantity
""" """
return Movement.getInventoriatedQuantity(self) return Movement.getInventoriatedQuantity(self)
def reindexObject(self, *args, **kw):
"""
Reindex Inventory too
"""
DeliveryLine.reindexObject(self, *args, **kw)
# No need to reindex recursively as Delivery does, so call
# _reindexObject() directly
self.getRootDeliveryValue()._reindexObject(*args, **kw)
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