Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
878 Visualizzazioni

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
Abbandona
Post correlati Risposte Visualizzazioni Attività
1
ago 25
983
1
mag 25
1740
0
nov 24
1772
2
ott 24
1878
0
ago 24
1512