Skip to content
  • Nshimiyimana Séna's avatar
    [FIX] account, l10n_account_edi_ubl_cii_tests: fix tests · f33e80dc
    Nshimiyimana Séna authored
    
    
    This PR fixes tests that were broken by commit 84e23047
    That commit fixes the rounding of Float fields, ensuring that the
    floats' 'digits' parameter is enforced.
    
    Issue
    -----
    Here an issue arise with the Discount field of `account.move.line`. In
    this case, the discount value is calculated from a price and a discount
    amount.
    
    Let's say we have an amount of $180 with a $30 discount amount. This
    gives a discount percentage of 16.6666666667 %. As expected, we can get
    the correct discounted amount like so:
    `180 * (1 - 0.166666666667) = 150`
    
    The default decimal accuracy of the discount field on
    `account.move.line` is 2 (and it's unlikely to be set much higher).
    Before commit 84e23047, that accuracy what not enforced in
    computes/onchanges, so the test ran without failure.
    
    But now the precision is always applied. As a result, the discount
    percentage become 16.67 %. However, with this value the test fails
    because, we cannot get the expected discounted amount:
    `180 * (1 - 0.1667) = 149.994 = 149.99`
    
    Fix
    ---
    Add a context manager to be used whenever we need Discount to have as
    much precision as possible. That context manager simply patches
    `DecimalPrecision.precision_get` to return a discount precision of 100
    
    closes odoo/odoo#137731
    
    Signed-off-by: default avatarFlorian Gilbert (flg) <flg@odoo.com>
    f33e80dc
Loading