[Erp5-report] r42117 jm - in /erp5/trunk: bt5/erp5_simulation_legacy/DocumentTemplateItem/ ...
nobody at svn.erp5.org
nobody at svn.erp5.org
Fri Jan 7 14:42:43 CET 2011
Author: jm
Date: Fri Jan 7 14:42:43 2011
New Revision: 42117
URL: http://svn.erp5.org?rev=42117&view=rev
Log:
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.
Modified:
erp5/trunk/bt5/erp5_simulation_legacy/DocumentTemplateItem/SimulationLegacyPatches.py
erp5/trunk/bt5/erp5_simulation_legacy/bt/revision
erp5/trunk/products/ERP5/mixin/amount_generator.py
Modified: erp5/trunk/bt5/erp5_simulation_legacy/DocumentTemplateItem/SimulationLegacyPatches.py
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_simulation_legacy/DocumentTemplateItem/SimulationLegacyPatches.py?rev=42117&r1=42116&r2=42117&view=diff
==============================================================================
--- erp5/trunk/bt5/erp5_simulation_legacy/DocumentTemplateItem/SimulationLegacyPatches.py [utf8] (original)
+++ erp5/trunk/bt5/erp5_simulation_legacy/DocumentTemplateItem/SimulationLegacyPatches.py [utf8] Fri Jan 7 14:42:43 2011
@@ -1,3 +1,4 @@
+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
Modified: erp5/trunk/bt5/erp5_simulation_legacy/bt/revision
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_simulation_legacy/bt/revision?rev=42117&r1=42116&r2=42117&view=diff
==============================================================================
--- erp5/trunk/bt5/erp5_simulation_legacy/bt/revision [utf8] (original)
+++ erp5/trunk/bt5/erp5_simulation_legacy/bt/revision [utf8] Fri Jan 7 14:42:43 2011
@@ -1 +1 @@
-9
\ No newline at end of file
+10
\ No newline at end of file
Modified: erp5/trunk/products/ERP5/mixin/amount_generator.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/mixin/amount_generator.py?rev=42117&r1=42116&r2=42117&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/mixin/amount_generator.py [utf8] (original)
+++ erp5/trunk/products/ERP5/mixin/amount_generator.py [utf8] Fri Jan 7 14:42:43 2011
@@ -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(),
More information about the Erp5-report
mailing list