diff --git a/web_m2x_options/static/src/components/form.esm.js b/web_m2x_options/static/src/components/form.esm.js index 51c3c69acc80..b18ba530eafa 100644 --- a/web_m2x_options/static/src/components/form.esm.js +++ b/web_m2x_options/static/src/components/form.esm.js @@ -325,7 +325,7 @@ patch(FormController.prototype, { * add more method to add subview limit on formview */ async _setSubViewLimit() { - const ir_options = session.web_m2x_options; + const ir_options = session.web_m2x_options || {}; const activeFields = this.archInfo.fieldNodes, isSmall = this.user; diff --git a/web_widget_dropdown_dynamic/README.rst b/web_widget_dropdown_dynamic/README.rst new file mode 100644 index 000000000000..06a3968754d4 --- /dev/null +++ b/web_widget_dropdown_dynamic/README.rst @@ -0,0 +1,141 @@ +======================= +Dynamic Dropdown Widget +======================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:e2b8eb236b4dc206f3a4ab9b5932f86c2e46c33bdac31c385725384f3fe970e3 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github + :target: https://github.com/OCA/web/tree/17.0/web_widget_dropdown_dynamic + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-17-0/web-17-0-web_widget_dropdown_dynamic + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Dynamic dropdown widget that supports resolving options from backend of: + + - ``fields.Char`` + - ``fields.Integer`` + - ``fields.Selection`` + +**NOTE:** This widget is not intended to *extend* ``fields.Selection``, +but to filter selection values. For fully-dynamic set of options, use +``fields.Char`` instead. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +.. code:: python + + @api.model + def method_name(self): + values = [ + ('value_a', 'Title A'), + ] + if self.env.context.get('depending_on') == True: + values += [ + ('value_b', 'Title B'), + ] + return values + +.. code:: xml + + + + +**DEMO** + +On User defined filters added new field to show the feature, it is +called **Dropdown Integer**. If any user selected just One option shoud +appear, but if Mitchell Admin it should be possible to select option One +and Two. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* CorporateHub + +Contributors +------------ + +- `CorporateHub `__ + + - Alexey Pelykh + +- `Therp BV `__ + + - Ronald Portier + +- Thanakrit Pintana + +- `Trobz `__: + + - Son Ho + +- `Tecnativa `__: + + - Carlos Roca + +Other credits +------------- + +The migration of this module from 15.0 to 16.0 was financially supported +by Camptocamp + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/web `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_widget_dropdown_dynamic/__init__.py b/web_widget_dropdown_dynamic/__init__.py new file mode 100644 index 000000000000..c32fd62b78d9 --- /dev/null +++ b/web_widget_dropdown_dynamic/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from . import models diff --git a/web_widget_dropdown_dynamic/__manifest__.py b/web_widget_dropdown_dynamic/__manifest__.py new file mode 100644 index 000000000000..12e1fe6a4a51 --- /dev/null +++ b/web_widget_dropdown_dynamic/__manifest__.py @@ -0,0 +1,26 @@ +# Copyright 2019-2020 Brainbean Apps (https://brainbeanapps.com) +# Copyright 2020 CorporateHub (https://corporatehub.eu) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + "name": "Dynamic Dropdown Widget", + "summary": "This module adds support for dynamic dropdown widget", + "category": "Web", + "version": "17.0.1.0.0", + "license": "AGPL-3", + "author": "CorporateHub, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/web", + "depends": ["web"], + "installable": True, + "assets": { + "web.assets_backend": [ + "web_widget_dropdown_dynamic/static/src/js/field_dynamic_dropdown.esm.js", + ], + "web.qunit_suite_tests": [ + "web_widget_dropdown_dynamic/static/tests/web_widget_dropdown_dynamic_tests.esm.js", + ], + }, + "demo": [ + "demo/ir_model_fields.xml", + "demo/ir_filters_view.xml", + ], +} diff --git a/web_widget_dropdown_dynamic/demo/ir_filters_view.xml b/web_widget_dropdown_dynamic/demo/ir_filters_view.xml new file mode 100644 index 000000000000..adf046ab19cb --- /dev/null +++ b/web_widget_dropdown_dynamic/demo/ir_filters_view.xml @@ -0,0 +1,17 @@ + + + + ir.filters + + + + + + + + diff --git a/web_widget_dropdown_dynamic/demo/ir_model_fields.xml b/web_widget_dropdown_dynamic/demo/ir_model_fields.xml new file mode 100644 index 000000000000..fe5be5d1208d --- /dev/null +++ b/web_widget_dropdown_dynamic/demo/ir_model_fields.xml @@ -0,0 +1,11 @@ + + + + Dropdown Integer + ir.filters + + x_dynamic_dropdown_int + manual + integer + + diff --git a/web_widget_dropdown_dynamic/i18n/de.po b/web_widget_dropdown_dynamic/i18n/de.po new file mode 100644 index 000000000000..61dd9d6002eb --- /dev/null +++ b/web_widget_dropdown_dynamic/i18n/de.po @@ -0,0 +1,24 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_widget_dropdown_dynamic +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-10-13 20:46+0000\n" +"Last-Translator: Corneliuus \n" +"Language-Team: none\n" +"Language: de\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.3.2\n" + +#. module: web_widget_dropdown_dynamic +#. odoo-javascript +#: code:addons/web_widget_dropdown_dynamic/static/src/js/field_dynamic_dropdown.esm.js:0 +#, python-format +msgid "Dynamic Dropdown" +msgstr "Dynamisches Dropdown" diff --git a/web_widget_dropdown_dynamic/i18n/es.po b/web_widget_dropdown_dynamic/i18n/es.po new file mode 100644 index 000000000000..21f65c66a502 --- /dev/null +++ b/web_widget_dropdown_dynamic/i18n/es.po @@ -0,0 +1,24 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_widget_dropdown_dynamic +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-02-17 14:45+0000\n" +"Last-Translator: claudiagn \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.3.2\n" + +#. module: web_widget_dropdown_dynamic +#. odoo-javascript +#: code:addons/web_widget_dropdown_dynamic/static/src/js/field_dynamic_dropdown.esm.js:0 +#, python-format +msgid "Dynamic Dropdown" +msgstr "MenĂº desplegable dinĂ¡mico" diff --git a/web_widget_dropdown_dynamic/i18n/it.po b/web_widget_dropdown_dynamic/i18n/it.po new file mode 100644 index 000000000000..7913b908c3b9 --- /dev/null +++ b/web_widget_dropdown_dynamic/i18n/it.po @@ -0,0 +1,24 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_widget_dropdown_dynamic +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-11-27 11:37+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: web_widget_dropdown_dynamic +#. odoo-javascript +#: code:addons/web_widget_dropdown_dynamic/static/src/js/field_dynamic_dropdown.esm.js:0 +#, python-format +msgid "Dynamic Dropdown" +msgstr "Dropdown dinamico" diff --git a/web_widget_dropdown_dynamic/i18n/web_widget_dropdown_dynamic.pot b/web_widget_dropdown_dynamic/i18n/web_widget_dropdown_dynamic.pot new file mode 100644 index 000000000000..9147b0b4f778 --- /dev/null +++ b/web_widget_dropdown_dynamic/i18n/web_widget_dropdown_dynamic.pot @@ -0,0 +1,21 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_widget_dropdown_dynamic +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: web_widget_dropdown_dynamic +#. odoo-javascript +#: code:addons/web_widget_dropdown_dynamic/static/src/js/field_dynamic_dropdown.esm.js:0 +#, python-format +msgid "Dynamic Dropdown" +msgstr "" diff --git a/web_widget_dropdown_dynamic/models/__init__.py b/web_widget_dropdown_dynamic/models/__init__.py new file mode 100644 index 000000000000..15a5fd375694 --- /dev/null +++ b/web_widget_dropdown_dynamic/models/__init__.py @@ -0,0 +1,4 @@ +from odoo.tools import config + +if not config.get("without_demo"): + from . import ir_filters diff --git a/web_widget_dropdown_dynamic/models/ir_filters.py b/web_widget_dropdown_dynamic/models/ir_filters.py new file mode 100644 index 000000000000..b3f9a78a8283 --- /dev/null +++ b/web_widget_dropdown_dynamic/models/ir_filters.py @@ -0,0 +1,19 @@ +# Copyright 2024 Tecnativa - Carlos Roca +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, models + + +class IrFilters(models.Model): + _inherit = "ir.filters" + + @api.model + def dynamic_dropdown_int_method_demo(self): + values = [ + ("1", "One"), + ] + if self.env.context.get("depending_on") == self.env.ref("base.user_admin").id: + values += [ + ("2", "Two"), + ] + return values diff --git a/web_widget_dropdown_dynamic/pyproject.toml b/web_widget_dropdown_dynamic/pyproject.toml new file mode 100644 index 000000000000..4231d0cccb3d --- /dev/null +++ b/web_widget_dropdown_dynamic/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/web_widget_dropdown_dynamic/readme/CONTRIBUTORS.md b/web_widget_dropdown_dynamic/readme/CONTRIBUTORS.md new file mode 100644 index 000000000000..510d7f721c0c --- /dev/null +++ b/web_widget_dropdown_dynamic/readme/CONTRIBUTORS.md @@ -0,0 +1,16 @@ +- [CorporateHub](https://corporatehub.eu/) + + - Alexey Pelykh \<\> + +- [Therp BV](https://therp.nl/) + + - Ronald Portier \<\> + +- Thanakrit Pintana \<\> + +- [Trobz](https://trobz.com): + + > - Son Ho \<\> + +- [Tecnativa](https://www.tecnativa.com): + - Carlos Roca \ No newline at end of file diff --git a/web_widget_dropdown_dynamic/readme/CREDITS.md b/web_widget_dropdown_dynamic/readme/CREDITS.md new file mode 100644 index 000000000000..291e14c81e2a --- /dev/null +++ b/web_widget_dropdown_dynamic/readme/CREDITS.md @@ -0,0 +1,2 @@ +The migration of this module from 15.0 to 16.0 was financially supported +by Camptocamp diff --git a/web_widget_dropdown_dynamic/readme/DESCRIPTION.md b/web_widget_dropdown_dynamic/readme/DESCRIPTION.md new file mode 100644 index 000000000000..e48e2f57419e --- /dev/null +++ b/web_widget_dropdown_dynamic/readme/DESCRIPTION.md @@ -0,0 +1,9 @@ +Dynamic dropdown widget that supports resolving options from backend of: + +> - `fields.Char` +> - `fields.Integer` +> - `fields.Selection` + +**NOTE:** This widget is not intended to *extend* `fields.Selection`, +but to filter selection values. For fully-dynamic set of options, use +`fields.Char` instead. diff --git a/web_widget_dropdown_dynamic/readme/USAGE.md b/web_widget_dropdown_dynamic/readme/USAGE.md new file mode 100644 index 000000000000..1e0af7dd6943 --- /dev/null +++ b/web_widget_dropdown_dynamic/readme/USAGE.md @@ -0,0 +1,30 @@ +``` python +@api.model +def method_name(self): + values = [ + ('value_a', 'Title A'), + ] + if self.env.context.get('depending_on') == True: + values += [ + ('value_b', 'Title B'), + ] + return values +``` + +``` xml + + +``` + +**DEMO** + +On User defined filters added new field to show the feature, it is called +**Dropdown Integer**. If any user selected just One option shoud appear, but if +Mitchell Admin it should be possible to select option One and Two. \ No newline at end of file diff --git a/web_widget_dropdown_dynamic/static/description/icon.png b/web_widget_dropdown_dynamic/static/description/icon.png new file mode 100644 index 000000000000..3a0328b516c4 Binary files /dev/null and b/web_widget_dropdown_dynamic/static/description/icon.png differ diff --git a/web_widget_dropdown_dynamic/static/description/index.html b/web_widget_dropdown_dynamic/static/description/index.html new file mode 100644 index 000000000000..de49ad290556 --- /dev/null +++ b/web_widget_dropdown_dynamic/static/description/index.html @@ -0,0 +1,494 @@ + + + + + +Dynamic Dropdown Widget + + + +
+

Dynamic Dropdown Widget

+ + +

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runboat

+

Dynamic dropdown widget that supports resolving options from backend of:

+
+
    +
  • fields.Char
  • +
  • fields.Integer
  • +
  • fields.Selection
  • +
+
+

NOTE: This widget is not intended to extend fields.Selection, +but to filter selection values. For fully-dynamic set of options, use +fields.Char instead.

+

Table of contents

+ +
+

Usage

+
+@api.model
+def method_name(self):
+    values = [
+        ('value_a', 'Title A'),
+    ]
+    if self.env.context.get('depending_on') == True:
+        values += [
+            ('value_b', 'Title B'),
+        ]
+    return values
+
+
+<field
+    name="other_field"
+/>
+<field
+    name="char_field"
+    widget="dynamic_dropdown"
+    options="{'values':'method_name'}"
+    context="{'depending_on': other_field}"
+/>
+
+

DEMO

+

On User defined filters added new field to show the feature, it is +called Dropdown Integer. If any user selected just One option shoud +appear, but if Mitchell Admin it should be possible to select option One +and Two.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • CorporateHub
  • +
+
+
+

Contributors

+ +
+
+

Other credits

+

The migration of this module from 15.0 to 16.0 was financially supported +by Camptocamp

+
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/web project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/web_widget_dropdown_dynamic/static/src/js/field_dynamic_dropdown.esm.js b/web_widget_dropdown_dynamic/static/src/js/field_dynamic_dropdown.esm.js new file mode 100644 index 000000000000..38752bae519b --- /dev/null +++ b/web_widget_dropdown_dynamic/static/src/js/field_dynamic_dropdown.esm.js @@ -0,0 +1,89 @@ +/** @odoo-module **/ +import {_lt} from "@web/core/l10n/translation"; +import {registry} from "@web/core/registry"; +import {standardFieldProps} from "@web/views/fields/standard_field_props"; +import {Component, onWillStart, onWillUpdateProps} from "@odoo/owl"; + +export class FieldDynamicDropdown extends Component { + static template = "web.SelectionField"; + static props = { + ...standardFieldProps, + method: {type: String}, + context: {type: Object}, + }; + setup() { + this.type = this.props.record.fields[this.props.name].type; + onWillStart(async () => { + this.specialData = await this._fetchSpecialData(this.props); + }); + onWillUpdateProps(async (nextProps) => { + if (this.props.context.depending_on !== nextProps.context.depending_on) { + this.specialData = await this._fetchSpecialData(nextProps); + } + }); + } + async _fetchSpecialData(props) { + const {resModel} = props.record.model.config; + const {specialDataCaches, orm} = props.record.model; + const key = `__reference__${props.name}-${props.context.depending_on}`; + if (!specialDataCaches[key]) { + specialDataCaches[key] = await orm.call(resModel, props.method, [], { + context: props.context, + }); + } + return specialDataCaches[key]; + } + get options() { + var field_type = this.type || ""; + if (["char", "integer", "selection"].includes(field_type)) { + if ( + this.props.record.data[this.props.name] && + !this.specialData + .map((val) => val[0]) + .includes(String(this.props.record.data[this.props.name])) + ) { + this.props.record.update({[this.props.name]: null}); + } + return this.specialData; + } + return []; + } + get value() { + return String(this.props.record.data[this.props.name]); + } + parseInteger(value) { + return Number(value); + } + /** + * @param {Event} ev + */ + onChange(ev) { + var isInvalid = false; + var value = JSON.parse(ev.target.value); + if (this.type === "integer") { + value = Number(value); + if (!value) { + if (this.props.record) { + this.props.record.setInvalidField(this.props.name); + } + isInvalid = true; + } + } + if (!isInvalid) { + this.props.record.update({[this.props.name]: value}); + } + } + stringify(value) { + return JSON.stringify(value); + } +} +export const dynamicDropdownField = { + component: FieldDynamicDropdown, + displayName: _lt("Dynamic Dropdown"), + supportedTypes: ["char", "integer", "selection"], + extractProps: (fieldInfo, dynamicInfo) => ({ + method: fieldInfo.options?.values, + context: dynamicInfo.context, + }), +}; +registry.category("fields").add("dynamic_dropdown", dynamicDropdownField); diff --git a/web_widget_dropdown_dynamic/static/tests/web_widget_dropdown_dynamic_tests.esm.js b/web_widget_dropdown_dynamic/static/tests/web_widget_dropdown_dynamic_tests.esm.js new file mode 100644 index 000000000000..b8b258025f5f --- /dev/null +++ b/web_widget_dropdown_dynamic/static/tests/web_widget_dropdown_dynamic_tests.esm.js @@ -0,0 +1,182 @@ +/** @odoo-module **/ + +import {editInput, getFixture} from "@web/../tests/helpers/utils"; +import {makeView, setupViewRegistries} from "@web/../tests/views/helpers"; +const {QUnit} = window; + +let serverData = {}; +let target = getFixture(); + +QUnit.module("web_widget_dropdown_dynamic", (hooks) => { + hooks.beforeEach(() => { + target = getFixture(); + serverData = { + models: { + "sale.order": { + fields: { + content_string: {string: "Content", type: "char"}, + bool_field: {string: "Boolean", type: "boolean"}, + content_integer: {string: "Integer", type: "integer"}, + change_field: {string: "Change", type: "char"}, + content_selection: { + string: "Selection", + type: "selection", + selection: [["default", "Default"]], + }, + }, + records: [ + {id: 1, bool_field: false, change_field: ""}, + {id: 2, bool_field: true, change_field: ""}, + ], + methods: { + method_name() { + return [["value a", "Value A"]]; + }, + }, + }, + }, + }; + setupViewRegistries(); + }); + QUnit.test("values are fetched with changing context", async function (assert) { + assert.expect(13); + + await makeView({ + type: "form", + resModel: "sale.order", + serverData, + arch: ` +
+ + + `, + resId: 1, + mockRPC: function (route, args) { + assert.step(args.method); + if (args.method === "method_name") { + if (args.kwargs.context.depending_on === "step-1") { + return [["value", "Title"]]; + } else if (args.kwargs.context.depending_on === "step-2") { + return [ + ["value", "Title"], + ["value_2", "Title 2"], + ]; + } + return []; + } + }, + }); + + await editInput(target, ".o_field_widget[name='change_field'] input", "step-1"); + assert.containsN(target, "option", 2); + assert.containsOnce(target, "option[value='\"value\"']"); + await editInput(target, ".o_field_widget[name='change_field'] input", "step-2"); + + assert.containsN(target, "option", 3); + assert.containsOnce(target, "option[value='\"value\"']"); + assert.containsOnce(target, "option[value='\"value_2\"']"); + await editInput( + target, + ".o_field_widget[name='change_field'] input", + "step-other" + ); + + assert.containsN(target, "option", 1); + assert.verifySteps([ + "get_views", + "web_read", + "method_name", + "method_name", + "method_name", + "method_name", + ]); + }); + QUnit.test("values are fetched w/o context (char)", async (assert) => { + assert.expect(6); + console.log("Start assert", serverData); + console.log("Start makeView"); + await makeView({ + type: "form", + resModel: "sale.order", + serverData, + arch: ` +
+ + + `, + resId: 2, + mockRPC(route, args) { + assert.step(args.method); + if (args.method === "method_name") { + if (args.kwargs.context.depending_on) { + return [["value b", "Value B"]]; + } + } + }, + }); + const field_target = target.querySelector("div[name='content_string']"); + assert.verifySteps(["get_views", "web_read", "method_name"]); + assert.containsN(field_target, "option", 2); + assert.containsOnce( + field_target, + "option[value='\"value b\"']", + "got `value b` " + ); + + console.log("Ending makeView", target); + }); + + QUnit.test("values are fetched w/o context (integer)", async (assert) => { + assert.expect(6); + await makeView({ + type: "form", + resModel: "sale.order", + serverData, + arch: ` +
+ + + `, + resId: 2, + mockRPC(route, args) { + assert.step(args.method); + if (args.method === "method_name") { + if (args.kwargs.context.depending_on) { + return [["10", "Value B"]]; + } + } + }, + }); + const field_target = target.querySelector("div[name='content_integer']"); + assert.verifySteps(["get_views", "web_read", "method_name"]); + assert.containsN(field_target, "option", 2); + assert.containsOnce(field_target, 'option[value="\\"10\\""]'); + }); + + QUnit.test("values are fetched w/o context (selection)", async (assert) => { + assert.expect(6); + await makeView({ + type: "form", + resModel: "sale.order", + serverData, + arch: ` +
+ + + `, + resId: 2, + mockRPC(route, args) { + assert.step(args.method); + if (args.method === "method_name") { + if (args.kwargs.context.depending_on) { + return [["choice b", "Choice B"]]; + } + } + }, + }); + const field_target = target.querySelector("div[name='content_selection']"); + assert.verifySteps(["get_views", "web_read", "method_name"]); + assert.containsN(field_target, "option", 2); + assert.containsOnce(field_target, "option[value='\"choice b\"']"); + }); +});