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

Odoo12-- statebar根据单据状态动态显示

当状态为草稿或者结算时候,显示结算。

已审核状态

#####当进行结算操作,状态变为‘到期收款’或者其他状态时,就显示单据状态
到期收款状态
背书状态

model.py 文件, ‘dynamic_state’选项为动态显示的内容

1
2
3
4
5
6
7
8
9
10
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属性中的值

1
2
3
<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进行重写。

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

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};

});

}

},

});

}

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