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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
odoo.define('hr_holidays.leave_stats_widget_tests', function (require) {
"use strict";
var FormView = require("web.FormView");
var testUtils = require('web.test_utils');
var createView = testUtils.createView;
QUnit.module('leave_stats_widget', {
beforeEach: function () {
this.data = {
department: {
fields: {
name: { string: "Name", type: "char" },
},
records: [{id:11, name: "R&D"}],
},
employee: {
fields: {
name: { string: "Name", type: "char" },
department_id: { string: "Department", type: "many2one", relation: 'department' },
},
records: [{
id: 100,
name: "Richard",
department_id: 11,
},{
id: 200,
name: "Jesus",
department_id: 11,
}],
},
'hr.leave.type': {
fields: {
name: { string: "Name", type: "char" }
},
records: [{
id: 55,
name: "Legal Leave",
}]
},
'hr.leave': {
fields: {
employee_id: { string: "Employee", type: "many2one", relation: 'employee' },
department_id: { string: "Department", type: "many2one", relation: 'department' },
date_from: { string: "From", type: "datetime" },
date_to: { string: "To", type: "datetime" },
holiday_status_id: { string: "Leave type", type: "many2one", relation: 'hr.leave.type' },
state: { string: "State", type: "char" },
holiday_type: { string: "Holiday Type", type: "char" },
number_of_days: { string: "State", type: "integer" },
},
records: [{
id: 12,
employee_id: 100,
department_id: 11,
date_from: "2016-10-20 09:00:00",
date_to: "2016-10-25 18:00:00",
holiday_status_id: 55,
state: 'validate',
number_of_days: 5,
holiday_type: 'employee',
},{
id: 13,
employee_id: 100,
department_id: 11,
date_from: "2016-10-2 09:00:00",
date_to: "2016-10-2 18:00:00",
holiday_status_id: 55,
state: 'validate',
number_of_days: 1,
holiday_type: 'employee',
},{
id: 14,
employee_id: 200,
department_id: 11,
date_from: "2016-10-15 09:00:00",
date_to: "2016-10-20 18:00:00",
holiday_status_id: 55,
state: 'validate',
number_of_days: 8,
holiday_type: 'employee',
}]
}
};
}
}, function () {
QUnit.test('leave stats renders correctly', async function (assert) {
assert.expect(5);
var self = this;
var form = await createView({
View: FormView,
model: 'hr.leave',
data: this.data,
arch: '<form string="Leave">' +
'<field name="employee_id"/>' +
'<field name="department_id"/>' +
'<field name="date_from"/>' +
'<widget name="hr_leave_stats"/>' +
'</form>',
res_id: 12,
mockRPC: function (route, args) {
if (args.model === 'hr.leave' && args.method === 'search') {
return Promise.resolve(self.data['hr.leave'].records.map(function (record) { return record.id; }));
}
return this._super.apply(this, arguments);
},
});
var $leaveTypeBody = form.$('.o_leave_stats table:first > tbody');
var $leavesDepartmentBody = form.$('.o_leave_stats table:nth-child(2) > tbody');
var $leavesDepartmentHeader = form.$('.o_leave_stats table:nth-child(2) > thead');
assert.strictEqual($leaveTypeBody.find('td:contains(Legal Leave)').length, 1, "it should have leave type");
assert.strictEqual($leaveTypeBody.find('td:contains(6)').length, 1, "it should have 6 days");
assert.strictEqual($leavesDepartmentBody.find('td:contains(Richard)').length, 2, "it should have 2 leaves for Richard");
assert.strictEqual($leavesDepartmentBody.find('td:contains(Jesus)').length, 1, "it should have 1 leaves for Jesus");
assert.strictEqual($leavesDepartmentHeader.find('td:contains(R&D)').length, 1, "it should have R&D title");
form.destroy();
});
QUnit.test('leave stats reload when employee/department changes', async function (assert) {
assert.expect(2);
var form = await createView({
View: FormView,
model: 'hr.leave',
mode: 'edit',
data: this.data,
arch: '<form string="Leave">' +
'<field name="employee_id"/>' +
'<field name="department_id"/>' +
'<field name="date_from"/>' +
'<widget name="hr_leave_stats"/>' +
'</form>',
mockRPC: function (route, args) {
if (args.model === 'hr.leave' && args.method === 'search_read') {
assert.ok(_.some(args.args[0], ['department_id', '=', 11]), "It should load department's leaves data");
}
if (args.model === 'hr.leave' && args.method === 'read_group') {
assert.ok(_.some(args.kwargs.domain, ['employee_id', '=', 200]), "It should load employee's leaves data");
}
return this._super.apply(this, arguments);
},
});
// Set date => shouldn't load data yet (no employee nor department defined)
await testUtils.fields.editSelect($('input[name="date_from"]'), '2016-10-12 09:00:00');
// Set employee => should load employee's date
await testUtils.fields.many2one.clickOpenDropdown("employee_id");
await testUtils.fields.many2one.clickItem("employee_id", "Jesus");
// Set department => should load department's data
await testUtils.fields.many2one.clickOpenDropdown("department_id");
await testUtils.fields.many2one.clickItem("department_id", "R&D");
form.destroy();
});
});
});
|