Posts

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.

Easy way to track document changes using Chatter

Though we can always write changes in Chatter Box via coding, the easier way is to do it automatically. In fields object, there is an attribute for doing just that.

  • track_visibility=’always’
  • track_visibility=’onchange’

track_change_chatter

Start OpenERP Server on Startup

Given we have more than 1 openerp server to start, here is how to add openerp startup scripts

Steps:

  • Place openerp startup script, i.e., openerp-test-7069 in /etc/init.d
  • Change permission to 777 sudo chmod 777 openerp-test-7069
  • Create symbolic link in all 6 rc*.d folders as following,
sudo ln -s /etc/init.d/openerp-test-7069 /etc/rc0.d/K22openerp-test-7069
sudo ln -s /etc/init.d/openerp-test-7069 /etc/rc1.d/K22openerp-test-7069
sudo ln -s /etc/init.d/openerp-test-7069 /etc/rc2.d/S22openerp-test-7069
sudo ln -s /etc/init.d/openerp-test-7069 /etc/rc3.d/S22openerp-test-7069
sudo ln -s /etc/init.d/openerp-test-7069 /etc/rc4.d/S22openerp-test-7069
sudo ln -s /etc/init.d/openerp-test-7069 /etc/rc5.d/K22openerp-test-7069

Note:

  • S## means to start at this run level. K## means not to start at this run level.
  • ## is the sequence number.

 

Example of start-up file.

#!/bin/sh

### BEGIN INIT INFO
# Provides:		openerp-server
# Required-Start:	$remote_fs $syslog
# Required-Stop:	$remote_fs $syslog
# Should-Start:		$network
# Should-Stop:		$network
# Default-Start:	2 3 4 5
# Default-Stop:		0 1 6
# Short-Description:	Enterprise Resource Management software
# Description:		Open ERP is a complete ERP and CRM software.
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/opt/openerp_mh/server/openerp-server
NAME=openerp-server-mh
DESC=openerp-server-mh
CONFIG=/opt/openerp_mh/mh_addons/openerp-server.conf
LOGFILE=/var/log/openerp/openerp-server-mh.log
USER=openerp
DBFILTER=MH*

test -x ${DAEMON} || exit 0

set -e

do_start () {
    echo -n "Starting ${DESC}: "
    start-stop-daemon --start --quiet --pidfile /var/run/${NAME}.pid --chuid ${USER} --background --make-pidfile --exec ${DAEMON} -- --config=${CONFIG} --db-filter=${DBFILTER} --logfile=${LOGFILE}
    echo "${NAME}."
}

do_stop () {
    echo -n "Stopping ${DESC}: "
    start-stop-daemon --stop --quiet --pidfile /var/run/${NAME}.pid --oknodo
    echo "${NAME}."
}

case "${1}" in
    start)
        do_start
        ;;

    stop)
        do_stop
        ;;

    restart|force-reload)
        echo -n "Restarting ${DESC}: "
        do_stop
        sleep 1
        do_start
        ;;

    *)
        N=/etc/init.d/${NAME}
        echo "Usage: ${NAME} {start|stop|restart|force-reload}" >&2
        exit 1
        ;;
esac

exit 0