Commit 414042ad authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

amount generator no longer ignores quantity=0 result like legacy trade model rule.

parent 04e1768e
......@@ -32,24 +32,6 @@ 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
......
15
\ No newline at end of file
16
\ No newline at end of file
......@@ -159,8 +159,7 @@ class AmountGeneratorMixin:
security.declareProtected(Permissions.AccessContentsInformation,
'getGeneratedAmountList')
def getGeneratedAmountList(self, amount_list=None, rounding=False,
amount_generator_type_list=None,
generate_empty_amounts=False):
amount_generator_type_list=None):
"""
Implementation of a generic transformation algorithm which is
applicable to payroll, tax generation and BOMs. Return the
......@@ -312,8 +311,14 @@ class AmountGeneratorMixin:
if property_dict.get(key, 0) in (None, ''):
del property_dict[key]
quantity *= property_dict.pop('quantity', 1)
if not (quantity or generate_empty_amounts):
continue
# 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.
# if not (quantity or generate_empty_amounts):
# continue
# Backward compatibility
if getattr(self.aq_base, 'create_line', None) == 0:
property_dict['resource'] = None
......@@ -369,8 +374,7 @@ class AmountGeneratorMixin:
security.declareProtected(Permissions.AccessContentsInformation,
'getAggregatedAmountList')
def getAggregatedAmountList(self, amount_list=None, rounding=False,
amount_generator_type_list=None,
generate_empty_amounts=False):
amount_generator_type_list=None):
"""
Implementation of a generic transformation algorith which is
applicable to payroll, tax generation and BOMs. Return the
......@@ -378,8 +382,7 @@ class AmountGeneratorMixin:
"""
generated_amount_list = self.getGeneratedAmountList(
amount_list=amount_list, rounding=rounding,
amount_generator_type_list=amount_generator_type_list,
generate_empty_amounts=generate_empty_amounts)
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 = {}
......@@ -394,10 +397,15 @@ class AmountGeneratorMixin:
else:
aggregate[1] += amount.getQuantity()
for amount, quantity in aggregate_dict.itervalues():
if quantity or generate_empty_amounts:
amount._setQuantity(quantity)
else:
result_list.remove(amount)
# 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.
# if quantity or generate_empty_amounts:
# amount._setQuantity(quantity)
# else:
# result_list.remove(amount)
amount._setQuantity(quantity)
if 0:
print 'getAggregatedAmountList(%r) -> (%s)' % (
self.getRelativeUrl(),
......
......@@ -198,7 +198,7 @@ return getBaseAmountQuantity""")
self.appendBaseContributionCategory(order['2'], special_discount)
transaction.commit()
self.getAggregatedAmountDict(order, partial_check=True,
SPECIAL_DISCOUNT_3CD_LINEAR=None,
SPECIAL_DISCOUNT_3CD_LINEAR=dict(total_price=0),
TOTAL_PRICE_WITHOUT_VAT=dict(total_price=8100),
TOTAL_PRICE_WITH_VAT=dict(total_price=8505),
VAT_AMOUNT=dict(total_price=405))
......@@ -254,7 +254,7 @@ return lambda delivery_amount, base_application, **kw: \\
self.appendBaseContributionCategory(order['2'], special_discount)
transaction.commit()
self.getAggregatedAmountDict(order, partial_check=True,
SPECIAL_DISCOUNT_3CD_FIXED=None,
SPECIAL_DISCOUNT_3CD_FIXED=dict(total_price=0),
TOTAL_PRICE_WITHOUT_VAT=dict(total_price=11000),
TOTAL_PRICE_WITH_VAT=dict(total_price=11550),
VAT_AMOUNT=dict(total_price=550))
......@@ -314,7 +314,7 @@ return getBaseAmountQuantity""")
self.appendBaseContributionCategory(order['3'], special_discount)
transaction.commit()
self.getAggregatedAmountDict(order, partial_check=True,
SPECIAL_DISCOUNT_3CD_LINEAR=None,
SPECIAL_DISCOUNT_3CD_LINEAR=dict(total_price=0),
TOTAL_PRICE_WITHOUT_VAT=dict(total_price=11000),
TOTAL_PRICE_WITH_VAT=dict(total_price=11550),
VAT_AMOUNT=dict(total_price=550))
......@@ -374,7 +374,7 @@ return lambda delivery_amount, base_application, **kw: \\
self.appendBaseContributionCategory(order['1'], poster_present_3cd)
transaction.commit()
self.getAggregatedAmountDict(order, partial_check=True,
SPECIAL_DISCOUNT_3CD_OR_1DVD_FIXED=None,
SPECIAL_DISCOUNT_3CD_OR_1DVD_FIXED=dict(total_price=None),
TOTAL_PRICE_WITHOUT_VAT=dict(total_price=6000),
TOTAL_PRICE_WITH_VAT=dict(total_price=6300),
VAT_AMOUNT=dict(total_price=300))
......@@ -450,7 +450,7 @@ return getBaseAmountQuantity""")
self.appendBaseContributionCategory(order['4'], special_discount)
transaction.commit()
self.getAggregatedAmountDict(order, partial_check=True,
SPECIAL_DISCOUNT_3CD=None,
SPECIAL_DISCOUNT_3CD=dict(total_price=0),
TOTAL_PRICE_WITHOUT_VAT=dict(total_price=12000),
TOTAL_PRICE_WITH_VAT=dict(total_price=12600),
VAT_AMOUNT=dict(total_price=600))
......
......@@ -425,10 +425,10 @@ class TestTradeModelLine(TestTradeModelLineMixin):
self.assertEqual(len(simulation_movement_list),
len(result_dict))
for use in 'discount', 'tax':
total_price = expected_result_dict[use].get(line.getId())
if total_price:
total_price = expected_result_dict[use].get(line.getId()) or 0.0
if True:
sm = result_dict.pop(use)
self.assertEqual(str(sm.getTotalPrice()), str(total_price))
self.assertEqual(str(sm.getTotalPrice() or 0.0), str(total_price))
self.assertEqual(3, len(sm.getCausalityValueList()))
self.assertEqual(1, len(sm.getCausalityValueList(
portal_type=self.business_link_portal_type)))
......@@ -853,7 +853,7 @@ return getBaseAmountQuantity""")
('tax_share/B',): .6,
}, base_application=(0,))
from Products.ERP5Type.Document import newTempAmount
for x in ((100, 30, 10, 20, 5, 12),
for x in ((100, 30, 10, 0, 0, 20, 5, 12),
(500, 150, 20, 90, 40, 120, 55, 96)):
amount = newTempAmount(self.portal, '_',
quantity=x[0], price=1,
......@@ -880,7 +880,8 @@ return lambda *args, **kw: 1""")
order = self.createOrder(trade_condition, (
dict(),
))
self.assertEqual([], self.getAggregatedAmountList(order))
amount_list = order.getAggregatedAmountList()
self.assertEqual([0, 0], [x.getTotalPrice() for x in amount_list])
for line in trade_condition.objectValues():
line.setBaseApplication(fixed_quantity)
amount_list = order.getAggregatedAmountList()
......
......@@ -41,11 +41,6 @@ def test_suite():
suite.addTest(unittest.makeSuite(TestComplexTradeModelLineUseCasePurchase))
return suite
def getAggregatedAmountList(self, amount_generator, *args, **kw):
kw.setdefault('generate_empty_amounts', False)
return amount_generator.getAggregatedAmountList(*args, **kw)
TestTradeModelLineMixin.getAggregatedAmountList = getAggregatedAmountList
###
## TestTradeModelLine
##
......
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