Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
4007 Lượt xem

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
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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).
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 5 20
3623
2
thg 11 19
6824
0
thg 1 21
2357
1
thg 8 25
3612
1
thg 11 24
1482