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

Odoo has the ability to select a layout in the settings. To do this, in the "Configure document layout" we select layout and click save. After that, the layout is replaced with the selected one.

I am interested in the ability to change the layout from another location without using this interface.

For simplicity, you can imagine this: There is a button by pressing which layout will change from "Light" to "Boxed".

I figured out how to get the layout ID or name:

class Test(models.TransientModel):  
    _inherit = 'base.document.layout'
    def get_id_and_name(self):
        current_layout_id = self.report_layout_id.id
        current_layout_name = self.report_layout_id.name

I also learned that you don't have to change the ‘report_layout_id’ field to change the layout. If we make the ‘external_report_layout_id’ field visible in the Document Layout view, we will see this field. At the same time, if you change it, then in the ‘report_layout_id’ field the selection will not change, but when saving the layout will be as in ‘external_report_layout_id’.

(in the screenshot, after saving, the layout will change to a 'clean', despite the fact that it is selected in the box


Next, I wanted to know what the "save" button does in the layout selection window. I was expecting to see some code that will show me how to change the layout to the selected one, however I don't understand what it does.

def document_layout_save(self):
    
# meant to be overridden
    
return self.env.context.get('report_action'or {'type''ir.actions.act_window_close'}


Ideally, I would like to know how to write code that, when run, will change the layout from one to another.

Def change_document_layout(first_layout, second_layout): #first and second layout it is ID or name of layout


Do you have any ideas or guesses?


                
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 3 21
5178
0
thg 12 22
3407
1
thg 5 22
4695
0
thg 11 21
21
0
thg 11 21
3763