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
master after_rebase allow_login_change allow_login_change_differentiate_id_and_login allow_login_change_wip arnau arnau-kns arnau-kns-without-property-mapping arnau-merge arnau-poc auto_extend_select_list autoflake backup_erp5_workflow bk_erp5ish_actions_tool bk_sqlcatalog boc-interaction-drop bt5_config cache catalog_fulltext catalog_fulltext_old cedric cedriclen cedriclen-eos cherry-pick-4a8e045d cleanJSByJSLint clean_up_upgrader cleanup_acquisition_base_category compact_title_no_reference cr_test cr_test_rebase credential_update_action datetimefield deferred_listbox delivery_item_barcode douglas_forum dream_distributor drop-legacy-simulation dsn-phase3 eos-dev erp5-component erp5-data-notebook erp5-forum erp5-preference erp5-release erp5-slapos-upgrade erp5-util-testing erp5-vifib erp5-vifib-cleanup erp5_calendar erp5_catalog erp5_free_subscription erp5_workflow erp5testnode_max_timeout experiment/coding_style_test_suite feat/accounting_balance_sheet_profit_and_loss_cleanups feat/accounting_stop_using_getObject feat/accounting_translate_gap feat/no_useless_records_in_predicate_table feat/olapy feat/trade_shipment_report feat/wendelin-py-data feature/renderjs-formbox feature/renderjs-matrixbox feature/renderjs-ui-no-header fix/full_text_script_conflict fix/login_validate_check_consistency fix/repair_graph_editor fix/xvfb_all_displays_locked fix_system_processes_ownership for_testrunner_1 for_testrunner_2 for_testrunner_3 gabriel gabriel-fix-rounding-in-accounting-generation gabriel-fix-rounding-in-accounting-generation2 gadget-json-value http_cache_fix improve_default_caching_policy_manager interaction-drop isDeletable item_tracking_graph_editor ivan jerome-bt-reference-doc jerome-test jerome_events jerome_graph_editor_renderjs jerome_new_style_solve_divergence jerome_promise_in_tests jerome_user_preference_time_zone jio jm/form-action-guard joblib-activity kns kns-kr lazy_simulation_causality lignan lingnan listbox-generator mame mame-bt5-cleanup mame-erp5_project-cleanup mame-naming-convention mame-naming-convention-list_method mame-test-stock-indexation mame-work mame2 maste_copy master-erp5-test-result-scalability master-erp5-test-result-scalability-rebase master-test-fix-additionalbt5path master_calendar_wip_patches master_calendar_wip_patches_extend_security master_no_guard_on_workflow_transition master_no_guard_on_workflow_transition_plus_calendar_wip_patchs merge_xhtml_jquery mmariani-inventory monitoring mrp new-render-presentation nexedi-erp5-jp no_longer_simulated_state officejs officejs_clean officejs_zip pere portal_callables portal_solver_process_security_configuration presentation rebased_mrp reindex_calendar_after_change_calendar_exception reverse_logistics rewrite_test_21_AcquiredPortalType romain-fulltext scalability-master2 scalability-master2-rebase scalability-rebase shop-box simulation sms_more_than_140_characters strict_catalog sws_fix syncml taskdistribution-xmlrpc-binary test_page testnode_software_link timezones tmp/getInstalledBusinessTemplate_never_installed_bt tristan tristan-merge tristan-performance ttr ttrm upgradeSite view-aggregated-amounts vivekpab_erp5webrenderjs_layoutconfig vivekpab_jabberclient vivekpab_renderjs_interfaces wenjie wenjie_branch yryr yryr-components-cp yryr-inventory-cache yryr-test yryr-with-components yusei erp5.util-0.4.49 erp5.util-0.4.46 erp5.util-0.4.44 erp5.util-0.4.43 erp5.util-0.4.41 erp5.util-0.4.40 erp5.util-0.4.37 erp5.util-0.4.1 erp5.util-0.4 erp5.util-0.3 erp5.util-0.2
No related merge requests found
......@@ -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