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

I have created a "assign" button in Helpdesk Module which on click opens a Maintenance Request form with some data from helpdesk. And the problem is that I've to save the request manually every time. What should I do to save the maintenance request automatically and not affecting the current method on button click.

Here's my python method for button. 

@api.multi
def on_assigned(self):
return {
'res_model': 'maintenance.request',
'type': 'ir.actions.act_window',
'context': {
'default_helpdesk_id': self.id,
'default_name': self.name,
},
'domain': [('customer_id', '=', self.customer_id)],
'view_mode': 'form',
'view_type': 'form',
'res_id': self.env['maintenance.request'].search([('helpdesk_id', '=', self.id)]).id,
'view_id': self.env.ref("maintenance.hr_equipment_request_view_form").id,
}

I just want to add the "Save" functionality on this button click. Any luck? 

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

Here in the button click you are returning maintenance.request model with some default values inside the context, so for the record to be created you have to click the Save Button. As you need to create the record without clicking the save button, what you can do is that, create record in the maintenance.request model from code and return the created record id in the return.

@api.multi
def on_assigned(self):
vals = {
'helpdesk_id': self.id,
'name': self.name
}
# you can update above dictionary with other values and required fields
new_rec = self.env['maintenance.request'].create(vals)

return {
'name': _('Maintenance Request'),
'view_type': 'form',
'view_mode': 'form',
'view_id': self.env.ref("maintenance.hr_equipment_request_view_form").id,
'res_model': 'maintenance.request',
'domain': [('customer_id', '=', self.customer_id)],
'context': {
'default_helpdesk_id': self.id,
'default_name': self.name,
}, 'type': 'ir.actions.act_window',
'res_id': new_rec.id,
}

Thanks

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Edited:

@niyas Raphy thanks for the help its working but it is showing the maintenance form. Can I redirect it back to previous form. How?

Ảnh đại diện
Huỷ bỏ

'target': 'new' remove it and try

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 8 20
5451
3
thg 2 24
4730
2
thg 3 22
5285
2
thg 7 24
2466
1
thg 6 24
4985