Skip to content Skip to sidebar Skip to footer

Change A Field Value Within An If Statement In Odoo 8

I have been using Odoo 8 with Ubuntu 14.04. I have an onchange function and under that an If statement in which I am trying to change a field value but it does not get change . All

Solution 1:

If you raise any exception then your all previous statements which are uncommit will be rolled back. So value will not be set to the fields if you raise from method.

Choose either raise or set default value there, you should return warning if you want, it will not break your execution.

For returning warning check the onchange method of price list in sale order.


Solution 2:

You have to raise the exception at the end! Raising an exception aborts the current execution of your code, this is why your values don't get changed. These statements aren't reached.

You could rewrite your ifs in a more Pythonic style such as:

if not (min_sal < self.emp_propose_total < max_sal):
    self.emp_propose_basic = 0.0
    self.emp_propose_allowance = 0.0
    raise osv.except_osv('out of range','Proposed Total must be in between %s to %s' % (max_sal, min_sal))

Post a Comment for "Change A Field Value Within An If Statement In Odoo 8"