From a51a5b70d3c78b65d32a9fa576dffa3d8a2af666 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Fri, 7 Sep 2018 08:26:12 +0200 Subject: [PATCH 1/3] [FIX] web: FieldDomain: reset field with a new domain Before this rev., there was a crash when a FieldDomain was reset with a new domain (e.g. coming from an onchange). For instance, it crashed in Email Marketing > create new Mass Mailing > select mailing lists. Introduced by 68332a01. opw-1882850 --- .../static/src/js/widgets/domain_selector.js | 2 +- .../static/tests/fields/basic_fields_tests.js | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/widgets/domain_selector.js b/addons/web/static/src/js/widgets/domain_selector.js index 2b100d923fa..ec295da6109 100644 --- a/addons/web/static/src/js/widgets/domain_selector.js +++ b/addons/web/static/src/js/widgets/domain_selector.js @@ -491,7 +491,7 @@ var DomainSelector = DomainTree.extend({ } var parsedDomain = this._parseDomain(domain); if (parsedDomain) { - return this._redraw(domain); + return this._redraw(parsedDomain); } }, diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index 4dd595cbfa0..fade0282f69 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -4521,6 +4521,43 @@ QUnit.module('basic_fields', { form.destroy(); }); + QUnit.test('domain field can be reset with a new domain (from onchange)', function (assert) { + assert.expect(2); + + this.data.partner.records[0].foo = '[]'; + this.data.partner.onchanges = { + display_name: function (obj) { + obj.foo = '[["id", "=", 1]]'; + }, + }; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: + '
' + + '' + + '' + + '', + res_id: 1, + viewOptions: { + mode: 'edit', + }, + }); + + assert.equal(form.$('.o_domain_show_selection_button').text().trim(), '5 record(s)', + "the domain being empty, there should be 5 records"); + + // update display_name to trigger the onchange and reset foo + form.$('.o_field_widget[name=display_name]').val('new value').trigger('input'); + + assert.equal(form.$('.o_domain_show_selection_button').text().trim(), '1 record(s)', + "the domain has changed, there should be only 1 record"); + + form.destroy(); + }); + QUnit.test('domain field: handle false domain as []', function (assert) { assert.expect(3); From 7e83ea8d579d8eb4c89f85b8f954c637284c6b11 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Thu, 6 Sep 2018 14:24:49 +0200 Subject: [PATCH 2/3] [FIX] point_of_sale: restrict price control - Activate the Price Control option in the POS - Connect as Admin => you are allowed to modify the price - Switch the user to Demo => you are still allowed to modify the price - Switch back to Admin => you are not allowed to modify the prices The two last steps are clearly incorrect. The reason is the following. The function `applyAccessRights` is bound to `'change:cashier'` event of the `pos` at: https://github.com/odoo/odoo/blob/d25719cdf2b8a863c1a855f2e42e9c3a43580f66/addons/point_of_sale/static/src/js/screens.js#L389 When switching the user, 2 steps are performed: 1. Set the cashier on the `pos` 2. Set the cashier on the `pos.db` https://github.com/odoo/odoo/blob/d25719cdf2b8a863c1a855f2e42e9c3a43580f66/addons/point_of_sale/static/src/js/models.js#L646-L647 Step 1 will trigger the function `applyAccessRights`, which calls `pos.get_cashier`. However, the latter retrieves the user on `pos.db` first, and falls back on `pos`. https://github.com/odoo/odoo/blob/d25719cdf2b8a863c1a855f2e42e9c3a43580f66/addons/point_of_sale/static/src/js/models.js#L642 This means that we retrieve the cashier in the `pos.db` before it is actually set (in step 2). To avoid this, we explicitly retrieve the cashier on the `pos`, then fall back on the usual `pos.get_cashier` function. Closes #26814 opw-1871189 opw-1881172 --- addons/point_of_sale/static/src/js/screens.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/point_of_sale/static/src/js/screens.js b/addons/point_of_sale/static/src/js/screens.js index bb6e5a1f1cf..a50ccb14c0e 100644 --- a/addons/point_of_sale/static/src/js/screens.js +++ b/addons/point_of_sale/static/src/js/screens.js @@ -394,7 +394,8 @@ var NumpadWidget = PosBaseWidget.extend({ this.$el.find('.mode-button').click(_.bind(this.clickChangeMode, this)); }, applyAccessRights: function() { - var has_price_control_rights = !this.pos.config.restrict_price_control || this.pos.get_cashier().role == 'manager'; + var cashier = this.pos.get('cashier') || this.pos.get_cashier(); + var has_price_control_rights = !this.pos.config.restrict_price_control || cashier.role == 'manager'; this.$el.find('.mode-button[data-mode="price"]') .toggleClass('disabled-mode', !has_price_control_rights) .prop('disabled', !has_price_control_rights); From 9b602ae648e6667a932b8edc11977ab0b8c70e86 Mon Sep 17 00:00:00 2001 From: len-odoo Date: Wed, 5 Sep 2018 16:43:41 +0200 Subject: [PATCH 3/3] [FIX] base: allow to use Python builtins in views Py.js does support Python builtins, e.g. abs, len, str, which can be used in views if the view validation accepts it. opw 1879160 --- odoo/addons/base/ir/ir_ui_view.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/odoo/addons/base/ir/ir_ui_view.py b/odoo/addons/base/ir/ir_ui_view.py index 3529e183ad4..f181b1786b2 100644 --- a/odoo/addons/base/ir/ir_ui_view.py +++ b/odoo/addons/base/ir/ir_ui_view.py @@ -905,6 +905,12 @@ actual arch. 'datetime', 'relativedelta', 'current_date', + 'abs', + 'len', + 'bool', + 'float', + 'str', + 'unicode', } def get_attrs_field_names(self, arch, model, editable):