在Odoo 8的If语句中更改字段值 [英] Change a field value within an If statement in Odoo 8

查看:91
本文介绍了在Odoo 8的If语句中更改字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在Ubuntu 14.04上使用Odoo 8.我有一个onchange函数,在该if语句下,我试图更改一个字段值,但没有得到更改.我需要的是将空值或0.0分配给该字段,但是失败了.我的Python代码如下:

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 I need is to assign the null value or 0.0 to the field but failed. My Python code is below:

def _proposed_total(self):
    print self.emp_propose_allowance
    self.emp_propose_total = self.emp_propose_basic + self.emp_propose_allowance
    cr=self._cr
    uid=self._uid
    ids=self._ids 
    val=int(self.employee_name)
    if(val):
       cr.execute("select max_salary,min_salary from hr_job where id in (select job_id from hr_employee where id='"+str(val)+"')")
       res=cr.fetchall()
       for data in res:
               max_sal=data[0]
               min_sal=data[1]
           if(self.emp_propose_total>max_sal): 
              raise osv.except_osv('out of range','Proposed Total must be in between "'+str(max_sal)+'" to "'+str(min_sal)+'"')            
              self.emp_propose_basic=0.0
              self.emp_propose_allowance=0.0

           elif(self.emp_propose_total<min_sal):
              raise osv.except_osv('out of range','Proposed Total must be in between "'+str(max_sal)+'" to "'+str(min_sal)+'"')
              self.emp_propose_basic=0
              self.emp_propose_allowance=0  
        else:
           cr.execute("select wage from hr_contract where employee_id=0") 

我想更改self.emp_propose_basic和self.emp_propose_allowance.我不确定在这里我做错了什么.请Plz指导我或指出我的错误以实现这一目标

I want to change the self.emp_propose_basic and self.emp_propose_allowance . I am not sure what I am doing wrong here. Plz guide me or point me my mistake to achieve this

推荐答案

如果引发任何异常,则所有之前未提交的语句将被回滚.因此,如果您从方法中引发,则不会将值设置为字段.

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.

这篇关于在Odoo 8的If语句中更改字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆