1. 自定义按钮响应事件
1.1 dodo9中的实现方式
1.1.1 在py中定义一个辅助用的字段
report_btn_submit = fields.Char(string='提交按钮', default='提交')
1.1.2 在xml中定义按钮
<field type="button" name="report_btn_submit" readonly="1" class="oe_read_only btn btn-primary report_btn_submit"/>
1.1.3. 在js中定义响应事件
FormView.include({
events: _.defaults({
'click .report_btn_submit': 'report_submit_click',
}, FormView.prototype.events),
report_submit_click: function (kwargs) {
// 响应代码
}
});
1.2 dodo13中的实现方式
1.2.1 在xml中定义按钮
不指定type属性的值,定义special属性
<button string="提交" special="report_btn_submit" class="oe_highlight"/>
1.2.2 在js中定义响应事件
在js中给FormController添加_onButtonClicked_special_{special}方法
FormController.include({
_onButtonClicked_special_report_btn_submit: function (ev) {
// 响应代码
},
});
2. 自定义字段描述弹窗
2.1 演示效果
2.2 dodo9中的实现方式
2.2.1 定义xml
<group class="dtdream_hr_recruit_class">
<div class="o_row">
<label for="position_type" readonly="1"/>
<span class='recruit_position_type'>(岗位体系说明)</span>
</div>
<div>
<field name="position_type" required="1"/>
</div>
</group>
2.2.2 定义样式
.recruit_position_type{
color: #81c48f;
cursor: pointer;
font-size: 8px;
}
.dtdream_hr_recruit_class tr:nth-child(3) td:nth-child(1){
width: 35% !important;
}
2.2.3 定义响应的js代码
odoo.define('dtdream_hr_recruit', function (require) {
var FormView = require('web.FormView');
var form_common = require('web.form_common');
FormView.include({
events: _.defaults({
'click span.recruit_position_type':'recruit_tooltip_show',
}, FormView.prototype.events),
recruit_tooltip_show: function(){
var pop = new form_common.FormViewDialog(self, {
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'dtdream.hr.recruit.receptiontool.wizard',
'res_id': '',
'context':'',
}).open();
$('.modal-footer').hide()
},
});
});
2.2.4 定义弹出窗口的模型
from openerp import models
class dtdream_hr_recruit_receptiontool_wizard(models.TransientModel):
_name = "dtdream.hr.recruit.receptiontool.wizard"
2.2.5 定义弹出窗口的视图
<record id="view_dtdream_hr_recruit_receptiontool_wizard_form" model="ir.ui.view">
<field name="name">view.dtdream.hr.recruit.receptiontool.wizard.form</field>
<field name="model">dtdream.hr.recruit.receptiontool.wizard</field>
<field name="arch" type="xml">
<form>
<div>营销体系——市场部</div>
<div>技术体系——CTO office</div>
<div>运营体系——除上述两个部门外的其他部门</div>
</form>
</field>
</record>
<record id="act_help_post" model="ir.actions.act_window">
<field name="name">help</field>
<field name="res_model">dtdream.hr.recruit.receptiontool.wizard</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
2.3 dodo13中的实现方式
2.3.1 定义xml视图
<group>
<div class="o_td_label">
<label for="position_type"/>
<dtooltip title="岗位体系说明">
<span>(说明)</span>
<templates>
<ul>
<li>营销体系——市场部</li>
<li>技术体系——CTO office</li>
<li>运营体系——除上述两个部门外的其他部门</li>
</ul>
</templates>
</dtooltip>
</div>
<field name="position_type" required="1" nolabel="1"/>
</group>