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