Skip to content

Commit

Permalink
[MIG] web_widget_dropdown_dynamic: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
HeliconiaSolutions committed Dec 23, 2024
1 parent 20a9a82 commit dfc6557
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 35 deletions.
34 changes: 17 additions & 17 deletions web_widget_dropdown_dynamic/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ Dynamic Dropdown Widget
: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
:target: https://github.com/OCA/web/tree/18.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
:target: https://translation.odoo-community.org/projects/web-18-0/web-18-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
:target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=18.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``
- ``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
Expand Down Expand Up @@ -84,7 +84,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/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 <https://github.com/OCA/web/issues/new?body=module:%20web_widget_dropdown_dynamic%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_widget_dropdown_dynamic%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Expand All @@ -99,23 +99,23 @@ Authors
Contributors
------------

- `CorporateHub <https://corporatehub.eu/>`__
- `CorporateHub <https://corporatehub.eu/>`__

- Alexey Pelykh <[email protected]>
- Alexey Pelykh <[email protected]>

- `Therp BV <https://therp.nl/>`__
- `Therp BV <https://therp.nl/>`__

- Ronald Portier <[email protected]>
- Ronald Portier <[email protected]>

- Thanakrit Pintana <[email protected]>
- Thanakrit Pintana <[email protected]>

- `Trobz <https://trobz.com>`__:
- `Trobz <https://trobz.com>`__:

- Son Ho <[email protected]>
- Son Ho <[email protected]>

- `Tecnativa <https://www.tecnativa.com>`__:
- `Tecnativa <https://www.tecnativa.com>`__:

- Carlos Roca
- Carlos Roca

Other credits
-------------
Expand All @@ -136,6 +136,6 @@ 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 <https://github.com/OCA/web/tree/17.0/web_widget_dropdown_dynamic>`_ project on GitHub.
This module is part of the `OCA/web <https://github.com/OCA/web/tree/18.0/web_widget_dropdown_dynamic>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion web_widget_dropdown_dynamic/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Dynamic Dropdown Widget",
"summary": "This module adds support for dynamic dropdown widget",
"category": "Web",
"version": "17.0.1.0.0",
"version": "18.0.1.0.0",
"license": "AGPL-3",
"author": "CorporateHub, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/web",
Expand Down
6 changes: 3 additions & 3 deletions web_widget_dropdown_dynamic/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ <h1 class="title">Dynamic Dropdown Widget</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:cd8f2fbb81d5981346094e7fb21bd25632e10536593177a28be1aca666f715a5
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/web/tree/17.0/web_widget_dropdown_dynamic"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/web-17-0/web-17-0-web_widget_dropdown_dynamic"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/web&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/web/tree/18.0/web_widget_dropdown_dynamic"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/web-18-0/web-18-0-web_widget_dropdown_dynamic"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/web&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>Dynamic dropdown widget that supports resolving options from backend of:</p>
<blockquote>
<ul class="simple">
Expand Down Expand Up @@ -431,7 +431,7 @@ <h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/web/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_widget_dropdown_dynamic%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_widget_dropdown_dynamic%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand Down Expand Up @@ -485,7 +485,7 @@ <h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/17.0/web_widget_dropdown_dynamic">OCA/web</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/18.0/web_widget_dropdown_dynamic">OCA/web</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/** @odoo-module **/
import {_lt} from "@web/core/l10n/translation";
import {_t} 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";
import {useOwnedDialogs} from "@web/core/utils/hooks";

export class FieldDynamicDropdown extends Component {
static template = "web.SelectionField";
Expand All @@ -11,31 +12,39 @@ export class FieldDynamicDropdown extends Component {
method: {type: String},
context: {type: Object},
};

setup() {
super.setup();
this.dialogs = useOwnedDialogs();
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)) {
const fieldType = this.type || "";
if (["char", "integer", "selection"].includes(fieldType)) {
if (
this.props.record.data[this.props.name] &&
!this.specialData
Expand All @@ -48,18 +57,22 @@ export class FieldDynamicDropdown extends Component {
}
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);
let isInvalid = false;
let value = JSON.parse(ev.target.value);

if (this.type === "integer") {
value = Number(value);
if (!value) {
Expand All @@ -69,21 +82,25 @@ export class FieldDynamicDropdown extends Component {
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"),
displayName: _t("Dynamic Dropdown"),
supportedTypes: ["char", "integer", "selection"],
extractProps: (fieldInfo, dynamicInfo) => ({
method: fieldInfo.options?.values,
context: dynamicInfo.context,
extractProps: ({options}, {context}) => ({
method: options?.values,
context,
}),
};

registry.category("fields").add("dynamic_dropdown", dynamicDropdownField);
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import {editInput, getFixture} from "@web/../tests/helpers/utils";
import {makeView, setupViewRegistries} from "@web/../tests/views/helpers";
const {QUnit} = window;
import {QUnit} from "@web/static/lib/qunit/qunit";

let serverData = {};
let target = getFixture();
Expand Down Expand Up @@ -93,8 +93,6 @@ QUnit.module("web_widget_dropdown_dynamic", (hooks) => {
});
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",
Expand Down Expand Up @@ -122,8 +120,6 @@ QUnit.module("web_widget_dropdown_dynamic", (hooks) => {
"option[value='\"value b\"']",
"got `value b` "
);

console.log("Ending makeView", target);
});

QUnit.test("values are fetched w/o context (integer)", async (assert) => {
Expand Down

0 comments on commit dfc6557

Please sign in to comment.