Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
163 views
in Technique[技术] by (71.8m points)

python 3.x - How to modify the one2many or many2one field in other model odoo10

Can any one tell with example how to modify the field in another model if changed in type-one2many field.

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})
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

One2many and Many2many use a special "commands" format to manipulate the set of records stored in/associated with the field.

You should try:

current.write({'emp_name_ids': [(6, 0, [ids])]})

For more info regarding the special commands see docs: https://www.odoo.com/documentation/10.0/reference/orm.html#model-reference.

Scroll a bit down to the CRUD section there you will find all possible commands ((6, _, ids) is only one of a few more).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...