Uploaded image for project: 'OFBiz'
  1. OFBiz
  2. OFBIZ-10500

Tax calculation incorrect when creating orders



    • Bug
    • Status: Closed
    • Major
    • Resolution: Invalid
    • Release Branch 16.11
    • None
    • order
    • None
    • OpenJDK 1.8.0_151 64bit on Ubuntu 16.04


      After a discussion on the user mailinglist we concluded there seems to be an issue with the tax calculations.

      Steps to reproduce

      • Create a tax authority for a specific country (e.g. The Netherlands in my case)
      • Set sales tax rate of 21% for your store with this Tax Authority
      • Create a product and enter a price either including or excluding taxes and set the corresponding flag for tax included y/n.
      • Go to the order manager and order entry. Fill in the details, select the product and go to the review page. It now shows the incorrect sales tax and price.

      Let's say we have a product of 20 euro incl. taxes. With 21% that comes down to 3.47 euro of taxes and a price of 16.53 euro. Instead Ofbiz shows a price of 20 euro excl. taxes and adds 4.20 euros in taxes.

      What I tried

      Changing the price to price excl. VAT and set the flag to 'N' and visa versa. Both gave the same error. 

      Possible solution

      I digged into the code and ended up in the file:


      The function in line 2401

      public static BigDecimal getOrderItemSubTotal(GenericValue orderItem, List<GenericValue> adjustments, boolean forTax, boolean forShipping)

      returns the price of one item there. It uses this piece of code:


      The line item is always the price including taxes. When I adjust this price (by dividing it by 1.21) I do get the correct price in the review page. I do not, however, get the right tax amount. This is calculated elsewhere and still using the 20 euro price I guess. Anyway, it does show I was in the right spot.

      I'm not familiar enough with Ofbiz to create a full patch, but I think the easiest way to go is to add another column to order items where the value excl. taxes is stored which can be used in places where needed. This does not affect the whole system. On the other hand I'm not sure where the order items are stored, since when you are on the review page it is not stored in database yet. Probably just in the session? Should make things even easier.

      The attachments show an example. I have stored a product of 20 euro (screenshot directly taken from the database tool) and I have set-up a tax exempt in this case for a customer which shows 4.20 euro sales tax. If I turn off the tax exempt the grand total becomes 24.20 euros, so it is not related to the exempt.



        1. Schermafbeelding 2018-07-30 om 10.16.16.png
          44 kB
          Frank Herrman
        2. Schermafbeelding 2018-07-30 om 10.15.51.png
          62 kB
          Frank Herrman
        3. VAT.png
          68 kB
          Ankush Upadhyay
        4. Invoice.png
          38 kB
          Ankush Upadhyay
        5. Stores.png
          114 kB
          Ankush Upadhyay
        6. OrderReview.png
          53 kB
          Ankush Upadhyay
        7. Shipping.png
          97 kB
          Ankush Upadhyay



            ankush.upadhyay Ankush Upadhyay
            FrankH Frank Herrman
            1 Vote for this issue
            5 Start watching this issue