当状态为草稿或者结算时候,显示结算。
当进行结算操作,状态变为‘到期收款’或者其他状态时,就显示单据状态
model.py 文件, 'dynamic_state'选项为动态显示的内容
state = fields.Selection([
('draft', '草稿'),
('verify', '已审核'),
('due_payment', '到期收款'),
('discount', '贴现'),
('endorsement', '背书'),
('endorsement_return', '背书退回'),
('bill_return', '票据退回'),
('dynamic_state', '结算'), # 动态显示,设置默认值为'结算'
], string='单据状态', copy=False, index=True, track_visibility='onchange', track_sequence=3, default='draft')
xml文件, 'dynamic_state' 会根据单据的状态动态显示 dynamic_visible属性中的值
<field name="state" widget="statusbar" readonly="1" statusbar_visible="draft,verify,dynamic_state"
dynamic_visible="due_payment,discount,endorsement,endorsement_return,bill_return"/>
js文件,继承relational_fields.js 。FieldStatus的widget进行重写。
odoo.define('ps_base.statusbar_dynamic_visible', function (require) {
"use strict";
var relational_fields = require('web.relational_fields');
relational_fields.FieldStatus.include({
_setState: function () {
var self = this;
if (this.field.type === 'many2one') {
this.status_information = _.map(this.record.specialData[this.name], function (info) {
return _.extend({
selected: info.id === self.value.res_id,
}, info);
});
} else {
var selection = this.field.selection;
if (this.attrs.statusbar_visible) {
var restriction = this.attrs.statusbar_visible;
if (this.attrs.dynamic_visible) {
var dynamic_state = this.attrs.dynamic_visible.split(",");
if (dynamic_state.indexOf(self.value) !== -1) {
restriction = restriction.replace('dynamic_state', self.value);
}
}
restriction = restriction.split(",");
selection = _.filter(selection, function (val) {
return _.contains(restriction, val[0]) || val[0] === self.value;
});
}
this.status_information = _.map(selection, function (val) {
return {id: val[0], display_name: val[1], selected: val[0] === self.value, fold: false};
});
}
},
});
}
);
====================================================================================================================================