即使一个人,也要活得像军队一样!

Odoo12-- 自定义配置面板

如题,Odoo开发过程中,有时遇到一些需求需要在页面中快速配置一些信息数据,此时就需要用到配置面板, 如下图所示:
配置面板

**主要分三步:
一是定义配置面板的模板
二是定义路由渲染模板
三是给指定模型视图绑定模板路由

代码如下:**

模板文件sale_onboarding_views.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- ONBOARDING STEPS -->
<template id="onboarding_quotation_layout_step">
<t t-call="base.onboarding_step">
<t t-set="title">Quotation Layout</t>
<t t-set="description">Customize the look of your quotations.</t>
<t t-set="done_icon" t-value="'fa-star'" />
<t t-set="done_text">Looks great!</t>
<t t-set="btn_text">Customize</t>
<t t-set="method" t-value="'action_open_sale_onboarding_quotation_layout'" />
<t t-set="model" t-value="'res.company'" />
<t t-set="state" t-value="state.get('account_onboarding_invoice_layout_state')" />
</t>
</template>
<template id="sale_onboarding_order_confirmation_step">
<t t-call="base.onboarding_step">
<t t-set="title">Confirmation &amp; Payment</t>
<t t-set="description">Choose how to confirm quotations and get paid.</t>
<t t-set="btn_text">Set payments</t>
<t t-set="method" t-value="'action_open_sale_onboarding_payment_acquirer'" />
<t t-set="model" t-value="'res.company'" />
<t t-set="state" t-value="state.get('sale_onboarding_order_confirmation_state')" />
</t>
</template>
<template id="sale_onboarding_sample_quotation_step">
<t t-call="base.onboarding_step">
<t t-set="title">Sample Quotation</t>
<t t-set="description">Send a quotation to test the customer portal.</t>
<t t-set="btn_text">Send sample</t>
<t t-set="method" t-value="'action_open_sale_onboarding_sample_quotation'" />
<t t-set="model" t-value="'res.company'" />
<t t-set="state" t-value="state.get('sale_onboarding_sample_quotation_state')" />
</t>
</template>

<!-- ONBOARDING PANEL-->
<template id="sale_quotation_onboarding_panel" name="sale.quotation.onboarding.panel">
<t t-call="base.onboarding_container">
<t t-set="classes" t-value="'o_onboarding_violet'" />
<t t-set="bg_image" t-value="'/sale/static/src/img/sale_quotation_onboarding_bg.jpg'"/>
<t t-set="close_method" t-value="'action_close_sale_quotation_onboarding'" />
<t t-set="close_model" t-value="'res.company'" />
<t t-call="base.onboarding_company_step" name="company_step" />
<t t-call="sale.onboarding_quotation_layout_step" name="quotation_layout_step" />
<t t-call="sale.sale_onboarding_order_confirmation_step" name="payment_acquirer_step" />
<t t-call="sale.sale_onboarding_sample_quotation_step" name="sample_quotation_step" />
</t>
</template>
<!-- ORDER CONFIRMATION -->
<record id="sale_onboarding_order_confirmation_form" model="ir.ui.view">
<field name="name">sale.order.confirmation.onboarding.form</field>
<field name="model">sale.payment.acquirer.onboarding.wizard</field>
<field name="inherit_id" ref="payment.payment_acquirer_onboarding_wizard_form" />
<field name="mode">primary</field>
<field name="priority">1000</field>
<field name="arch" type="xml">
<xpath expr="//div[@name='left-column']" position="attributes">
<attribute name="class">col col-4</attribute>
</xpath>
</field>
</record>
<record id="action_open_sale_onboarding_payment_acquirer_wizard" model="ir.actions.act_window">
<field name="name">How your customers can confirm an order</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">sale.payment.acquirer.onboarding.wizard</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="sale_onboarding_order_confirmation_form" />
<field name="target">new</field>
</record>
<!-- QUOTATION LAYOUT -->
<record id="sale_onboarding_quotation_layout_form" model="ir.ui.view">
<field name="name">sale.onboarding.quotation.layout.form</field>
<field name="model">res.company</field>
<field name="inherit_id" ref="base.view_company_document_template_form" />
<field name="mode">primary</field>
<field name="priority">1000</field>
<field name="arch" type="xml">
<xpath expr="//button[@special='save']" position="replace">
<button string="Apply" class="btn btn-primary" type="object" name="action_save_onboarding_quotation_layout" />
</xpath>
</field>
</record>
<record id="action_open_sale_onboarding_quotation_layout" model="ir.actions.act_window">
<field name="name">Configure your document layout</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">res.company</field>
<field name="view_mode">form</field>
<field name="view_type">form</field>
<field name="view_id" ref="sale_onboarding_quotation_layout_form" />
<field name="target">new</field>
</record>
<!-- SAMPLE QUOTATION -->
<record model="ir.ui.view" id="sale_onboarding_sample_quotation_form">
<field name="name">mail.compose.message.sale.onboarding.sample.quotation.form</field>
<field name="model">mail.compose.message</field>
<field name="inherit_id" ref="mail.email_compose_message_wizard_form" />
<field name="priority">1000</field>
<field name="mode">primary</field>
<field name="arch" type="xml">
<xpath expr="//span[@name='document_followers_text']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//button[@name='save_as_template']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//field[@name='template_id']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
</field>
</record>

<record id="action_open_sale_onboarding_sample_quotation" model="ir.actions.act_window">
<field name="name">Send a sample quotation.</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">mail.compose.message</field>
<field name="view_mode">form</field>
<field name="view_type">form</field>
<field name="view_id" ref="sale_onboarding_sample_quotation_form" />
<field name="target">new</field>
</record>
</odoo>

路由文件sale_onboarding_views.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import http
from odoo.http import request


class OnboardingController(http.Controller):

@http.route('/sales/sale_quotation_onboarding_panel', auth='user', type='json')
def sale_quotation_onboarding(self):
""" Returns the `banner` for the sale onboarding panel.
It can be empty if the user has closed it or if he doesn't have
the permission to see it. """

company = request.env.user.company_id
if not request.env.user._is_admin() or \
company.sale_quotation_onboarding_state == 'closed':
return {}

return {
'html': request.env.ref('sale.sale_quotation_onboarding_panel').render({
'company': company,
'state': company.get_and_update_sale_quotation_onboarding_state()
})
}

指定模型视图,添加banner_route属性,属性值为路由。

1
2
3
4
5
6
7
8
9
10
11
<record id="view_quotation_tree_with_onboarding" model="ir.ui.view">
<field name="name">sale.order.tree</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="view_quotation_tree"/>
<field name="mode">primary</field>
<field name="arch" type="xml">
<xpath expr="//tree" position="attributes">
<attribute name="banner_route">/sales/sale_quotation_onboarding_panel</attribute>
</xpath>
</field>
</record>

以上, 为自定义配置面板大致过程。

-------------本文结束感谢您的阅读-------------