Commit 57e9945f authored by Titouan Soulard's avatar Titouan Soulard

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

parent c52c4ec9
Pipeline #36857 failed with stage
in 0 seconds
......@@ -30,11 +30,11 @@ from Acquisition import aq_base
from AccessControl import ClassSecurityInfo
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.MappedValue import MappedValue
from erp5.component.document.Amount import Amount
class InventoryCell(DeliveryCell):
class InventoryCell(MappedValue, Amount):
"""
An InventoryCell allows to define specific inventory
for each variation of a resource in an inventory line.
......@@ -42,7 +42,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()
......@@ -68,23 +67,6 @@ class InventoryCell(DeliveryCell):
"""
return self.getInventory()
security.declareProtected(Permissions.AccessContentsInformation, 'getQuantity')
def getQuantity(self):
"""
Computes a quantity which allows to reach inventory
"""
if not self.hasCellContent():
# First check if quantity already exists
quantity = self._baseGetQuantity()
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()
else:
return None
# Inventory cataloging
security.declareProtected(Permissions.AccessContentsInformation, 'getConvertedInventory')
def getConvertedInventory(self):
......@@ -93,12 +75,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)
......@@ -43,7 +43,9 @@
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
<tuple>
<string>W: 29, 0: Unused aq_base imported from Acquisition (unused-import)</string>
</tuple>
</value>
</item>
<item>
......
......@@ -27,21 +27,19 @@
##############################################################################
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()
......@@ -52,14 +50,21 @@ class InventoryLine(DeliveryLine):
, PropertySheet.XMLObject
, PropertySheet.CategoryCore
, PropertySheet.Amount
, PropertySheet.InventoryMovement
, PropertySheet.Task
, PropertySheet.Arrow
, PropertySheet.Movement
, PropertySheet.VariationRange
, PropertySheet.ItemAggregation
)
security.declareProtected(Permissions.AccessContentsInformation,
'hasCellContent')
def hasCellContent(self, base_id="movement"):
"""
Returns True is the line contains cells.
"""
cell_range = XMLMatrix.getCellRange(self, base_id=base_id)
return (cell_range is not None and len(cell_range) > 0)
security.declareProtected(Permissions.AccessContentsInformation, 'getTotalInventory')
def getTotalInventory(self):
"""
......@@ -74,24 +79,19 @@ class InventoryLine(DeliveryLine):
total_quantity += cell.getInventory()
return total_quantity
security.declareProtected(Permissions.AccessContentsInformation,
'getQuantity')
def getQuantity(self):
security.declareProtected(Permissions.AccessContentsInformation, 'getTotalPrice')
def getTotalPrice(self):
"""
Computes a quantity which allows to reach inventory
Returns the price if no cell or the total price if cells
"""
if not self.hasCellContent():
# First check if quantity already exists
quantity = self._baseGetQuantity()
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)
if inventory is not None:
return inventory
return quantity
return self.getPrice()
else:
return None
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,
......@@ -111,12 +111,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