Commit 87639a83 authored by Jérome Perrin's avatar Jérome Perrin

introduce IAggregatedAmountList and change

TradeCondition.getAggregatedAmountList to return an AggregatedAmountList
instead of a simple list. Some XXX are left.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28075 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 95e5ea6e
...@@ -28,15 +28,21 @@ ...@@ -28,15 +28,21 @@
############################################################################## ##############################################################################
from UserList import UserList from UserList import UserList
import zope.interface
from Globals import InitializeClass from Globals import InitializeClass
from Products.PythonScripts.Utility import allow_class from Products.PythonScripts.Utility import allow_class
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from UserList import UserList
from Products.ERP5.interfaces.transformation import IAggregatedAmountList
class AggregatedAmountList(UserList): class AggregatedAmountList(UserList):
""" """
Temporary object needed to aggregate Amount value Temporary object needed to aggregate Amount value
And to calculate some report or total value And to calculate some report or total value
""" """
zope.interface.implements(IAggregatedAmountList)
meta_type = "AggregatedAmountList" meta_type = "AggregatedAmountList"
security = ClassSecurityInfo() security = ClassSecurityInfo()
# security.declareObjectPublic() # security.declareObjectPublic()
......
...@@ -88,7 +88,6 @@ class TradeCondition(Path, Transformation, XMLMatrix): ...@@ -88,7 +88,6 @@ class TradeCondition(Path, Transformation, XMLMatrix):
.getPreferredNormalResourceUseCategoryList() .getPreferredNormalResourceUseCategoryList()
# check if the existing movements are in aggregated movements # check if the existing movements are in aggregated movements
movement_to_delete_list = [] movement_to_delete_list = []
movement_to_add_list = []
for movement in existing_movement_list: for movement in existing_movement_list:
keep_movement = False keep_movement = False
# check if the movement is a generated one or entered by the user. # check if the movement is a generated one or entered by the user.
...@@ -112,8 +111,9 @@ class TradeCondition(Path, Transformation, XMLMatrix): ...@@ -112,8 +111,9 @@ class TradeCondition(Path, Transformation, XMLMatrix):
keep_movement = True keep_movement = True
if not keep_movement: if not keep_movement:
movement_to_delete_list.append(movement) movement_to_delete_list.append(movement)
movement_to_add_list = [amount for amount in aggregated_amount_list if movement_to_add_list = AggregatedAmountList(
amount.getReference() not in modified_reference_list] [amount for amount in aggregated_amount_list if
amount.getReference() not in modified_reference_list])
return {'movement_to_delete_list' : movement_to_delete_list, return {'movement_to_delete_list' : movement_to_delete_list,
'movement_to_add_list': movement_to_add_list} 'movement_to_add_list': movement_to_add_list}
...@@ -228,15 +228,20 @@ class TradeCondition(Path, Transformation, XMLMatrix): ...@@ -228,15 +228,20 @@ class TradeCondition(Path, Transformation, XMLMatrix):
**kw)) **kw))
movement_list = result movement_list = result
# remove movement that should not be created # remove amounts that should not be created, or with "incorrect" references.
final_movement_list = [] # XXX what are incorrect references ???
# getTradeModelLineComposedList should have removed duplicate reference
# in the model graph
# TODO: review this part
aggregated_amount_list = AggregatedAmountList()
for movement in movement_list: for movement in movement_list:
movement_ref = movement.getReference() movement_reference = movement.getReference()
for model_line in trade_model_line_composed_list: for model_line in trade_model_line_composed_list:
if model_line.getReference() == movement_ref and\ if model_line.getReference() == movement_reference and\
model_line.isCreateLine(): model_line.isCreateLine():
final_movement_list.append(movement) aggregated_amount_list.append(movement)
return final_movement_list
return aggregated_amount_list
security.declareProtected( Permissions.AccessContentsInformation, 'getCell') security.declareProtected( Permissions.AccessContentsInformation, 'getCell')
def getCell(self, *kw , **kwd): def getCell(self, *kw , **kwd):
......
...@@ -30,10 +30,18 @@ ...@@ -30,10 +30,18 @@
from zope.interface import Interface from zope.interface import Interface
try:
from zope.interface.common.sequence import ISequence
except ImportError:
# ISequence does not exists in old zope.interface versions
class ISequence(Interface):
pass
class ITransformation(Interface): class ITransformation(Interface):
""" """
Common Interface to implementing querying of Indirect Amount Common Interface to implementing querying of indirect amount
Models (TaxModelLine, InvoiceModelLine, etc) shall be based on this models (TaxModelLine, InvoiceModelLine, etc) shall be based on this
interface interface
""" """
...@@ -48,17 +56,16 @@ class ITransformation(Interface): ...@@ -48,17 +56,16 @@ class ITransformation(Interface):
rounding - boolean argument, which controls if rounding shall be applied on rounding - boolean argument, which controls if rounding shall be applied on
generated movements or not generated movements or not
Returns list of instance of AggregatedAmountList class Returns an instance implementing IAggregatedAmountList.
Note: This method shall be linear in case if context is order, line, Note: This method shall be linear in case if context is order, line,
applied rule or movement. In case of built delivery this method shall applied rule or movement. In case of built delivery this method shall
be wise enough to CORRECTLY un-linearise calculation, eg. tax is be wise enough to CORRECTLY un-linearise calculation, eg. tax is
time dependent, paysheet build from invoices. time dependent, paysheet build from invoices.
""" """
pass
def updateAggregatedAmountList(context, movement_list=None, rounding=False): def updateAggregatedAmountList(context, movement_list=None, rounding=False):
"""Updates existing movement and returns new or deleted if any according to model """Updates existing movements and returns new or deleted if any according to model
context - represents object on which update shall happen context - represents object on which update shall happen
...@@ -68,9 +75,18 @@ class ITransformation(Interface): ...@@ -68,9 +75,18 @@ class ITransformation(Interface):
rounding - boolean argument, which controls if rounding shall be applied on rounding - boolean argument, which controls if rounding shall be applied on
generated movements or not generated movements or not
Returns a dictionary of list of instances of AggregatedAmountList class. Returns a dictionary with two keys:
Dictionary contain lists described by keys: * movement_to_add_list - an instance of IAggregatedAmountList for amounts
* movement_to_add_list - list for movements which shall be added that have to be added in the context.
* movement_to_delete_list - list of movements which shall be deleted FIXME: this is not 'movement'
* movement_to_delete_list - a list of movements from movement_list or from the
context that shall be deleted.
""" """
pass
class IAggregatedAmountList(ISequence):
"""An Aggregated Amount List is a list of amounts aggregated together.
It is a sequence of objects implementing IAmount interface.
"""
...@@ -61,6 +61,12 @@ implements_tuple_list = [ ...@@ -61,6 +61,12 @@ implements_tuple_list = [
class TestERP5Interfaces(ERP5TypeTestCase): class TestERP5Interfaces(ERP5TypeTestCase):
"""Tests implementation of interfaces""" """Tests implementation of interfaces"""
def test_AggregatedAmountList_implements_IAggregatedAmountList(self):
# AggregatedAmountList is not a document
from Products.ERP5.interfaces.transformation import IAggregatedAmountList
from Products.ERP5.AggregatedAmountList import AggregatedAmountList
verifyClass(IAggregatedAmountList, AggregatedAmountList)
def makeTestMethod(document, interface): def makeTestMethod(document, interface):
"""Common method which checks if documents implements interface""" """Common method which checks if documents implements interface"""
def testMethod(self): def testMethod(self):
......
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