mirror of https://github.com/OCA/web.git
[IMP] web_widget_dropdown_dynamic: black, isort, prettier
parent
ec5084302a
commit
db803eb8c8
|
@ -8,7 +8,7 @@
|
||||||
"version": "13.0.1.0.0",
|
"version": "13.0.1.0.0",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"author": "CorporateHub, Odoo Community Association (OCA)",
|
"author": "CorporateHub, Odoo Community Association (OCA)",
|
||||||
"website": "https://github.com/OCA/web/",
|
"website": "https://github.com/OCA/web",
|
||||||
"depends": ["web"],
|
"depends": ["web"],
|
||||||
"data": ["templates/assets.xml"],
|
"data": ["templates/assets.xml"],
|
||||||
"installable": True,
|
"installable": True,
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* Copyright 2019-2020 Brainbean Apps (https://brainbeanapps.com)
|
* Copyright 2019-2020 Brainbean Apps (https://brainbeanapps.com)
|
||||||
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||||
*/
|
*/
|
||||||
odoo.define("web_widget_dropdown_dynamic.basic_model", function(require) {
|
odoo.define("web_widget_dropdown_dynamic.basic_model", function (require) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var BasicModel = require("web.BasicModel");
|
var BasicModel = require("web.BasicModel");
|
||||||
|
@ -20,7 +20,7 @@ odoo.define("web_widget_dropdown_dynamic.basic_model", function(require) {
|
||||||
* (for the given parameters), no RPC is done and the promise
|
* (for the given parameters), no RPC is done and the promise
|
||||||
* is resolved with the undefined value.
|
* is resolved with the undefined value.
|
||||||
*/
|
*/
|
||||||
_fetchDynamicDropdownValues: function(record, fieldName, fieldInfo) {
|
_fetchDynamicDropdownValues: function (record, fieldName, fieldInfo) {
|
||||||
var model = fieldInfo.options.model || record.model;
|
var model = fieldInfo.options.model || record.model;
|
||||||
var method = fieldInfo.values || fieldInfo.options.values;
|
var method = fieldInfo.values || fieldInfo.options.values;
|
||||||
if (!method) {
|
if (!method) {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
|
* Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
|
||||||
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||||
*/
|
*/
|
||||||
odoo.define("web_widget_dropdown_dynamic.field_dynamic_dropdown", function(require) {
|
odoo.define("web_widget_dropdown_dynamic.field_dynamic_dropdown", function (require) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var core = require("web.core");
|
var core = require("web.core");
|
||||||
|
@ -22,7 +22,7 @@ odoo.define("web_widget_dropdown_dynamic.field_dynamic_dropdown", function(requi
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
init: function() {
|
init: function () {
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
this._setValues();
|
this._setValues();
|
||||||
},
|
},
|
||||||
|
@ -35,13 +35,13 @@ odoo.define("web_widget_dropdown_dynamic.field_dynamic_dropdown", function(requi
|
||||||
* @override
|
* @override
|
||||||
* @returns {jQuery}
|
* @returns {jQuery}
|
||||||
*/
|
*/
|
||||||
getFocusableElement: function() {
|
getFocusableElement: function () {
|
||||||
return this.$el.is("select") ? this.$el : $();
|
return this.$el.is("select") ? this.$el : $();
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
isSet: function() {
|
isSet: function () {
|
||||||
return this.value !== false;
|
return this.value !== false;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
@ -50,7 +50,7 @@ odoo.define("web_widget_dropdown_dynamic.field_dynamic_dropdown", function(requi
|
||||||
*
|
*
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
updateModifiersValue: function() {
|
updateModifiersValue: function () {
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
if (!this.attrs.modifiersValue.invisible && this.mode !== "readonly") {
|
if (!this.attrs.modifiersValue.invisible && this.mode !== "readonly") {
|
||||||
this._setValues();
|
this._setValues();
|
||||||
|
@ -66,14 +66,14 @@ odoo.define("web_widget_dropdown_dynamic.field_dynamic_dropdown", function(requi
|
||||||
* @override
|
* @override
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_formatValue: function(value) {
|
_formatValue: function (value) {
|
||||||
var options = _.extend(
|
var options = _.extend(
|
||||||
{},
|
{},
|
||||||
this.nodeOptions,
|
this.nodeOptions,
|
||||||
{data: this.recordData},
|
{data: this.recordData},
|
||||||
this.formatOptions
|
this.formatOptions
|
||||||
);
|
);
|
||||||
var formattedValue = _.find(this.values, function(option) {
|
var formattedValue = _.find(this.values, function (option) {
|
||||||
return option[0] === value;
|
return option[0] === value;
|
||||||
});
|
});
|
||||||
if (!formattedValue) {
|
if (!formattedValue) {
|
||||||
|
@ -89,7 +89,7 @@ odoo.define("web_widget_dropdown_dynamic.field_dynamic_dropdown", function(requi
|
||||||
* @override
|
* @override
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_renderEdit: function() {
|
_renderEdit: function () {
|
||||||
this.$el.empty();
|
this.$el.empty();
|
||||||
for (var i = 0; i < this.values.length; i++) {
|
for (var i = 0; i < this.values.length; i++) {
|
||||||
this.$el.append(
|
this.$el.append(
|
||||||
|
@ -105,13 +105,13 @@ odoo.define("web_widget_dropdown_dynamic.field_dynamic_dropdown", function(requi
|
||||||
* @override
|
* @override
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_renderReadonly: function() {
|
_renderReadonly: function () {
|
||||||
this.$el.empty().text(this._formatValue(this.value));
|
this.$el.empty().text(this._formatValue(this.value));
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
_reset: function() {
|
_reset: function () {
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
this._setValues();
|
this._setValues();
|
||||||
},
|
},
|
||||||
|
@ -120,8 +120,8 @@ odoo.define("web_widget_dropdown_dynamic.field_dynamic_dropdown", function(requi
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_setValues: function() {
|
_setValues: function () {
|
||||||
this.values = _.reject(this.record.specialData[this.name], function(v) {
|
this.values = _.reject(this.record.specialData[this.name], function (v) {
|
||||||
return v[0] === false && v[1] === "";
|
return v[0] === false && v[1] === "";
|
||||||
});
|
});
|
||||||
if (!this.attrs.modifiersValue || !this.attrs.modifiersValue.required) {
|
if (!this.attrs.modifiersValue || !this.attrs.modifiersValue.required) {
|
||||||
|
@ -138,7 +138,7 @@ odoo.define("web_widget_dropdown_dynamic.field_dynamic_dropdown", function(requi
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_onChange: function() {
|
_onChange: function () {
|
||||||
var value = JSON.parse(this.$el.val());
|
var value = JSON.parse(this.$el.val());
|
||||||
this._setValue(value.toString());
|
this._setValue(value.toString());
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
odoo.define("web_widget_dropdown_dynamic.web_widget_dropdown_dynamic_tests", function(
|
odoo.define("web_widget_dropdown_dynamic.web_widget_dropdown_dynamic_tests", function (
|
||||||
require
|
require
|
||||||
) {
|
) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
@ -8,8 +8,8 @@ odoo.define("web_widget_dropdown_dynamic.web_widget_dropdown_dynamic_tests", fun
|
||||||
var FormView = require("web.FormView");
|
var FormView = require("web.FormView");
|
||||||
var testUtils = require("web.test_utils");
|
var testUtils = require("web.test_utils");
|
||||||
|
|
||||||
QUnit.module("web_widget_dropdown_dynamic", {}, function() {
|
QUnit.module("web_widget_dropdown_dynamic", {}, function () {
|
||||||
QUnit.test("values are fetched w/o context (char)", async function(assert) {
|
QUnit.test("values are fetched w/o context (char)", async function (assert) {
|
||||||
assert.expect(2);
|
assert.expect(2);
|
||||||
|
|
||||||
var form = await testUtils.createView({
|
var form = await testUtils.createView({
|
||||||
|
@ -27,7 +27,7 @@ odoo.define("web_widget_dropdown_dynamic.web_widget_dropdown_dynamic_tests", fun
|
||||||
"<form>" +
|
"<form>" +
|
||||||
'<field name="test_field" widget="dynamic_dropdown" values="_get_test_field_values"/>' +
|
'<field name="test_field" widget="dynamic_dropdown" values="_get_test_field_values"/>' +
|
||||||
"</form>",
|
"</form>",
|
||||||
mockRPC: function(route, args) {
|
mockRPC: function (route, args) {
|
||||||
if (args.method === "_get_test_field_values") {
|
if (args.method === "_get_test_field_values") {
|
||||||
return Promise.resolve([["value", "Title"]]);
|
return Promise.resolve([["value", "Title"]]);
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ odoo.define("web_widget_dropdown_dynamic.web_widget_dropdown_dynamic_tests", fun
|
||||||
form.destroy();
|
form.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test("values are fetched w/o context (integer)", async function(assert) {
|
QUnit.test("values are fetched w/o context (integer)", async function (assert) {
|
||||||
assert.expect(2);
|
assert.expect(2);
|
||||||
|
|
||||||
var form = await testUtils.createView({
|
var form = await testUtils.createView({
|
||||||
|
@ -59,7 +59,7 @@ odoo.define("web_widget_dropdown_dynamic.web_widget_dropdown_dynamic_tests", fun
|
||||||
"<form>" +
|
"<form>" +
|
||||||
'<field name="test_field" widget="dynamic_dropdown" values="_get_test_field_values"/>' +
|
'<field name="test_field" widget="dynamic_dropdown" values="_get_test_field_values"/>' +
|
||||||
"</form>",
|
"</form>",
|
||||||
mockRPC: function(route, args) {
|
mockRPC: function (route, args) {
|
||||||
if (args.method === "_get_test_field_values") {
|
if (args.method === "_get_test_field_values") {
|
||||||
return Promise.resolve([[0, "Title"]]);
|
return Promise.resolve([[0, "Title"]]);
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ odoo.define("web_widget_dropdown_dynamic.web_widget_dropdown_dynamic_tests", fun
|
||||||
form.destroy();
|
form.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test("values are fetched w/o context (selection)", async function(
|
QUnit.test("values are fetched w/o context (selection)", async function (
|
||||||
assert
|
assert
|
||||||
) {
|
) {
|
||||||
assert.expect(2);
|
assert.expect(2);
|
||||||
|
@ -93,7 +93,7 @@ odoo.define("web_widget_dropdown_dynamic.web_widget_dropdown_dynamic_tests", fun
|
||||||
"<form>" +
|
"<form>" +
|
||||||
'<field name="test_field" widget="dynamic_dropdown" values="_get_test_field_values"/>' +
|
'<field name="test_field" widget="dynamic_dropdown" values="_get_test_field_values"/>' +
|
||||||
"</form>",
|
"</form>",
|
||||||
mockRPC: function(route, args) {
|
mockRPC: function (route, args) {
|
||||||
if (args.method === "_get_test_field_values") {
|
if (args.method === "_get_test_field_values") {
|
||||||
return Promise.resolve([["value", "Title"]]);
|
return Promise.resolve([["value", "Title"]]);
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ odoo.define("web_widget_dropdown_dynamic.web_widget_dropdown_dynamic_tests", fun
|
||||||
form.destroy();
|
form.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test("values are fetched with changing context", async function(assert) {
|
QUnit.test("values are fetched with changing context", async function (assert) {
|
||||||
assert.expect(6);
|
assert.expect(6);
|
||||||
|
|
||||||
var form = await testUtils.createView({
|
var form = await testUtils.createView({
|
||||||
|
@ -127,7 +127,7 @@ odoo.define("web_widget_dropdown_dynamic.web_widget_dropdown_dynamic_tests", fun
|
||||||
'<field name="other_field" />' +
|
'<field name="other_field" />' +
|
||||||
'<field name="test_field" widget="dynamic_dropdown" values="_get_test_field_values" context="{\'step\': other_field}"/>' +
|
'<field name="test_field" widget="dynamic_dropdown" values="_get_test_field_values" context="{\'step\': other_field}"/>' +
|
||||||
"</form>",
|
"</form>",
|
||||||
mockRPC: function(route, args) {
|
mockRPC: function (route, args) {
|
||||||
if (args.method === "_get_test_field_values") {
|
if (args.method === "_get_test_field_values") {
|
||||||
if (args.kwargs.context.step === "step-1") {
|
if (args.kwargs.context.step === "step-1") {
|
||||||
return Promise.resolve([["value", "Title"]]);
|
return Promise.resolve([["value", "Title"]]);
|
||||||
|
|
Loading…
Reference in New Issue