odoo12 在网站上增加菜单以及功能
2020-03-03 本文已影响0人
隔壁小红馆
公司为了方便,有时需要在网站上直接增加菜单来查看利用某些功能
以自己写过的为例:
图片.png
-
先在顶部定义一个名为 Museum Ticket 的菜单
图片.png
#xml 定义菜单
<odoo>
<record id="menu_buy_ticket_management_menu" model="website.menu">
<field name="name">Museum Ticket</field>
<field name="url">/buy_ticket_management</field>
<field name="parent_id" ref="website.main_menu"/>
<field name="sequence" type="int">31</field>
</record>
</odoo>
#controllers.py 定义点击菜单完跳转到那个视图里去
@http.route(['/buy_ticket_management', '/search/time'], type='http', auth="user", website=True, csrf=False)
def index(self, search=''):
mail_id = request.env()['ticket.management'].sudo().search([('maintain', '=', False)])
manage = []
for mail in mail_id:
if mail.ticket_date == fields.Date.today():
manage += [mail]
if search:
manage = []
search_time = datetime.datetime.strptime(search, '%Y-%m-%d').date()
if 0 <= (search_time - fields.Date.today()).days <= 30:
mail_id = request.env()['ticket.management'].sudo().search(
[('maintain', '=', False), ('ticket_date', '=', search)])
for mail in mail_id:
manage += [mail]
else:
manage = []
values = {
'mail_id': manage,
}
return request.render('ticket_management.template_buy_ticket_management', values)
-
点击完菜单后根据路径跳转指定视图
图片.png
<template id="template_buy_ticket_management" name="Museum Ticket Management">
<t t-call="website.layout">
<div class="col-md-6 offset-md-3" style="padding-bottom:25px;">
......
</div>
</t>
</template>
- 然后根据需要定义适合自己的视图页面
看完记得点赞哦,笔芯