Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
139
Merge Requests
139
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
erp5
Commits
a6b1b63f
Commit
a6b1b63f
authored
May 23, 2016
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Plain Diff
amount_generator: revert last change in testApparelTransformation
parents
1abc4bac
5b3055d8
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
38 deletions
+29
-38
product/ERP5/Document/TradeCondition.py
product/ERP5/Document/TradeCondition.py
+1
-1
product/ERP5/GeneratedAmountList.py
product/ERP5/GeneratedAmountList.py
+23
-2
product/ERP5/mixin/amount_generator.py
product/ERP5/mixin/amount_generator.py
+4
-34
product/ERP5/tests/testERP5Interfaces.py
product/ERP5/tests/testERP5Interfaces.py
+1
-1
No files found.
product/ERP5/Document/TradeCondition.py
View file @
a6b1b63f
...
...
@@ -39,7 +39,7 @@ from Products.ERP5Type import Permissions, PropertySheet, interfaces
from
Products.ERP5Type.Utils
import
deprecated
from
Products.ERP5.mixin.composition
import
_getEffectiveModel
from
Products.ERP5.Document.Transformation
import
Transformation
from
Products.ERP5.
AggregatedAmountList
import
Aggreg
atedAmountList
from
Products.ERP5.
GeneratedAmountList
import
Gener
atedAmountList
from
Products.ERP5.Document.MappedValue
import
MappedValue
from
Products.ERP5.mixin.amount_generator
import
AmountGeneratorMixin
from
Products.ERP5.mixin.variated
import
VariatedMixin
...
...
product/ERP5/
Aggreg
atedAmountList.py
→
product/ERP5/
Gener
atedAmountList.py
View file @
a6b1b63f
...
...
@@ -31,7 +31,7 @@ import zope.interface
from
AccessControl
import
allow_class
from
Products.ERP5Type
import
interfaces
class
Aggreg
atedAmountList
(
list
):
class
Gener
atedAmountList
(
list
):
"""
Temporary object needed to aggregate Amount value
And to calculate some report or total value
...
...
@@ -60,4 +60,25 @@ class AggregatedAmountList(list):
result
+=
duration
return
result
allow_class
(
AggregatedAmountList
)
def
aggregate
(
self
):
# XXX: Do we handle rounding correctly ?
# What to do if only total price is rounded ??
aggregate_dict
=
{}
result_list
=
self
.
__class__
()
for
amount
in
self
:
key
=
(
amount
.
getPrice
(),
amount
.
getEfficiency
(),
amount
.
getReference
(),
amount
.
categories
)
aggregate
=
aggregate_dict
.
get
(
key
)
if
aggregate
is
None
:
aggregate_dict
[
key
]
=
[
amount
,
amount
.
getQuantity
()]
result_list
.
append
(
amount
)
else
:
aggregate
[
1
]
+=
amount
.
getQuantity
()
for
amount
,
quantity
in
aggregate_dict
.
itervalues
():
# Before we ignore 'quantity==0' amount here for better performance,
# but it is not a good idea, especially when the first expand causes
# non-zero quantity and then quantity becomes zero.
amount
.
_setQuantity
(
quantity
)
return
result_list
allow_class
(
GeneratedAmountList
)
product/ERP5/mixin/amount_generator.py
View file @
a6b1b63f
...
...
@@ -32,7 +32,7 @@ import zope.interface
from
AccessControl
import
ClassSecurityInfo
from
Products.ERP5Type.Globals
import
InitializeClass
from
Acquisition
import
aq_base
,
Implicit
from
Products.ERP5.
AggregatedAmountList
import
Aggreg
atedAmountList
from
Products.ERP5.
GeneratedAmountList
import
Gener
atedAmountList
from
Products.ERP5Type
import
Permissions
,
interfaces
from
Products.ERP5Type.TransactionalVariable
import
getTransactionalVariable
from
Products.ERP5.Document.MappedValue
import
MappedValue
...
...
@@ -281,7 +281,7 @@ class AmountGeneratorMixin:
portal
.
getPortalAmountGeneratorCellTypeList
()
# Set empty result by default
result
=
Aggreg
atedAmountList
()
result
=
Gener
atedAmountList
()
args
=
(
getTransactionalVariable
().
setdefault
(
"amount_generator.BaseAmountDict"
,
{}),
...
...
@@ -503,42 +503,12 @@ class AmountGeneratorMixin:
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
'getAggregatedAmountList'
)
def
getAggregatedAmountList
(
self
,
amount_list
=
None
,
rounding
=
False
,
amount_generator_type_list
=
None
,
generate_empty_amounts
=
True
):
def
getAggregatedAmountList
(
self
,
*
args
,
**
kw
):
"""
Implementation of a generic transformation algorith which is
applicable to payroll, tax generation and BOMs. Return the
list of amounts with aggregation.
"""
generated_amount_list
=
self
.
getGeneratedAmountList
(
amount_list
=
amount_list
,
rounding
=
rounding
,
amount_generator_type_list
=
amount_generator_type_list
)
# XXX: Do we handle rounding correctly ?
# What to do if only total price is rounded ??
aggregate_dict
=
{}
result_list
=
AggregatedAmountList
()
for
amount
in
generated_amount_list
:
key
=
(
amount
.
getPrice
(),
amount
.
getEfficiency
(),
amount
.
getReference
(),
amount
.
categories
)
aggregate
=
aggregate_dict
.
get
(
key
)
if
aggregate
is
None
:
aggregate_dict
[
key
]
=
[
amount
,
amount
.
getQuantity
()]
result_list
.
append
(
amount
)
else
:
aggregate
[
1
]
+=
amount
.
getQuantity
()
for
amount
,
quantity
in
aggregate_dict
.
itervalues
():
# Before we ignore 'quantity==0' amount here for better
# performance, but it is not a good idea, especially when the
# first expand causes non-zero quantity and then quantity
# becomes zero.
amount
.
_setQuantity
(
quantity
)
if
0
:
print
'getAggregatedAmountList(%r) -> (%s)'
%
(
self
.
getRelativeUrl
(),
', '
.
join
(
'(%s, %s, %s)'
%
(
x
.
getResourceTitle
(),
x
.
getQuantity
(),
x
.
getPrice
())
for
x
in
result_list
))
return
result_list
return
self
.
getGeneratedAmountList
(
*
args
,
**
kw
).
aggregate
()
InitializeClass
(
AmountGeneratorMixin
)
product/ERP5/tests/testERP5Interfaces.py
View file @
a6b1b63f
...
...
@@ -55,7 +55,7 @@ implements_tuple_list = [
((
'Products.ERP5.Document.EmailDocument'
,
'EmailDocument'
),
'IDocument'
),
((
'Products.ERP5.Document.Event'
,
'Event'
),
'IDocument'
),
# IAmountList
((
'Products.ERP5.
AggregatedAmountList'
,
'Aggreg
atedAmountList'
),
'IAmountList'
),
((
'Products.ERP5.
GeneratedAmountList'
,
'Gener
atedAmountList'
),
'IAmountList'
),
]
# IMovementGroup
for
movement_group_class_name
in
[
'MovementGroup'
,
'BaseVariantMovementGroup'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment