[FIX] web_editor: make monetary field unremovable

Before this commit, the span within monetary field could wrongly be
removed. Python code that parse the value (see `from_html` of
`ir.qweb.field.monetary`) expect to have that span available.

This commit make that span being unremovable.

opw-3090775

closes odoo/odoo#108496

X-original-commit: 7576c88fec4f993e525279d15c22077a11132281
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
This commit is contained in:
Nicolas Bayet
2022-12-22 10:39:31 +01:00
parent 97ec1f4ab3
commit cb3dc19969
3 changed files with 23 additions and 0 deletions
@@ -1344,6 +1344,7 @@ export function isUnremovable(node) {
(node.nodeType === Node.ELEMENT_NODE &&
(node.classList.contains('o_editable') || node.getAttribute('t-set') || node.getAttribute('t-call'))) ||
(node.classList && node.classList.contains('oe_unremovable')) ||
(node.nodeName === 'SPAN' && node.parentElement && node.parentElement.getAttribute('data-oe-type') === 'monetary') ||
(node.ownerDocument && node.ownerDocument.defaultWindow && !ancestors(node).find(ancestor => ancestor.oid === 'root')) // Node is in DOM but not in editable.
);
}
@@ -12,6 +12,7 @@ import './spec/tabs.test.js';
import './spec/autostep.test.js';
import './spec/urlRegex.test.js';
import './spec/collab.test.js';
import './spec/odooFields.test.js';
import './spec/powerbox.test.js';
/* global mocha */
@@ -0,0 +1,21 @@
import { BasicEditor, testEditor, unformat } from '../utils.js';
describe('Odoo fields', () => {
describe('monetary field', () => {
it('should make a span inside a monetary field be unremovable', async () => {
const content = unformat(`
<p>
<span data-oe-model="product.template" data-oe-id="27" data-oe-field="list_price" data-oe-type="monetary" data-oe-expression="product.list_price" data-oe-xpath="/t[1]/div[1]/h3[2]/span[1]" class="o_editable">
$&nbsp;
<span class="oe_currency_value">[]</span>
</span>
</p>
`);
await testEditor(BasicEditor, {
contentBefore: content,
stepFunction: (editor) => editor.execCommand('oDeleteBackward'),
contentAfter: content,
});
});
});
});