Commit 35966f23 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_accounting: Fixup Constraints to not make Reversal Transactions inconsistent

parent e27cbaa6
root_trade_condition_list = ["sale_trade_condition_module/slapos_aggregated_trade_condition", root_trade_condition_list = ["sale_trade_condition_module/slapos_aggregated_trade_condition",
"sale_trade_condition_module/slapos_aggregated_subscription_trade_condition"] "sale_trade_condition_module/slapos_aggregated_subscription_trade_condition",
# Valid trade condition for payments
"sale_trade_condition_module/slapos_manual_accounting_trade_condition"]
if context.getSpecialise() in root_trade_condition_list: if context.getSpecialise() in root_trade_condition_list:
return True return True
......
invoice = context invoice = context
total_price = invoice.getTotalPrice() total_price = invoice.getTotalPrice()
if invoice.getTotalPrice() < 0:
# For a negative total is from the Reversal transactions
total_price *= -1
accounting_price = invoice.AccountingTransaction_getTotalCredit() accounting_price = invoice.AccountingTransaction_getTotalCredit()
precision = invoice.getPriceCurrencyValue().getQuantityPrecision() precision = invoice.getPriceCurrencyValue().getQuantityPrecision()
return round(total_price, precision) == round(accounting_price, precision) return round(total_price, precision) == round(accounting_price, precision)
specialise = context.getSpecialiseValue(portal_type='Sale Trade Condition') specialise = context.getSpecialiseValue(portal_type='Sale Trade Condition')
if specialise.getSpecialiseValue() is None:
# The trade model don't applies if the Trade Condition isn't attached to
# A business process
return True
amount_list = specialise.getAggregatedAmountList(context) amount_list = specialise.getAggregatedAmountList(context)
if len(amount_list) < 1: if len(amount_list) < 1:
return False return False
......
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