Hello can some one give and example how should method look like when we need copy ids from one model to another.
For example we need to copy follower_ids from project.project to project.task. 
Odoo is the world's easiest all-in-one management software.
 It includes hundreds of business apps:
Hello can some one give and example how should method look like when we need copy ids from one model to another.
For example we need to copy follower_ids from project.project to project.task. 
When you are working with o2m & m2m fields, you should use the special operators (search by the key '(0, _, values)' here: https://www.odoo.com/documentation/8.0/reference/orm.html)
In your example:
for follower in project_id.message_follower_ids:
if follower not in task_id.message_follower_ids:
task_id.message_follower_ids = [(4,partner.id)]
Or in case task for sure doesn't have the same followers before:
task_id.message_follower_ids = [(6,0,project_id.message_follower_ids.ids)]
You may add this to create or write
i'm using this method as button, but i get error NameError: global name 'project_id' is not defined
here is my method
@api.multi
def add_project_followers(self):
for follower in project_id.message_follower_ids:
if follower not in task_id.message_follower_ids:
task_id.message_follower_ids = [(6, 0, project_id.message_follower_ids.ids)]
It was an example! Please read the documentation how to write functions in Odoo / Python. In your case you try to apply a variable which doesn't exist. It should be sth like:
@api.multi
def add_project_followers(self):
for task in self:
for follower in task.project_id.message_follower_ids:
if follower not in task.message_follower_ids:
task.message_follower_ids = [(4, follower.id)]
| 관련 게시물 | 답글 | 화면 | 활동 | |
|---|---|---|---|---|
| 
            
                Expected singleton
            
            
                    해결 완료
            
         |  | 9 3월 20  | 42763 | |
|  | 2 10월 18  | 4550 | ||
|  | 1 10월 17  | 4863 | ||
|  | 2 4월 15  | 21235 | ||
|  | 3 3월 15  | 8285 |