Commit d54fee87 authored by Jérome Perrin's avatar Jérome Perrin

WIP

parent 4b114fc3
"""Convert the amounts used in the accounting transaction to the currency of the destination section
"""
portal = context.getPortalObject()
precision = context.getDestinationSectionValue().getPriceCurrencyValue().getQuantityPrecision()
currency = context.getDestinationSectionValue().getPriceCurrencyValue()
precision = currency.getQuantityPrecision()
base_unit_quantity = currency.getBaseUnitQuantity()
line_list = context.contentValues(
portal_type=portal.getPortalAccountingMovementTypeList())
total_destination_total_asset_price = 0.0
for line in line_list:
section = line.getDestinationSectionValue()
if section != context.getDestinationSectionValue():
......@@ -24,8 +27,19 @@ for line in line_list:
# update the corresponding price and round it according to the precision of
# the converted currency
line.setDestinationTotalAssetPrice(
round(exchange_rate * (line.getQuantity()), precision))
destination_total_asset_price = round(exchange_rate * (line.getQuantity()), precision)
total_destination_total_asset_price += destination_total_asset_price
line.setDestinationTotalAssetPrice(destination_total_asset_price)
# Adjust last line so that we keep debit == credit
if total_destination_total_asset_price:
# make sure difference is not too big.
# TODO: check this is correct maybe we can have more than 1 time base_unit_quantity ?
assert -base_unit_quantity <= total_destination_total_asset_price <= base_unit_quantity
line_to_adjust = line_list[-1]
line_to_adjust.setDestinationTotalAssetPrice(
line_to_adjust.getDestinationTotalAssetPrice() - total_destination_total_asset_price)
msg = context.Base_translateString('Price converted.')
......
  • @xiaowu.zhang

    pour mémoire, des valeurs qui reproduisent

    19925.50 * 15.55 = 309841.525 apres rounding c'est 309841.53
    1174.74 * 15.55 = 18267.207 roudning 18267.21
    mais  21 100.24 * 15.55 = 328108.732 rounding 328108.73
  • des valeurs plus simples:

    taux = 0.333
    
    q_list = [2, 2, -3, -1]
    converted_list = []
    
    for q in q_list:
        converted = round(q*taux, 2)
        print (q, converted)
        converted_list.append(converted)
    
    print (sum(converted_list))
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