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
|
odoo.define('event.configurator.tests', function (require) {
"use strict";
var FormView = require('web.FormView');
var testUtils = require('web.test_utils');
var createView = testUtils.createView;
var getArch = function (){
return '<form>' +
'<sheet>' +
'<field name="sale_order_line" widget="section_and_note_one2many">' +
'<tree editable="top"><control>' +
'<create string="Add a product"/>' +
'<create string="Add a section" context="{\'default_display_type\': \'line_section\'}"/>' +
'<create string="Add a note" context="{\'default_display_type\': \'line_note\'}"/>' +
'</control>' +
'<field name="product_id" widget="product_configurator" />' +
'</tree>' +
'</field>' +
'</sheet>' +
'</form>';
};
QUnit.module('Event Configurator', {
beforeEach: function () {
this.data = {
'product.product': {
fields: {
id: {type: 'integer'},
event_ok: {type: 'boolean'},
rent_ok: {type: 'boolean'}//sale_rental purposes
},
records: [{
id: 1,
display_name: "Customizable Event",
event_ok: true,
rent_ok: false//sale_rental purposes
}, {
id: 2,
display_name: "Desk",
event_ok: false,
rent_ok: false//sale_rental purposes
}]
},
sale_order: {
fields: {
id: {type: 'integer'},
sale_order_line: {
string: 'lines',
type: 'one2many',
relation: 'sale_order_line'
},
}
},
sale_order_line: {
fields: {
product_id: {
string: 'product',
type: 'many2one',
relation: 'product.product'
},
event_ok: {type: 'boolean'},
rent_ok: {type: 'boolean'},//sale_rental purposes
event_id: {
string: 'event',
type: 'many2one',
relation: 'event'
},
event_ticket_id: {
string: 'event_ticket',
type: 'many2one',
relation: 'event_ticket'
}
}
}
};
}
}, function (){
QUnit.test('Select a regular product and verify that the event configurator is not opened', async function (assert) {
assert.expect(1);
var form = await createView({
View: FormView,
model: 'sale_order',
data: this.data,
arch: getArch(),
mockRPC: function (route, params) {
if (params.method === 'read' && params.args[1][0] === 'event_ok') {
assert.ok(true);
return Promise.resolve([{event_ok: false}]);
}
return this._super.apply(this, arguments);
},
intercepts: {
do_action: function (ev) {
if (ev.data.action === 'event_sale.event_configurator_action') {
assert.ok(false, "Should not execute the configure action");
}
},
}
});
await testUtils.dom.click(form.$("a:contains('Add a product')"));
await testUtils.fields.many2one.searchAndClickItem("product_id", {item: 'Desk'})
form.destroy();
});
QUnit.test('Select a configurable event and verify that the event configurator is opened', async function (assert) {
assert.expect(2);
var form = await createView({
View: FormView,
model: 'sale_order',
data: this.data,
arch: getArch(),
mockRPC: function (route, params) {
if (params.method === 'read' && params.args[1][0] === 'event_ok') {
assert.ok(true);
return Promise.resolve([{event_ok: true}]);
}
return this._super.apply(this, arguments);
},
intercepts: {
do_action: function (ev) {
if (ev.data.action === 'event_sale.event_configurator_action') {
assert.ok(true);
}
},
}
});
await testUtils.dom.click(form.$("a:contains('Add a product')"));
await testUtils.fields.many2one.searchAndClickItem("product_id", {item: 'Customizable Event'});
form.destroy();
});
});
});
|