Skip to Content
Menu
This question has been flagged
1 Reply
3120 Views

Hi,

I am trying to map project to a employee profile

What I am trying to do is,I have a provision that is add employees in a project creation form

By clicking Add employees button there appears a wizard that can select multiple employees(many2many field), and that time the selected employees profile have the field project(many2many) that should automatically be filled.I tried this code

add_resources = fields.Many2many("hr.employee", string="Select Resources") //selecting employees for project

@api.multi
def add_employees_to_project(self):
for item in self.add_resources:
item.project_ids = self.id 
  self.add_resources = False

return {
'type': 'ir.actions.client',
'tag': 'reload',
}@api.multi
def add_resource_wizard(self):
context = {'edit': True, }
form_view = self.env.ref('project_ft.resource_project_form_view_add_wiz')
context['form_view_initial_mode'] = 'edit'
return {'name': _('Add Employees To Project'),
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'project.project',
'res_id': self.id,
'views': [(form_view.id, 'form'), ],
'context': context,
'target': 'new'}
Thank in advance 
Veni V R
Avatar
Discard
Best Answer

Without using a button try to add employees directly to the projects using a many2many field inside a page. Here the employees and project get the many2many relation and you can also display the same under the employee profile. If you are adding it using a wizard then you have to update these relations for project and employee id manuallly using a function. So you have to modify the definition of many2many accordingly, like 

fields.Many2many(comodel_name="hr.employee",relation="employees_project_rel"
column1="realtion1", column2="relation2", string="Select Resources")


:param comodel_name: name of the target model (string)

The attribute ``comodel_name`` is mandatory except in the case of related
fields or field extensions.

:param relation: optional name of the table that stores the relation in
the database (string)

:param column1: optional name of the column referring to "these" records
in the table ``relation`` (string)

:param column2: optional name of the column referring to "those" records
in the table ``relation`` (string)

So in your function you have to provide the values of relations accordingly(if you are using extra wizard).
Avatar
Discard
Related Posts Replies Views Activity
2
May 20
2692
2
Nov 19
5203
0
Jan 21
1497
1
Nov 24
100
1
Nov 24
147