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

how to add a button in tree view to get the form view of the desired record(as the list view is in editable mode,it wont directly go to the form view)?.how to set the action of the button to open the edit mode of form view?

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

not really useful since you can open the form by clicking directly on the record line, why do you need a button in the record to do specifically the same? or in the top buttons of the tree where you can select multiple record lines?

Tác giả

i actually changed the list view as editable ,so it wont go to the form view directly when click.so i would like to add a edit button next to every record,so when i click on edit,it should go to the edit part of form view.

Câu trả lời hay nhất

1. Add a function (something like this) to the model that opens the form

def open_to_form_view(self, cr, uid, ids, context=None):

if not context:
context = {}

name = '<Name>' res_model = '<model>'
view_name = '<view>'

document_id = self.browse(cr, uid, ids[0]).id

view = models.get_object_reference(cr, uid, name, view)
view_id = view and view[1] or False


return {
'name': (name),
'view_type': 'form',
'view_mode': 'form',
'view_id': [view_id],
'res_model': res_model,
'type': 'ir.actions.act_window',
'nodestroy': True,
'target': 'current',
'res_id': document_id,
}

 

2. Add a button to your treeview like this:

<button name="open_to_form_view" type="object" icon="STOCK_INDEX"/>

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

can u explain deeper about the

    name = '<Name>'
 res_model = '<model>'  
 view_name = '<view>'
Ảnh đại diện
Huỷ bỏ

name as you give.

res_model like sale.order, product.product (table name)

view_name --> sale.view_order_form (sale order form view)

view_name xml id of sale order form view.

sorry about the very late reply, Thank you for explaining I understand it now