Why am I getting wrong Montant HT with tax-included

Why am I getting wrong Montant HT with tax-included

Hi everyone,

I’m having a rounding/precision issue on Sales Invoices when using tax-included pricing with TND (Tunisian Currency) and 19% TVA or 7%TVA.

Setup

  • Currency: TND
  • TVA: 19%
  • Tax configuration:
    • Tax 1: 19%, “Is this tax included in basic rate” = YES
    • Tax 2: 1.000 TND (timbre fiscal), type = Actual
  • Item price:
    • Price List Rate (TTC): 79.000 TND per unit
  • Quantity: 12

What Dokos/ERPNext shows

On the invoice, Dokos displays:

  • PU HT (net_rate): 66.387
  • Montant HT (net_amount): 796.639

But (expected Montant HT) 796.644 DT:

66.387 × 12 = 796.644   

item

Am I doing something wrong in my settings/configuration (currency precision, tax setup, “tax included in rate”, etc.) that causes this behavior?

Or is this actually a bug in how ERPNext calculates and rounds net_rate / net_amount when tax is included in the rate

Thanks in advance to anyone who can help or share their experience.

I think there are hidden decimals in the PU HT field’s value.

Do they disappear after saving the document?

The actual value of the PU HT field could be anything that rounds to the displayed value of 66.387: in between 66.386500 and 66.387499, and thus possibly not exactly 66.387000, because additional decimals are just not shown. I don’t know yet if it’s intentional or not.

66.386590 * 12 = 796.639080 ≈ 796.639

1 Like

The cause was that net_amount was calculated from high-precision tax-inclusive math, and net_rate was rounded later – they were not forced to match. I fixed it by ensuring net_amount = rounded(net_rate) × qty in the tax-included calculation and again in calculate_net_total().