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 @@
#
##############################################################################
from Acquisition import aq_base
from AccessControl import ClassSecurityInfo
from Acquisition import aq_base
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
for each variation of a resource in an inventory line.
......@@ -42,7 +41,6 @@ class InventoryCell(DeliveryCell):
meta_type = 'ERP5 Inventory Cell'
portal_type = 'Inventory Cell'
add_permission = Permissions.AddPortalContent
isInventoryMovement = ConstantGetter('isInventoryMovement', value=True)
# Declarative security
security = ClassSecurityInfo()
......@@ -50,25 +48,25 @@ class InventoryCell(DeliveryCell):
# Declarative properties
property_sheets = ( PropertySheet.Base
, PropertySheet.XMLObject
, PropertySheet.CategoryCore
, PropertySheet.Amount
, PropertySheet.InventoryMovement
, PropertySheet.Task
, PropertySheet.Movement
, PropertySheet.Price
, PropertySheet.Predicate
, PropertySheet.MappedValue
, PropertySheet.ItemAggregation
)
security.declareProtected(Permissions.AccessContentsInformation, 'getTotalInventory')
def getTotalInventory(self):
security.declareProtected(Permissions.AccessContentsInformation,
'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):
"""
Computes a quantity which allows to reach inventory
......@@ -79,12 +77,20 @@ class InventoryCell(DeliveryCell):
if quantity not in (0.0, 0, None):
return quantity
# Make sure inventory is defined somewhere (here or parent)
if getattr(aq_base(self), 'inventory', None) is None:
return 0.0 # No inventory defined, so no quantity
return self.getInventory()
inventory = getattr(aq_base(self), 'inventory', None)
if inventory is not None:
return inventory
return quantity
else:
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
security.declareProtected(Permissions.AccessContentsInformation, 'getConvertedInventory')
def getConvertedInventory(self):
......@@ -93,12 +99,3 @@ class InventoryCell(DeliveryCell):
no inventory was defined.
"""
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
from Acquisition import aq_base
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 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.
"""
meta_type = 'ERP5 Inventory Line'
portal_type = 'Inventory Line'
add_permission = Permissions.AddPortalContent
isInventoryMovement = ConstantGetter('isInventoryMovement', value=True)
# Declarative security
security = ClassSecurityInfo()
......@@ -54,25 +54,20 @@ class InventoryLine(DeliveryLine):
, PropertySheet.Amount
, PropertySheet.InventoryMovement
, PropertySheet.Task
, PropertySheet.Price
, PropertySheet.Arrow
, PropertySheet.Movement
, PropertySheet.VariationRange
, PropertySheet.ItemAggregation
)
security.declareProtected(Permissions.AccessContentsInformation, 'getTotalInventory')
def getTotalInventory(self):
security.declareProtected(Permissions.AccessContentsInformation,
'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():
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
cell_range = XMLMatrix.getCellRange(self, base_id=base_id)
return (cell_range is not None and len(cell_range) > 0)
security.declareProtected(Permissions.AccessContentsInformation,
'getQuantity')
......@@ -83,7 +78,7 @@ class InventoryLine(DeliveryLine):
if not self.hasCellContent():
# First check if quantity already exists
quantity = self._baseGetQuantity()
if quantity not in (0.0,0,None):
if quantity not in (0.0, 0, None):
return quantity
# Make sure inventory is defined somewhere (here or parent)
inventory = getattr(aq_base(self), 'inventory', None)
......@@ -93,6 +88,34 @@ class InventoryLine(DeliveryLine):
else:
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
security.declareProtected(Permissions.AccessContentsInformation,
'getConvertedInventory')
......@@ -111,12 +134,3 @@ class InventoryLine(DeliveryLine):
Take into account efficiency in converted target quantity
"""
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