summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/views/basic_model_tests.js
diff options
context:
space:
mode:
authorAurélien Warnon <awa@odoo.com>2019-03-06 07:24:28 +0000
committerAurélien Warnon <awa@odoo.com>2019-03-28 14:55:00 +0000
commit220f5ae53f66400320b697c778039b0585da8fc4 (patch)
treec043173861eeb83ee54688a20ef983bd3c39744c /addons/web/static/tests/views/basic_model_tests.js
parent55ed70f405a7614756f878599ddc7e7d34f6b508 (diff)
[IMP] sale_product_configurator: improve p. configurator
Task #1891970 Original p. configurator commit d3530eb Purpose ======= - The p. configurator now comes with a widget that is "o2m" like in the SO lines view. The widget is only used on the added "product_template_id" field on the SO line. This widget controls the opening of the configuration window and removes the need of a "Configure a product" button. The "SectionAndNoteListRenderer" is now cleaned from p. configurator specific code. The widget is also responsible for handling the configuration provided by the p. configurator form and applying it on the SO line with a 'field_changed' event that updates all the necessary fields. - Added support for 'MULTI' and 'DELETE_ALL' operations on X2Many fields in basic_model.js - 'MULTI' allows to batch multiple operations at once - 'DELETE_ALL' behaves like 'DELETE' with all the current data of the field Spec ======= - remove "configure a product" from sale order lines When the product configurator is active, replace the product_product_id by a product_template_id in the sale order line. When we select a template without variants, it sets the variant automatically, but when we select a product template having variants, it opens the configurator dialog. - add a widget to modify the product configuration in the sale order line (next to product template field) - UX improvements: - Invert image and configuration in the main screen - If the product doesn't have an image, hide it instead of showing the placeholder (only for first screen?) - new independent option in sales settings to activate product configurator. (same in e-commerce) - demo data: Change demo data to set Customizable Desk & Conference Chair as make to order - If only one attribute value that is Custom, don't display radio, selection or even color box
Diffstat (limited to 'addons/web/static/tests/views/basic_model_tests.js')
-rw-r--r--addons/web/static/tests/views/basic_model_tests.js161
1 files changed, 161 insertions, 0 deletions
diff --git a/addons/web/static/tests/views/basic_model_tests.js b/addons/web/static/tests/views/basic_model_tests.js
index 33f07493ef9..2a9fbec6bd4 100644
--- a/addons/web/static/tests/views/basic_model_tests.js
+++ b/addons/web/static/tests/views/basic_model_tests.js
@@ -2155,5 +2155,166 @@ odoo.define('web.basic_model_tests', function (require) {
assert.strictEqual(record.data.foobool2, true, "foobool2 field should be true");
model.destroy();
});
+
+ QUnit.test('notifyChange DELETE_ALL on a one2many', async function (assert) {
+ assert.expect(5);
+
+ this.data.partner.records[1].product_ids = [37, 38];
+ this.params.fieldNames = ['product_ids'];
+
+ var model = createModel({
+ Model: BasicModel,
+ data: this.data,
+ });
+
+ var o2mParams = {
+ modelName: 'product',
+ fields: this.data.product.fields,
+ };
+
+ var resultID = await model.load(this.params);
+ var newRecordID = await model.load(o2mParams);
+ var record = model.get(resultID);
+ var x2mListID = record.data.product_ids.id;
+
+ assert.strictEqual(record.data.product_ids.count, 2,
+ "there should be two records in the relation");
+
+ await model.notifyChanges(resultID, {product_ids: {operation: 'ADD', id: newRecordID}});
+
+ assert.deepEqual(model.localData[x2mListID]._changes, [{
+ operation: 'ADD', id: newRecordID,
+ }], "_changes should be correct");
+
+ record = model.get(resultID);
+ assert.strictEqual(record.data.product_ids.count, 3,
+ "there should be three records in the relation");
+
+ await model.notifyChanges(resultID, {product_ids: {operation: 'DELETE_ALL'}});
+
+ assert.deepEqual(model.localData[x2mListID]._changes, [{
+ id: 37,
+ operation: "DELETE"
+ }, {
+ id: 38,
+ operation: "DELETE"
+ }], "_changes should contain the two 'DELETE' operations");
+
+ record = model.get(resultID);
+ assert.strictEqual(record.data.product_ids.count, 0,
+ "there should be no more records in the relation");
+ model.destroy();
+ });
+
+ QUnit.test('notifyChange MULTI on a one2many', async function (assert) {
+ assert.expect(4);
+
+ this.data.partner.records[1].product_ids = [37, 38];
+ this.params.fieldNames = ['product_ids'];
+
+ var model = createModel({
+ Model: BasicModel,
+ data: this.data,
+ });
+
+ var o2mParams = {
+ modelName: 'product',
+ fields: this.data.product.fields,
+ };
+
+ var resultID = await model.load(this.params);
+ var newRecordID = await model.load(o2mParams);
+ var record = model.get(resultID);
+ var x2mListID = record.data.product_ids.id;
+
+ assert.strictEqual(record.data.product_ids.count, 2,
+ "there should be two records in the relation");
+
+ await model.notifyChanges(resultID, {product_ids: {
+ operation: 'MULTI',
+ commands: [{
+ operation: 'DELETE_ALL'
+ }, {
+ operation: 'ADD',
+ id: newRecordID
+ }]
+ }});
+
+ assert.deepEqual(model.localData[x2mListID]._changes, [{
+ id: 37,
+ operation: "DELETE"
+ }, {
+ id: 38,
+ operation: "DELETE"
+ }, {
+ operation: 'ADD', id: newRecordID,
+ }], "_changes should be correct");
+
+ record = model.get(resultID);
+ assert.strictEqual(record.data.product_ids.count, 1,
+ "there should be one record in the relation");
+
+ assert.strictEqual(record.data.product_ids.data[0].id, newRecordID,
+ "the id should match");
+ });
+
+ QUnit.test('notifyChange MULTI on a many2many', async function (assert) {
+ assert.expect(3);
+
+ this.params.fieldsInfo = {
+ default: {
+ category: {
+ fieldsInfo: {default: {some_char: { context: "{'a': parent.foo}"}}},
+ relatedFields: {some_char: {type: "char"}},
+ viewType: 'default',
+ },
+ foo: {},
+ },
+ };
+
+ var model = createModel({
+ Model: BasicModel,
+ data: this.data,
+ });
+
+ var resultID = await model.load(this.params);
+ var changes = {
+ category: {
+ operation: 'MULTI',
+ commands: [{
+ operation: 'ADD_M2M',
+ ids: [{id: 23}, {id: 24}, {id: 25}]
+ }, {
+ operation: 'ADD_M2M',
+ ids: [{id: 26}]
+ }]
+ }
+ };
+ await model.notifyChanges(resultID, changes);
+ var record = model.get(resultID);
+ var categoryRecord = record.data.category;
+
+ assert.strictEqual(categoryRecord.data.length, 4,
+ "there should 2 records in the relation");
+
+ await model.notifyChanges(resultID, {category: {
+ operation: 'MULTI',
+ commands: [{
+ operation: 'DELETE_ALL'
+ }, {
+ operation: 'ADD_M2M',
+ ids: [{id: 27}]
+ }]
+ }});
+ record = model.get(resultID);
+ categoryRecord = record.data.category;
+ assert.strictEqual(categoryRecord.data.length, 1,
+ "there should 1 record in the relation");
+
+ assert.strictEqual(record.data.category.data[0].data.id, 27,
+ "the id should match");
+
+ model.destroy();
+ });
});
});