如何在odoo中自动更改选择字段 [英] How to Change selection field automatically in odoo

查看:225
本文介绍了如何在odoo中自动更改选择字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Odoo8.我有一个视图,其中包含一组组合框类型字段和一个选择字段.我想对组合框字段进行测试,如果所有复选框均已选中,则选择字段值应更改.这是我到目前为止所拥有的:

I'm working on Odoo 8. I have a view that contains a set of combo-box type fields and a selection field. I want to make a test on the combo-box fields and if there are all checked then the selection field value should change. Here is what i have so far:

def get_etat_dossier(self,cr,uid,ids,args,fields,context=None):
    res = {}
    for rec in self.browse(cr,uid,ids):

        if rec.casier_judiciare==True: # test field if = true 
            res[rec.id]= 02 # field etat_dos type selection = Dossier Complet
        else:
            res[rec.id] = 01

    return res


_columns= {

   'casier_judiciare' : fields.boolean('Casier Judiciaire'), #  field to test 

   'reference_pro' : fields.boolean('Réferences Professionnelles'),
   'certificat_qual' : fields.boolean('Certificat de qualification'),
   'extrait_role' : fields.boolean('Extrait de Role'),
   'statut_entre' : fields.selection([('eurl','EURL'),('sarl','SARL')],'Statut Entreprise'),
   'etat_dos': fields.selection([('complet','Dossier Complet'),('manquant','Dossier Manquant')],'Etat De Dossier'), # field ho change after test 
}

这是我的视图的代码

<group col='4' name="doss_grp" string="Dossier de Soumission" colspan="4" >       <field name="casier_judiciare"/> 
    <field name="certificat_qual"/> 
    <field name="extrait_role"/> 
    <field name="reference_pro"/> 
    <field name="statut_entre" style="width:20%%"/> 
    <field name="etat_dos"/> 
</group>

推荐答案

casier_judiciare字段中添加onchange属性,然后将要检查的所有其他字段作为参数传递给这样的方法

Add an onchange attribute to the casier_judiciare field and then pass all the other fields you want to check as arguments to the method like this

<group col='4' name="doss_grp" string="Dossier de Soumission" colspan="4" >
    <field name="casier_judiciare" on_change="onchange_casier_judiciare(casier_judiciare, certificat_qual, extrait_role, reference_pro)"/> 
    <field name="certificat_qual"/> 
    <field name="extrait_role"/> 
    <field name="reference_pro"/> 
    <field name="statut_entre" style="width:20%%"/> 
    <field name="etat_dos"/> 
</group>

在模型文件中定义这样的方法,并使用if语句检查它们是否全部为True(这意味着它们都已被检查),如果是,则可以返回具有所需值的字典.选择字段,在这种情况下,etat_dos将更改为Dossier Complet

In your model file define the method like this and use an if statement to check if they're all True (That means they have all been checked), if so then you can return a dictionary with any value you want for the selection field, in this case etat_dos will change to Dossier Complet

def onchange_casier_judiciare(self, cr, uid, ids, casier_judiciare, certificat_qual, extrait_role, reference_pro, context=None):
    if casier_judiciare and certificat_qual and extrait_role and reference_pro: # if they're all True (that means they're all checked):
        values = {'value': {'etat_dos': 'complet'}} #set the value of etat_dos field

        return values

请注意,onchange仅在casier_judiciare字段上触发,但是您也可以在其他字段上设置onchange,它应该可以正常工作

Note that the onchange is only triggered on the casier_judiciare field but you can also set onchange on other fields and it should work just fine

这篇关于如何在odoo中自动更改选择字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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