diff options
| author | Aaron Bohy <aab@odoo.com> | 2021-01-14 09:53:26 +0000 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2021-01-14 14:22:24 +0000 |
| commit | 69cadbe1be6320d96fe9bc5bf8dd808f87d735c0 (patch) | |
| tree | 323a47589b17f1fca0efe12646ef5c90fb9cd14d /addons/web/static/tests | |
| parent | 8dfee8cb2d60942641b73eaa6489b02aa378c5ac (diff) | |
[FIX] web, purchase_product_matrix: can open twice the matrix
Let's assume the following scenario with 'purchase_product_matrix'
module installed:
- create a new Purchase Order
- add a line in the one2many
- select "Customizable desk" as product
- [the desk matrix opens]
- close the matrix
- select "Conference chair" instead
- [the desk matrix opens, whereas it should be the chair one]
It didn't work because of a small bug in the FieldOne2Many. This
field is configured to be reset when any other field in the view
changes. The product configurator feature relies on that. However,
when another field changes, the One2Many didn't update its internal
state with the new record (and it skipped the rendering, which is
fine). The matrix product configurator thus read an obsolete value
in the internal of the one2many.
Since the internal state is now always up-to-date, we can directly
read there the grid information, instead of looking inside other
fields that have been updated (attempt done in [1])
It would be nice to rethink the whole product configurator stuff
in master, to make it more robust, maybe when converting it to owl?
[1] https://github.com/odoo/odoo/commit/21bcafc053be7f80eed7a684fee2dc1e3caaafa5
opw~2421798
closes odoo/odoo#64552
Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
Diffstat (limited to 'addons/web/static/tests')
| -rw-r--r-- | addons/web/static/tests/fields/relational_fields/field_one2many_tests.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js b/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js index f8ff8cba1eb..bb64e3f0775 100644 --- a/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js +++ b/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js @@ -16,6 +16,7 @@ var fieldUtils = require('web.field_utils'); const cpHelpers = testUtils.controlPanel; var createView = testUtils.createView; +const { FieldOne2Many } = relationalFields; QUnit.module('fields', {}, function () { @@ -9513,6 +9514,43 @@ QUnit.module('fields', {}, function () { assert.verifySteps(["willUnmount"]); }); + + QUnit.test('one2many: internal state is updated after another field changes', async function (assert) { + // The FieldOne2Many is configured such that it is reset at any field change. + // The MatrixProductConfigurator feature relies on that, and requires that its + // internal state is correctly updated. This white-box test artificially checks that. + assert.expect(2); + + let o2m; + testUtils.patch(FieldOne2Many, { + init() { + this._super(...arguments); + o2m = this; + }, + }); + + const form = await createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: ` + <form> + <field name="display_name"/> + <field name="p"> + <tree><field name="display_name"/></tree> + </field> + </form>`, + }); + + assert.strictEqual(o2m.recordData.display_name, false); + + await testUtils.fields.editInput(form.$('.o_field_widget[name=display_name]'), 'val'); + + assert.strictEqual(o2m.recordData.display_name, "val"); + + form.destroy(); + testUtils.unpatch(FieldOne2Many); + }); }); }); }); |
