From efad2b1a105a83651e7f5961bada895ebfb51485 Mon Sep 17 00:00:00 2001 From: luvi Date: Tue, 27 Sep 2022 22:08:53 +0000 Subject: [PATCH] [FIX] sms: fix sms_button in form views MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit brings back the Send SMS button, which was no longer visible in form views since they are now displayed in edition by default. It also solves the missing enable_sms option, which was not yet ported from the legacy implementation. A test file has been added to the sms module to verify the presence of the button in the view. closes odoo/odoo#101786 X-original-commit: fdb38657904202d9bfa75817289a53596b914406 Related: odoo/enterprise#32108 Signed-off-by: Michaƫl Mattiello Signed-off-by: Luca Vitali --- .../src/components/phone_field/phone_field.js | 14 ++++ .../components/phone_field/phone_field.xml | 12 ++- .../components/sms_button_tests.js | 79 +++++++++++++++++++ .../src/views/fields/phone/phone_field.xml | 2 +- 4 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 addons/sms/static/tests/qunit_suite_tests/components/sms_button_tests.js diff --git a/addons/sms/static/src/components/phone_field/phone_field.js b/addons/sms/static/src/components/phone_field/phone_field.js index 677a335b0c9..6441de17581 100644 --- a/addons/sms/static/src/components/phone_field/phone_field.js +++ b/addons/sms/static/src/components/phone_field/phone_field.js @@ -9,4 +9,18 @@ patch(PhoneField, "sms.PhoneField", { ...PhoneField.components, SendSMSButton }, + defaultProps: { + ...PhoneField.defaultProps, + enableButton: true, + }, + props: { + ...PhoneField.props, + enableButton: { type: Boolean, optional: true }, + }, + extractProps: ({ attrs }) => { + return { + enableButton: attrs.options.enable_sms, + placeholder: attrs.placeholder, + }; + }, }); diff --git a/addons/sms/static/src/components/phone_field/phone_field.xml b/addons/sms/static/src/components/phone_field/phone_field.xml index e73c030b467..7a189668636 100644 --- a/addons/sms/static/src/components/phone_field/phone_field.xml +++ b/addons/sms/static/src/components/phone_field/phone_field.xml @@ -2,8 +2,16 @@ - - + + + + + + + + + + diff --git a/addons/sms/static/tests/qunit_suite_tests/components/sms_button_tests.js b/addons/sms/static/tests/qunit_suite_tests/components/sms_button_tests.js new file mode 100644 index 00000000000..cadfc242cd5 --- /dev/null +++ b/addons/sms/static/tests/qunit_suite_tests/components/sms_button_tests.js @@ -0,0 +1,79 @@ +/** @odoo-module **/ + +import { makeView, setupViewRegistries } from "@web/../tests/views/helpers"; +import { getFixture } from "@web/../tests/helpers/utils"; + + +QUnit.module('fields', { + beforeEach: function () { + this.data = { + partner: { + fields: { + message: {string: "message", type: "text"}, + foo: {string: "Foo", type: "char", default: "My little Foo Value"}, + mobile: {string: "mobile", type: "text"}, + }, + records: [{ + id: 1, + message: "", + foo: 'yop', + mobile: "+32494444444", + }, { + id: 2, + message: "", + foo: 'bayou', + }] + }, + visitor: { + fields: { + mobile: {string: "mobile", type: "text"}, + }, + records: [{ + id: 1, + mobile: "+32494444444", + }] + }, + }; + setupViewRegistries(); + this.target = getFixture(); + } +}, function () { + + QUnit.module('SmsButton'); + + QUnit.test('Sms button in form view', async function (assert) { + await makeView({ + type: "form", + resModel: "visitor", + resId: 1, + serverData: { models: this.data }, + arch: /* xml */ ` +
+ + + +
`, + }); + + assert.containsOnce(this.target.querySelector('.o_field_phone'), ".o_field_phone_sms", "the button is present"); + }); + + QUnit.test('Sms button with option enable_sms set as False', async function (assert) { + await makeView({ + type: "form", + resModel: "visitor", + resId: 1, + serverData: { models: this.data }, + mode: "readonly", + arch: /* xml */ ` +
+ + + +
`, + }); + + assert.containsNone(this.target.querySelector('.o_field_phone'), ".o_field_phone_sms", "the button is not present"); + }); + +}); diff --git a/addons/web/static/src/views/fields/phone/phone_field.xml b/addons/web/static/src/views/fields/phone/phone_field.xml index 99337bb2daf..bcd57958694 100644 --- a/addons/web/static/src/views/fields/phone/phone_field.xml +++ b/addons/web/static/src/views/fields/phone/phone_field.xml @@ -23,7 +23,7 @@ Call