如何在其他模型odoo10中修改one2many或many2one字段 [英] How to modify the one2many or many2one field in other model odoo10
问题描述
任何人都可以举例说明如果在type-one2many字段中进行了更改,如何在另一个模型中修改该字段.
Can any one tell with example how to modify the field in another model if changed in type-one2many field.
例如,我有两个模型a)hr_shifts b)hr_contract 在hr_shifts中,有一个2个字段(emp_name_ids),当更改此字段时,单击保存"按钮后,会在hr_contract中反映出来. 此代码有效,但是当我在one2many字段(emp_name_ids)中使用时,此代码不起作用
For example, I have two models a) hr_shifts b)hr_contract in hr_shifts there is one2many field(emp_name_ids) when changed in this fields reflect in hr_contract after click on save button. this code work, but when I used in one2many field (emp_name_ids) it doesn't work
@api.depends('schedule')
def _onchange_schedule(self):
for item in self.hr_shifts_line:
current=self.env['hr.contract'].search([('employee_id','=',item.emp_name_ids.id)])
current.write({'working_hours':self.schedule.id})
推荐答案
One2many
和Many2many
使用特殊的命令"格式来操作存储在字段中/与字段相关的记录集.
One2many
and Many2many
use a special "commands" format to manipulate the set of records stored in/associated with the field.
您应该尝试:
current.write({'emp_name_ids': [(6, 0, [ids])]})
有关特殊命令的更多信息,请参阅文档: https ://www.odoo.com/documentation/10.0/reference/orm.html#model-reference .
For more info regarding the special commands see docs: https://www.odoo.com/documentation/10.0/reference/orm.html#model-reference.
向下滚动至CRUD部分,您将找到所有可能的命令((6, _, ids)
仅是其中几个命令之一).
Scroll a bit down to the CRUD section there you will find all possible commands ((6, _, ids)
is only one of a few more).
这篇关于如何在其他模型odoo10中修改one2many或many2one字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!