Commit 1474a3d5 authored by Julien Muchembled's avatar Julien Muchembled

get{Aggregated,Generated}AmountList get a new 'generate_empty_amounts' parameter

The default value is False, except for getAggregatedAmountList with legacy
simulation, in order to fix a backward compatibility issue when solving
a simulation tree.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@42117 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c37b6f07
import warnings
from Products.ERP5.mixin import composition
from Products.ERP5.ERP5Site import ERP5Site
......@@ -31,6 +32,24 @@ def patch():
ERP5Site.getPortalBusinessPathTypeList = getPortalBusinessPathTypeList
## AmountGeneratorMixin
class true:
def __nonzero__(self):
warnings.warn("Default value for 'generate_empty_amounts' parameter"
" is False for new simulation", DeprecationWarning)
return True
true = true()
from Products.ERP5.mixin.amount_generator import AmountGeneratorMixin
for method_id in ('getAggregatedAmountList',): # getGeneratedAmountList
m = getattr(AmountGeneratorMixin, method_id)
f = m.im_func
f = type(f)(f.func_code, f.func_globals, f.func_name,
f.func_defaults[:3] + (true,), f.func_closure)
m = type(m)(f, None, AmountGeneratorMixin)
setattr(AmountGeneratorMixin, method_id, m)
## CompositionMixin
composition._LEGACY_SIMULATION = True
......
9
\ No newline at end of file
10
\ No newline at end of file
......@@ -148,7 +148,8 @@ class AmountGeneratorMixin:
security.declareProtected(Permissions.AccessContentsInformation,
'getGeneratedAmountList')
def getGeneratedAmountList(self, amount_list=None, rounding=False,
amount_generator_type_list=None):
amount_generator_type_list=None,
generate_empty_amounts=False):
"""
Implementation of a generic transformation algorithm which is
applicable to payroll, tax generation and BOMs. Return the
......@@ -291,7 +292,7 @@ class AmountGeneratorMixin:
quantity *= property_dict.pop('quantity', 1)
except TypeError: # None or ''
pass
if not quantity:
if not (quantity or generate_empty_amounts):
continue
# Backward compatibility
if getattr(self.aq_base, 'create_line', None) == 0:
......@@ -337,7 +338,8 @@ class AmountGeneratorMixin:
security.declareProtected(Permissions.AccessContentsInformation,
'getAggregatedAmountList')
def getAggregatedAmountList(self, amount_list=None, rounding=False,
amount_generator_type_list=None):
amount_generator_type_list=None,
generate_empty_amounts=False):
"""
Implementation of a generic transformation algorith which is
applicable to payroll, tax generation and BOMs. Return the
......@@ -348,7 +350,8 @@ class AmountGeneratorMixin:
"""
generated_amount_list = self.getGeneratedAmountList(
amount_list=amount_list, rounding=rounding,
amount_generator_type_list=amount_generator_type_list)
amount_generator_type_list=amount_generator_type_list,
generate_empty_amounts=generate_empty_amounts)
# XXX: Do we handle rounding correctly ?
# What to do if only total price is rounded ??
aggregate_dict = {}
......@@ -363,7 +366,10 @@ class AmountGeneratorMixin:
else:
aggregate[1] += amount.getQuantity()
for amount, quantity in aggregate_dict.itervalues():
amount._setQuantity(quantity)
if quantity or generate_empty_amounts:
amount._setQuantity(quantity)
else:
result_list.remove(amount)
if 0:
print 'getAggregatedAmountList(%r) -> (%s)' % (
self.getRelativeUrl(),
......
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