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 @@
##############################################################################
from UserList import UserList
import zope.interface
from Globals import InitializeClass
from Products.PythonScripts.Utility import allow_class
from AccessControl import ClassSecurityInfo
from UserList import UserList
from Products.ERP5.interfaces.transformation import IAggregatedAmountList
class AggregatedAmountList(UserList):
"""
Temporary object needed to aggregate Amount value
And to calculate some report or total value
"""
zope.interface.implements(IAggregatedAmountList)
meta_type = "AggregatedAmountList"
security = ClassSecurityInfo()
# security.declareObjectPublic()
......
......@@ -88,7 +88,6 @@ class TradeCondition(Path, Transformation, XMLMatrix):
.getPreferredNormalResourceUseCategoryList()
# check if the existing movements are in aggregated movements
movement_to_delete_list = []
movement_to_add_list = []
for movement in existing_movement_list:
keep_movement = False
# check if the movement is a generated one or entered by the user.
......@@ -112,8 +111,9 @@ class TradeCondition(Path, Transformation, XMLMatrix):
keep_movement = True
if not keep_movement:
movement_to_delete_list.append(movement)
movement_to_add_list = [amount for amount in aggregated_amount_list if
amount.getReference() not in modified_reference_list]
movement_to_add_list = AggregatedAmountList(
[amount for amount in aggregated_amount_list if
amount.getReference() not in modified_reference_list])
return {'movement_to_delete_list' : movement_to_delete_list,
'movement_to_add_list': movement_to_add_list}
......@@ -228,15 +228,20 @@ class TradeCondition(Path, Transformation, XMLMatrix):
**kw))
movement_list = result
# remove movement that should not be created
final_movement_list = []
# remove amounts that should not be created, or with "incorrect" references.
# 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:
movement_ref = movement.getReference()
movement_reference = movement.getReference()
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():
final_movement_list.append(movement)
return final_movement_list
aggregated_amount_list.append(movement)
return aggregated_amount_list
security.declareProtected( Permissions.AccessContentsInformation, 'getCell')
def getCell(self, *kw , **kwd):
......
......@@ -30,10 +30,18 @@
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):
"""
Common Interface to implementing querying of Indirect Amount
Models (TaxModelLine, InvoiceModelLine, etc) shall be based on this
Common Interface to implementing querying of indirect amount
models (TaxModelLine, InvoiceModelLine, etc) shall be based on this
interface
"""
......@@ -48,17 +56,16 @@ class ITransformation(Interface):
rounding - boolean argument, which controls if rounding shall be applied on
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,
applied rule or movement. In case of built delivery this method shall
be wise enough to CORRECTLY un-linearise calculation, eg. tax is
time dependent, paysheet build from invoices.
"""
pass
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
......@@ -68,9 +75,18 @@ class ITransformation(Interface):
rounding - boolean argument, which controls if rounding shall be applied on
generated movements or not
Returns a dictionary of list of instances of AggregatedAmountList class.
Dictionary contain lists described by keys:
* movement_to_add_list - list for movements which shall be added
* movement_to_delete_list - list of movements which shall be deleted
Returns a dictionary with two keys:
* movement_to_add_list - an instance of IAggregatedAmountList for amounts
that have to be added in the context.
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 = [
class TestERP5Interfaces(ERP5TypeTestCase):
"""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):
"""Common method which checks if documents implements interface"""
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