Skip to Content
Menu
This question has been flagged
664 Views

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?

Avatar
Discard
Related Posts Replies Views Activity
1
May 25
1105
0
Nov 24
1290
2
Oct 24
1353
0
Aug 24
1175
0
Aug 24
1063