#862 amount rounding issue: discounted amount gets rounded differently in "sales order entry" (and sales invoice entry) and in templates

1.3
closed-fixed
nobody
5
2013-11-07
2013-06-13
No

Hello,

following my message https://sourceforge.net/mailarchive/message.php?msg_id=31038526 in users mailing list

I tried this:

  1. new sales order with 2 items

1.a item 1 with price 14.155, the amount gets rounded to 14.16 (both in
"price" field and in "extended" field with qty=1)

1.b item 2 with price 14.90 and 5% discount, the extended amount (qty=1)
gets rounded to 14.16 as in 1.a (plz note that the discounted amount is
14.90*0.95=14.155)

  1. save the order and print it in HTML (same behaviour in PDF)

2.a item 1 price is 14.16 and obviously the total amount is the same (qty=1)

2.b item 2 price is 14.90, disc. 5% and amount is 14.15 (in 1.b is 14.16)

the discounted amount gets rounded differently in "order entry" and in
templates (HTML or PDF)

the very same issue happens in invoices too

Best regards
Giovanni

Discussion

  • Giovanni Biscuolo

    Oh sorry,
    forgot to mention that I'm using LedgerSMB v. 1.3.25 from Debian Jessie (testing) repository

     
  • Giovanni Biscuolo

    OK I think I've found the issue.

    if I don't get wrong the code used for visualization of rows in order entry screen is bin/io.pl (http://ur1.ca/eb6jk) where I find:

    .........................
    297 $linetotal = $form->round_amount( $form->{"sellprice_$i"}
    298 * (1 - ($form->{"discount_$i"} / 100)),
    299 $decimalplaces);
    300 $linetotal = $form->round_amount( $linetotal * $form->{"qty_$i"},
    301 $moneyplaces);
    ........................

    while that used for order forms should be LedgerSMB/OE.pm ( where I find:

    .........................
    272 $discount =
    273 $form->round_amount(
    274 $form->{"sellprice_$i"} * $form->{"discount_$i"},
    275 $decimalplaces );
    276 $form->{"sellprice_$i"} =
    277 $form->round_amount( $form->{"sellprice_$i"} - $discount,
    278 $decimalplaces );
    279
    280 $linetotal =
    281 $form->round_amount( $form->{"sellprice_$i"} * $form->{"qty_$i"},
    282 2 );
    .........................

    in OE.pm the discount value is rounded before the net price item calculation, while the discont amount rounding in io.pl is missing (http://ur1.ca/eb6m8) discount amount is calculated "inline" and not rounded)

    this means that in cases like the one described in my first message there could be a difference of 1 cent on the calculated discount amount

    I have to stop working for today, tomorrow I'll try a patch... If I did not got wrong with the program logic

    Ciao
    Giovanni

     
    • Giovanni Biscuolo

      OK I think I've found a fix to io.pl code, please see attached patch

      I've applied that patch to one of my instances and it seemps the problem is solved: I've tried both with old issued orders (and invoices) and with new issued ones and row linetotals are calculated with no rounding errors

      unfortunately there is still a related (discount rounding) calculation error on taxes (total amount of taxes on printed tamplate is different from the displayed one in "New Invoice" form)... and I think I've found it, I'll send a patch ASAP for that too.

      best regards
      Giovanni

       
  • Giovanni Biscuolo

    OK I've found the error (I think it's an error) in _calc_taxes function in io.pl and applied a patch that seems to fix that, please find it atttached

    the patch fixes both issues described above: linetolal and taxes rounding errors

    please review the patch and give me somw feedback, I've tested it but it needs more testing/review from upstream

    thanks in advance
    best regards
    Giovanni

     
  • Chris Travers

    Chris Travers - 2013-11-07

    patches committed in svn feel free to contact us for inclusion in the CONTRIBUTORS file.

     
  • Chris Travers

    Chris Travers - 2013-11-07
    • status: open --> closed-fixed