触发了Onchange,但没有用视图上的值填充字段(Odoo)(Onchange triggered but didnt fill the fields with the values on the view (Odoo))

我已经创建了一个onchange函数,其目标是在笔记本工作表视图上自动填充值。

我的功能正常工作,但它没有填充视图中的字段。

我该怎么做才能做到这一点?

这是我从pdb得到的:

这是我想要的价值,但它没有填补视图上的字段

这是py:

@api.multi
@api.model
@api.onchange('employee_id')
def onchange_lines(self):
    import pdb;pdb.set_trace()
    if self.employee_id:
        check = self.env['hr.employee'].sudo().search([('id','=',self.employee_id.id)])
        for empy in check:
            if empy.id:
                res = {}
                vals = []
                if not empy:
                    vals.
                    res.update({'self.job_id':'', 'self.nik':''})
                else:
                    vals.append({'self.job_id':empy.job_id, 'self.nik':empy.identification_id})
                    res.update(vals)
            return res
 

这是字段的xml:

<!-- language: xml --> <notebook> <page string="Employees"> <field name="employee_ids"> <tree string="Employees" editable="bottom"> <field name="nik"/> <field name="employee_id"/> <field name="job_id"/> <field name="ovrtm"/> <field name="ttalmtp"/> </tree> </field> </page> </notebook>

I've made an onchange function, the goal of which is to autofill the values on the notebook sheet view.

My function was working properly but it didn't fill the field on the view.

What should i do to achieve this?

this was what i got from pdb:

and that was the value i want but it didnt fill the field on the view

and here is the py :

@api.multi
@api.model
@api.onchange('employee_id')
def onchange_lines(self):
    import pdb;pdb.set_trace()
    if self.employee_id:
        check = self.env['hr.employee'].sudo().search([('id','=',self.employee_id.id)])
        for empy in check:
            if empy.id:
                res = {}
                vals = []
                if not empy:
                    vals.
                    res.update({'self.job_id':'', 'self.nik':''})
                else:
                    vals.append({'self.job_id':empy.job_id, 'self.nik':empy.identification_id})
                    res.update(vals)
            return res
 

and here is the xml for the fields :

<!-- language: xml --> <notebook> <page string="Employees"> <field name="employee_ids"> <tree string="Employees" editable="bottom"> <field name="nik"/> <field name="employee_id"/> <field name="job_id"/> <field name="ovrtm"/> <field name="ttalmtp"/> </tree> </field> </page> </notebook>

最满意答案

在onchange的新的api中你可以直接在记录集对象中赋值。

您可以按照以下代码。

@api.onchange('employee_id') def onchange_lines(self): import pdb;pdb.set_trace() if self.employee_id: check = self.env['hr.employee'].sudo().search([('id','=',self.employee_id.id)]) for empy in check: if empy.id: res = {} vals = [] if not empy: self.job_id=False self.nik=False else: self.job_id=empy.job_id self.nik=empy.identification_id

这可能对你有所帮助。

In odoo new api of onchange you can directly assign value in record-set object.

You can follow below code.

@api.onchange('employee_id') def onchange_lines(self): import pdb;pdb.set_trace() if self.employee_id: check = self.env['hr.employee'].sudo().search([('id','=',self.employee_id.id)]) for empy in check: if empy.id: res = {} vals = [] if not empy: self.job_id=False self.nik=False else: self.job_id=empy.job_id self.nik=empy.identification_id

This may help you.

触发了Onchange,但没有用视图上的值填充字段(Odoo)(Onchange triggered but didnt fill the fields with the values on the view (Odoo))

我已经创建了一个onchange函数,其目标是在笔记本工作表视图上自动填充值。

我的功能正常工作,但它没有填充视图中的字段。

我该怎么做才能做到这一点?

这是我从pdb得到的:

这是我想要的价值,但它没有填补视图上的字段

这是py:

@api.multi
@api.model
@api.onchange('employee_id')
def onchange_lines(self):
    import pdb;pdb.set_trace()
    if self.employee_id:
        check = self.env['hr.employee'].sudo().search([('id','=',self.employee_id.id)])
        for empy in check:
            if empy.id:
                res = {}
                vals = []
                if not empy:
                    vals.
                    res.update({'self.job_id':'', 'self.nik':''})
                else:
                    vals.append({'self.job_id':empy.job_id, 'self.nik':empy.identification_id})
                    res.update(vals)
            return res
 

这是字段的xml:

<!-- language: xml --> <notebook> <page string="Employees"> <field name="employee_ids"> <tree string="Employees" editable="bottom"> <field name="nik"/> <field name="employee_id"/> <field name="job_id"/> <field name="ovrtm"/> <field name="ttalmtp"/> </tree> </field> </page> </notebook>

I've made an onchange function, the goal of which is to autofill the values on the notebook sheet view.

My function was working properly but it didn't fill the field on the view.

What should i do to achieve this?

this was what i got from pdb:

and that was the value i want but it didnt fill the field on the view

and here is the py :

@api.multi
@api.model
@api.onchange('employee_id')
def onchange_lines(self):
    import pdb;pdb.set_trace()
    if self.employee_id:
        check = self.env['hr.employee'].sudo().search([('id','=',self.employee_id.id)])
        for empy in check:
            if empy.id:
                res = {}
                vals = []
                if not empy:
                    vals.
                    res.update({'self.job_id':'', 'self.nik':''})
                else:
                    vals.append({'self.job_id':empy.job_id, 'self.nik':empy.identification_id})
                    res.update(vals)
            return res
 

and here is the xml for the fields :

<!-- language: xml --> <notebook> <page string="Employees"> <field name="employee_ids"> <tree string="Employees" editable="bottom"> <field name="nik"/> <field name="employee_id"/> <field name="job_id"/> <field name="ovrtm"/> <field name="ttalmtp"/> </tree> </field> </page> </notebook>

最满意答案

在onchange的新的api中你可以直接在记录集对象中赋值。

您可以按照以下代码。

@api.onchange('employee_id') def onchange_lines(self): import pdb;pdb.set_trace() if self.employee_id: check = self.env['hr.employee'].sudo().search([('id','=',self.employee_id.id)]) for empy in check: if empy.id: res = {} vals = [] if not empy: self.job_id=False self.nik=False else: self.job_id=empy.job_id self.nik=empy.identification_id

这可能对你有所帮助。

In odoo new api of onchange you can directly assign value in record-set object.

You can follow below code.

@api.onchange('employee_id') def onchange_lines(self): import pdb;pdb.set_trace() if self.employee_id: check = self.env['hr.employee'].sudo().search([('id','=',self.employee_id.id)]) for empy in check: if empy.id: res = {} vals = [] if not empy: self.job_id=False self.nik=False else: self.job_id=empy.job_id self.nik=empy.identification_id

This may help you.