[FIX] sms: fix sms_button in form views

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 <mcm@odoo.com>
Signed-off-by: Luca Vitali <luvi@odoo.com>
This commit is contained in:
luvi
2022-09-30 18:42:32 +02:00
parent 909a510120
commit efad2b1a10
4 changed files with 104 additions and 3 deletions
@@ -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,
};
},
});
@@ -2,8 +2,16 @@
<templates xml:space="preserve">
<t t-inherit="web.PhoneField" t-inherit-mode="extension">
<xpath expr="//*[hasclass('o_phone_link')]" position="after">
<t t-if="props.value.length > 0">
<xpath expr="//div[hasclass('o_phone_content')]//a" position="after">
<t t-if="props.enableButton and props.value.length > 0">
<SendSMSButton t-props="props" />
</t>
</xpath>
</t>
<t t-inherit="web.FormPhoneField" t-inherit-mode="extension">
<xpath expr="//div[hasclass('o_phone_content')]" position="inside">
<t t-if="props.enableButton and props.value.length > 0">
<SendSMSButton t-props="props" />
</t>
</xpath>
@@ -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 */ `
<form>
<sheet>
<field name="mobile" widget="phone"/>
</sheet>
</form>`,
});
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 */ `
<form>
<sheet>
<field name="mobile" widget="phone" options="{'enable_sms': false}"/>
</sheet>
</form>`,
});
assert.containsNone(this.target.querySelector('.o_field_phone'), ".o_field_phone_sms", "the button is not present");
});
});
@@ -23,7 +23,7 @@
<a
t-if="props.value"
t-att-href="'tel:'+props.value"
class="ms-3 d-inline-flex align-items-center"
class="o_phone_form_link ms-3 d-inline-flex align-items-center"
>
<i class="fa fa-phone"></i><small class="fw-bold ms-1">Call</small>
</a>