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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
|
odoo.define('crm.form_rainbowman_tests', function (require) {
"use strict";
var CrmFormView = require('crm.crm_form').CrmFormView;
var CrmKanbanView = require('crm.crm_kanban').CrmKanbanView;
var testUtils = require('web.test_utils');
var createView = testUtils.createView;
QUnit.module('Crm Rainbowman Triggers', {
beforeEach: function () {
const format = "YYYY-MM-DD HH:mm:ss";
this.data = {
'res.users': {
fields: {
display_name: { string: 'Name', type: 'char' },
},
records: [
{ id: 1, name: 'Mario' },
{ id: 2, name: 'Luigi' },
{ id: 3, name: 'Link' },
{ id: 4, name: 'Zelda' },
],
},
'crm.team': {
fields: {
display_name: { string: 'Name', type: 'char' },
member_ids: { string: 'Members', type: 'many2many', relation: 'res.users' },
},
records: [
{ id: 1, name: 'Mushroom Kingdom', member_ids: [1, 2] },
{ id: 2, name: 'Hyrule', member_ids: [3, 4] },
],
},
'crm.stage': {
fields: {
display_name: { string: 'Name', type: 'char' },
is_won: { string: 'Is won', type: 'boolean' },
},
records: [
{ id: 1, name: 'Start' },
{ id: 2, name: 'Middle' },
{ id: 3, name: 'Won', is_won: true},
],
},
'crm.lead': {
fields: {
display_name: { string: 'Name', type: 'char' },
planned_revenue: { string: 'Revenue', type: 'float' },
stage_id: { string: 'Stage', type: 'many2one', relation: 'crm.stage' },
team_id: { string: 'Sales Team', type: 'many2one', relation: 'crm.team' },
user_id: { string: 'Salesperson', type: 'many2one', relation: 'res.users' },
date_closed: { string: 'Date closed', type: 'datetime' },
},
records : [
{ id: 1, name: 'Lead 1', planned_revenue: 5.0, stage_id: 1, team_id: 1, user_id: 1 },
{ id: 2, name: 'Lead 2', planned_revenue: 5.0, stage_id: 2, team_id: 2, user_id: 4 },
{ id: 3, name: 'Lead 3', planned_revenue: 3.0, stage_id: 3, team_id: 1, user_id: 1, date_closed: moment().subtract(5, 'days').format(format) },
{ id: 4, name: 'Lead 4', planned_revenue: 4.0, stage_id: 3, team_id: 2, user_id: 4, date_closed: moment().subtract(23, 'days').format(format) },
{ id: 5, name: 'Lead 5', planned_revenue: 7.0, stage_id: 3, team_id: 1, user_id: 1, date_closed: moment().subtract(20, 'days').format(format) },
{ id: 6, name: 'Lead 6', planned_revenue: 4.0, stage_id: 2, team_id: 1, user_id: 2 },
{ id: 7, name: 'Lead 7', planned_revenue: 1.8, stage_id: 3, team_id: 2, user_id: 3, date_closed: moment().subtract(23, 'days').format(format) },
{ id: 8, name: 'Lead 8', planned_revenue: 1.9, stage_id: 1, team_id: 2, user_id: 3 },
{ id: 9, name: 'Lead 9', planned_revenue: 1.5, stage_id: 3, team_id: 2, user_id: 3, date_closed: moment().subtract(5, 'days').format(format) },
{ id: 10, name: 'Lead 10', planned_revenue: 1.7, stage_id: 2, team_id: 2, user_id: 3 },
{ id: 11, name: 'Lead 11', planned_revenue: 2.0, stage_id: 3, team_id: 2, user_id: 4, date_closed: moment().subtract(5, 'days').format(format) },
],
},
};
this.testFormView = {
arch: `
<form js_class="crm_form">
<header><field name="stage_id" widget="statusbar" options="{'clickable': '1'}"/></header>
<field name="name"/>
<field name="planned_revenue"/>
<field name="team_id"/>
<field name="user_id"/>
</form>`,
data: this.data,
model: 'crm.lead',
View: CrmFormView,
};
this.testKanbanView = {
arch: `
<kanban js_class="crm_kanban">
<templates>
<t t-name="kanban-box">
<div><field name="name"/></div>
</t>
</templates>
</kanban>`,
data: this.data,
model: 'crm.lead',
View: CrmKanbanView,
groupBy: ['stage_id'],
};
},
}, function () {
QUnit.test("first lead won, click on statusbar", async function (assert) {
assert.expect(2);
this.testFormView.res_id = 6;
this.testFormView.mockRPC = async function (route, args) {
const result = await this._super(...arguments);
if (args.model === 'crm.lead' && args.method === 'get_rainbowman_message') {
assert.step(result || "no rainbowman");
}
return result;
};
const form = await createView(this.testFormView);
await testUtils.dom.click(form.$(".o_statusbar_status button[data-value='3']"));
assert.verifySteps(['Go, go, go! Congrats for your first deal.']);
form.destroy();
});
QUnit.test("first lead won, click on statusbar in edit mode then save", async function (assert) {
assert.expect(3);
const form = await createView(_.extend(this.testFormView, {
res_id: 6,
mockRPC: async function (route, args) {
const result = await this._super(...arguments);
if (args.model === 'crm.lead' && args.method === 'get_rainbowman_message') {
assert.step(result || "no rainbowman");
}
return result;
},
viewOptions: {mode: 'edit'}
}));
await testUtils.dom.click(form.$(".o_statusbar_status button[data-value='3']"));
assert.verifySteps([]); // no message displayed yet
await testUtils.form.clickSave(form);
assert.verifySteps(['Go, go, go! Congrats for your first deal.']);
form.destroy();
});
QUnit.test("team record 30 days, click on statusbar", async function (assert) {
assert.expect(2);
this.testFormView.res_id = 2;
this.testFormView.mockRPC = async function (route, args) {
const result = await this._super(...arguments);
if (args.model === 'crm.lead' && args.method === 'get_rainbowman_message') {
assert.step(result || "no rainbowman");
}
return result;
};
const form = await createView(this.testFormView);
await testUtils.dom.click(form.$(".o_statusbar_status button[data-value='3']"));
assert.verifySteps(['Boom! Team record for the past 30 days.']);
form.destroy();
});
QUnit.test("team record 7 days, click on statusbar", async function (assert) {
assert.expect(2);
this.testFormView.res_id = 1;
this.testFormView.mockRPC = async function (route, args) {
const result = await this._super(...arguments);
if (args.model === 'crm.lead' && args.method === 'get_rainbowman_message') {
assert.step(result || "no rainbowman");
}
return result;
};
const form = await createView(this.testFormView);
await testUtils.dom.click(form.$(".o_statusbar_status button[data-value='3']"));
assert.verifySteps(['Yeah! Deal of the last 7 days for the team.']);
form.destroy();
});
QUnit.test("user record 30 days, click on statusbar", async function (assert) {
assert.expect(2);
this.testFormView.res_id = 8;
this.testFormView.mockRPC = async function (route, args) {
const result = await this._super(...arguments);
if (args.model === 'crm.lead' && args.method === 'get_rainbowman_message') {
assert.step(result || "no rainbowman");
}
return result;
};
const form = await createView(this.testFormView);
await testUtils.dom.click(form.$(".o_statusbar_status button[data-value='3']"));
assert.verifySteps(['You just beat your personal record for the past 30 days.']);
form.destroy();
});
QUnit.test("user record 7 days, click on statusbar", async function (assert) {
assert.expect(2);
this.testFormView.res_id = 10;
this.testFormView.mockRPC = async function (route, args) {
const result = await this._super(...arguments);
if (args.model === 'crm.lead' && args.method === 'get_rainbowman_message') {
assert.step(result || "no rainbowman");
}
return result;
};
const form = await createView(this.testFormView);
await testUtils.dom.click(form.$(".o_statusbar_status button[data-value='3']"));
assert.verifySteps(['You just beat your personal record for the past 7 days.']);
form.destroy();
});
QUnit.test("click on stage (not won) on statusbar", async function (assert) {
assert.expect(2);
this.testFormView.res_id = 1;
this.testFormView.mockRPC = async function (route, args) {
const result = await this._super(...arguments);
if (args.model === 'crm.lead' && args.method === 'get_rainbowman_message') {
assert.step(result || "no rainbowman");
}
return result;
};
const form = await createView(this.testFormView);
await testUtils.dom.click(form.$(".o_statusbar_status button[data-value='2']"));
assert.verifySteps(['no rainbowman']);
form.destroy();
});
QUnit.test("first lead won, drag & drop kanban", async function (assert) {
assert.expect(2);
this.testKanbanView.mockRPC = async function (route, args) {
const result = await this._super(...arguments);
if (args.model === 'crm.lead' && args.method === 'get_rainbowman_message') {
assert.step(result || "no rainbowman");
}
return result;
};
const kanban = await createView(this.testKanbanView);
kanban.model.defaultGroupedBy = ['stage_id'];
await kanban.reload();
await testUtils.dom.dragAndDrop(kanban.$('.o_kanban_record:contains("Lead 6")'), kanban.$('.o_kanban_group:eq(2)'));
assert.verifySteps(['Go, go, go! Congrats for your first deal.']);
kanban.destroy();
});
QUnit.test("team record 30 days, drag & drop kanban", async function (assert) {
assert.expect(2);
this.testKanbanView.mockRPC = async function (route, args) {
const result = await this._super(...arguments);
if (args.model === 'crm.lead' && args.method === 'get_rainbowman_message') {
assert.step(result || "no rainbowman");
}
return result;
};
const kanban = await createView(this.testKanbanView);
kanban.model.defaultGroupedBy = ['stage_id'];
await kanban.reload();
await testUtils.dom.dragAndDrop(kanban.$('.o_kanban_record:contains("Lead 2")'), kanban.$('.o_kanban_group:eq(2)'));
assert.verifySteps(['Boom! Team record for the past 30 days.']);
kanban.destroy();
});
QUnit.test("team record 7 days, drag & drop kanban", async function (assert) {
assert.expect(2);
this.testKanbanView.mockRPC = async function (route, args) {
const result = await this._super(...arguments);
if (args.model === 'crm.lead' && args.method === 'get_rainbowman_message') {
assert.step(result || "no rainbowman");
}
return result;
};
const kanban = await createView(this.testKanbanView);
kanban.model.defaultGroupedBy = ['stage_id'];
await kanban.reload();
await testUtils.dom.dragAndDrop(kanban.$('.o_kanban_group:eq(0) .o_kanban_record:contains("Lead 1")'), kanban.$('.o_kanban_group:eq(2)'));
assert.verifySteps(['Yeah! Deal of the last 7 days for the team.']);
kanban.destroy();
});
QUnit.test("user record 30 days, drag & drop kanban", async function (assert) {
assert.expect(2);
this.testKanbanView.mockRPC = async function (route, args) {
const result = await this._super(...arguments);
if (args.model === 'crm.lead' && args.method === 'get_rainbowman_message') {
assert.step(result || "no rainbowman");
}
return result;
};
const kanban = await createView(this.testKanbanView);
kanban.model.defaultGroupedBy = ['stage_id'];
await kanban.reload();
await testUtils.dom.dragAndDrop(kanban.$('.o_kanban_record:contains("Lead 8")'), kanban.$('.o_kanban_group:eq(2)'));
assert.verifySteps(['You just beat your personal record for the past 30 days.']);
kanban.destroy();
});
QUnit.test("user record 7 days, drag & drop kanban", async function (assert) {
assert.expect(2);
this.testKanbanView.mockRPC = async function (route, args) {
const result = await this._super(...arguments);
if (args.model === 'crm.lead' && args.method === 'get_rainbowman_message') {
assert.step(result || "no rainbowman");
}
return result;
};
const kanban = await createView(this.testKanbanView);
kanban.model.defaultGroupedBy = ['stage_id'];
await kanban.reload();
await testUtils.dom.dragAndDrop(kanban.$('.o_kanban_record:contains("Lead 10")'), kanban.$('.o_kanban_group:eq(2)'));
assert.verifySteps(['You just beat your personal record for the past 7 days.']);
kanban.destroy();
});
QUnit.test("drag & drop record kanban in stage not won", async function (assert) {
assert.expect(2);
this.testKanbanView.mockRPC = async function (route, args) {
const result = await this._super(...arguments);
if (args.model === 'crm.lead' && args.method === 'get_rainbowman_message') {
assert.step(result || "no rainbowman");
}
return result;
};
const kanban = await createView(this.testKanbanView);
kanban.model.defaultGroupedBy = ['stage_id'];
await kanban.reload();
await testUtils.dom.dragAndDrop(kanban.$('.o_kanban_record:contains("Lead 8")'), kanban.$('.o_kanban_group:eq(1)'));
assert.verifySteps(["no rainbowman"]);
kanban.destroy();
});
QUnit.test("drag & drop record in kanban not grouped by stage_id", async function (assert) {
assert.expect(1);
this.testKanbanView.mockRPC = async function (route, args) {
const result = await this._super(...arguments);
if (args.model === 'crm.lead' && args.method === 'get_rainbowman_message') {
assert.step(result || "no rainbowman");
}
return result;
};
this.testKanbanView.groupBy = ['user_id'];
const kanban = await createView(this.testKanbanView);
kanban.model.defaultGroupedBy = ['stage_id'];
await kanban.reload();
await testUtils.dom.dragAndDrop(kanban.$('.o_kanban_group:eq(0) .o_kanban_record:first'), kanban.$('.o_kanban_group:eq(1)'));
assert.verifySteps([]); // Should never pass by the rpc
kanban.destroy();
});
});
});
|