--- tags: ODOO, 隨手筆記 --- # 隨手筆記 - 用 qweb 模板引擎設計頁面 ## 撰文動機 對於面向使用者的功能,像是報修或者系統 bug 等需要填單的問題,就不會像之前寫模組的方式,而是改用內建模組的 website,建立相對應的頁面,並且配合可讀的路由,讓使用者更方便使用。 ## 基本架構 先講一下最基本的架構,在這個架構下只需要撰寫 xml,不須動到 python 的東西,但由於沒有碰到python 的關係,在基本架構下是沒辦法針對 model 做操作的。 ### template ```htmlembedded <template id="sample_template" name="Sample template"> <t t-call="website.layout"> <div class="or_structure"> <div class="container"> 123 </div> </div> </t> </template> ``` ### page ```xml <record id="sample_page" model="website.page"> <field name="name">Sample page</field> <field name="url">/sample_page</field> <field name="view_id" ref="sample_template"/> <field name="website_indexed">True</field> <field name="website_published">True</field> <field name="website_id" ref="website.default_website"/> </record> ``` ### menu ```xml <record id="menu_sample_menu" model="website.menu"> <field name="name">sample menu</field> <field name="url">/sample_menu</field> <field name="parent_id" ref="website.main_menu"/> </record> ``` ## 進階用法 進階用法的部分會用到 odoo controller 的路由功能,可以配合環境變數的方式讀到資料庫的內容,這樣就可以操作 model 了。 ### template ```xml <template id="sample_template" name="Sample template"> <t t-call="website.layout"> <div class="or_structure"> <div class="container"> 123 </div> </div> </t> </template> ``` ### python ```python @http.route('/repair_order', auth='user', type='http', website=True) def repair_order_page(self, **kw): http.request.env['repair.order'].sudo().create(kw) return http.request.render('app_panel.new_repair_order_view', {}) ``` ### menu ```xml <record id="menu_sample_menu" model="website.menu"> <field name="name">sample menu</field> <field name="url">/sample_menu</field> <field name="parent_id" ref="website.main_menu"/> </record> ``` ## 結語 odoo 給的彈性實在很大,不過需要習慣一下他的設計模式,第一次接觸這樣的系統會很不熟悉,不過可以感覺得出他的好處,在和主管討論需求時,由於整體的設計習慣都是統一的,很容易就可以判斷新的需求的實現難度,在設計功能時直接使用 odoo 的設計習慣去想也能很快地找到現成的東西做使用,是一套很適合沒碰過大型系統設計的新手值得學習的一套系統。
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up