Posts

Saving Attachment in Filestore

By default, OpenERP save attachment in database as binary field. To change it to save in file server is easy, follow these steps,

  • Create new System Parameter
key: ir_attachment.location
value: file:///filestore
  • That’s all you need to do, and the file will be stored in server/openerp/filestore/<dbname>/

Avoiding Infinite OnChange Loop

OnChange loop happens when 2 fields with onchange() method which return result with some decimal point residue to another field, which trigger another call and another call.

The solution is to round() method before return value, ensure there is not decimal point residue to trigger next call.

    def onchange_amount(self, cr, uid, ids, field, src_amount, dst_amount, exchange_rate):
        res = {'value':{}}
        if field == 'src_amount':
            res['value']['src_amount'] = src_amount
            res['value']['dst_amount'] = round(src_amount * exchange_rate, 2) # Round to avoid infinite looping
            res['value']['exchange_rate'] = exchange_rate
            res['value']['exchange_inv'] = exchange_rate and 1.0 / exchange_rate or 0.0
        elif field == 'dst_amount':
            res['value']['src_amount'] = round(exchange_rate and dst_amount / exchange_rate or 0.0, 2)  # Round to avoid infinite looping
            res['value']['dst_amount'] = dst_amount
            res['value']['exchange_rate'] = exchange_rate
            res['value']['exchange_inv'] = exchange_rate and 1.0 / exchange_rate or 0.0
        elif field == 'exchange_rate':
            res['value']['src_amount'] = src_amount
            res['value']['dst_amount'] = round(src_amount * exchange_rate, 2)  # Round to avoid infinite looping
            res['value']['exchange_rate'] = exchange_rate
            res['value']['exchange_inv'] = exchange_rate and 1.0 / exchange_rate or 0.0
        return res

Round Tax Globally Feature in OpenERP

In OpenERP, the Tax calculation rounding method in e.g., SO/PO/INV have 2 rounding method.

This can be setup in menu Setting > Configuration > Accounting

  1. Round globally, where rounding per line in 5 digits and then round again in 2 digit globally.
  2. Round per line, where rounding per line in 2 digits.

round_tax_globally

I would recommend Rounding globally always. In some very rare case, Round per line can give some digit problem as following,

rounding_problem