跳至內容
選單
此問題已被標幟
723 瀏覽次數

I have a many-to-many relationship with my Employee and Project models. But since in my intermediate table there must be an attribute called "employee_performance" I had to create an intermediate table to add it and make one2many many2one relationships to simulate this many2many relationship, this is how it looks in code:


class Employee(models.Model):   

​_name = "company.employee"    

​_description = "Employee"

​ name = fields.Char("Name", required=True)

employee_proyect_ids = fields.One2many("company.employee_proyect", "employee_id", string="Proyects") 


class Proyect(models.Model):   

​_name = "company.proyect"    

​_description = "Proyect"

​ name = fields.Char("Name", required=True)

employee_proyect_ids = fields.One2many("company.employee_proyect", "proyect_id", string="Employees") 


class EmployeeProyect(models.Model):   

​_name = "company.employee_proyect"    

​_description = "Employees and Proyects"

​ employee_performance = fields.Integer("Performance", required=True)

employee_id = fields.Many2one("company.employee", string="Employee") 

​proyect_id = fields.Many2one("company.proyect", string="Proyect")



But with this implementation, when, for example, I assign a project to an employee, and then I want to assign another project, the previously selected project appears again to choose from again. On the other hand, when I made the relationship with "many2many" between both tables and made the same project assignment, only the projects that were not assigned to my employee were shown, making it impossible for me to grant him repeated projects. 
And this is the behavior I need but it doesn't work with my implementation, so, how can I achieve this?

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
8月 25
530
1
5月 25
1338
0
11月 24
1432
2
10月 24
1520
0
8月 24
1252