Commit 103aa8b3 authored by Julien Muchembled's avatar Julien Muchembled

Do not generate amounts without any base_application

Before we dropped amounts with quantity=0 and we stopped doing that because
it broke expand. However, there's still one case when such amount can be
ignored, i.e. when there's no base_application set on the amount generator.
parent 0c9d9206
...@@ -302,6 +302,14 @@ class AmountGeneratorMixin: ...@@ -302,6 +302,14 @@ class AmountGeneratorMixin:
if x[:12] != 'base_amount/'])) if x[:12] != 'base_amount/']))
if variation_category_list: if variation_category_list:
base_application_set.difference_update(variation_category_list) base_application_set.difference_update(variation_category_list)
# Before we ignored 'quantity=0' amount here for better performance,
# but it makes expand unstable (e.g. when the first expand causes
# non-zero quantity and then quantity becomes zero).
# Ignore only if there's no base_application.
if not base_application_set:
continue
# property_dict may include # property_dict may include
# resource - VAT service or a Component in MRP # resource - VAT service or a Component in MRP
# (if unset, the amount will only be used for reporting) # (if unset, the amount will only be used for reporting)
...@@ -325,13 +333,6 @@ class AmountGeneratorMixin: ...@@ -325,13 +333,6 @@ class AmountGeneratorMixin:
del property_dict[key] del property_dict[key]
quantity *= property_dict.pop('quantity', 1) quantity *= property_dict.pop('quantity', 1)
# 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 # Backward compatibility
if getattr(self.aq_base, 'create_line', None) == 0: if getattr(self.aq_base, 'create_line', None) == 0:
property_dict['resource'] = None property_dict['resource'] = None
...@@ -416,10 +417,6 @@ class AmountGeneratorMixin: ...@@ -416,10 +417,6 @@ class AmountGeneratorMixin:
# performance, but it is not a good idea, especially when the # performance, but it is not a good idea, especially when the
# first expand causes non-zero quantity and then quantity # first expand causes non-zero quantity and then quantity
# becomes zero. # becomes zero.
# if quantity or generate_empty_amounts:
# amount._setQuantity(quantity)
# else:
# result_list.remove(amount)
amount._setQuantity(quantity) amount._setQuantity(quantity)
if 0: if 0:
print 'getAggregatedAmountList(%r) -> (%s)' % ( print 'getAggregatedAmountList(%r) -> (%s)' % (
......
...@@ -872,8 +872,7 @@ return lambda *args, **kw: 1""") ...@@ -872,8 +872,7 @@ return lambda *args, **kw: 1""")
order = self.createOrder(trade_condition, ( order = self.createOrder(trade_condition, (
dict(), dict(),
)) ))
amount_list = order.getAggregatedAmountList() self.assertEqual([], order.getAggregatedAmountList())
self.assertEqual([0, 0], [x.getTotalPrice() for x in amount_list])
for line in trade_condition.objectValues(): for line in trade_condition.objectValues():
line.setBaseApplication(fixed_quantity) line.setBaseApplication(fixed_quantity)
amount_list = order.getAggregatedAmountList() amount_list = order.getAggregatedAmountList()
......
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