Correct way to setup decimal precision in OpenERP

Wrong setting of decimal precision can result in big problem for accounting. Here is some tips from my experience.

  • It is ok (and sometime required to make a valid result) to increase the precision for non-Account items. I.e., Price, Discount.
  • But we should not change the precision of Account as it will affect account posting. Also, 2 digit is what we want for our Forms, it should be the same as what is recorded in system.

decmial_setup

  • In coding, OpenERP is using the same concept as Excel’s “Calculate as Display”. Meaning, each number should be rounded (2 digit as setup in currency) before further calculation.
  • Make sure when writing the code, use this concept to avoid future problem.

oe_1

    def cur_round(value):
        """Round value according to currency."""
        return cur_obj.round(cr, uid, cur, value)

    # add discount
    amount_untaxed = sum(line.price_subtotal
                         for line in getattr(record, self._line_column))
    add_disc = record.add_disc
    add_disc_amt = cur_round(amount_untaxed * add_disc / 100)
    o_res['add_disc_amt'] = add_disc_amt
    o_res['amount_net'] = o_res['amount_untaxed'] - add_disc_amt

    # we apply a discount on the tax as well.
    # We might have rounding issue
    o_res['amount_tax'] = cur_round(
        o_res['amount_tax'] * (100.0 - (add_disc or 0.0))/100.0)
    o_res['amount_total'] = o_res['amount_net'] + o_res['amount_tax']

Note:

You can note from the code that, we always round it (to 2 digits) before pass it to next calculation.