[FIX] isort, prettier, black: JS lint in all affect modules

pull/1976/head
KKamaa 2022-03-28 03:43:11 +03:00
parent 872ae6cb09
commit 9bd63dd24a
14 changed files with 116 additions and 81 deletions

View File

@ -1,11 +1,13 @@
odoo.define('support_branding.crash_manager_tests', function (require) { odoo.define("support_branding.crash_manager_tests", function (require) {
"use strict"; "use strict";
const CrashManager = require('web.CrashManager').CrashManager; /* global QUnit*/
const testUtils = require('web.test_utils');
const CrashManager = require("web.CrashManager").CrashManager;
const testUtils = require("web.test_utils");
const createActionManager = testUtils.createActionManager; const createActionManager = testUtils.createActionManager;
QUnit.module('support_branding', {}, function() { QUnit.module("support_branding", {}, function () {
QUnit.test("Error Dialog is created", async function (assert) { QUnit.test("Error Dialog is created", async function (assert) {
// No of assertion expected. // No of assertion expected.
assert.expect(5); assert.expect(5);
@ -14,53 +16,63 @@ odoo.define('support_branding.crash_manager_tests', function (require) {
var actionManager = await createActionManager({ var actionManager = await createActionManager({
services: { services: {
crash_manager: CrashManager, crash_manager: CrashManager,
} },
}); });
// Check if action with crash manager service was created. // Check if action with crash manager service was created.
assert.notOk(_.isEmpty(actionManager), "Action manager with " + assert.notOk(
"crash manager service should be created and not empty"); _.isEmpty(actionManager),
"Action manager with " +
"crash manager service should be created and not empty"
);
// Test custom error // Test custom error
let error = { const error = {
type: 'Support Branding Odoo Client Error', type: "Support Branding Odoo Client Error",
message: 'Message', message: "Message",
data: { data: {
debug: 'Traceback', debug: "Traceback",
}, },
}; };
// NB: This will use the saved res.config settings of support // NB: This will use the saved res.config settings of support
// branding containing the support mail. It is fetched in crash // branding containing the support mail. It is fetched in crash
// manager init function as saved in res.config settings. // manager init function as saved in res.config settings.
// attached is a default data xml with sample data. // attached is a default data xml with sample data.
actionManager.call('crash_manager', 'show_error', error); actionManager.call("crash_manager", "show_error", error);
await testUtils.nextTick(); await testUtils.nextTick();
var $mail_dialog = 'form.support-branding-submit-form'; var $mail_dialog = "form.support-branding-submit-form";
// Confirm if we have a form and its required elements. // Confirm if we have a form and its required elements.
assert.containsOnce($, $mail_dialog, "Error dialog should be " + assert.containsOnce(
"opened and showing mail section on footer"); $,
assert.containsOnce($, '.support-desc', 'We should have a ' + $mail_dialog,
'textarea to add our issues'); "Error dialog should be opened and showing mail section on footer"
assert.containsOnce($, 'button.support-btn', 'We should have a ' + );
'send mail button to send support mail'); assert.containsOnce(
$,
".support-desc",
"We should have a textarea to add our issues"
);
assert.containsOnce(
$,
"button.support-btn",
"We should have a send mail button to send support mail"
);
// Add a test text mail. // Add a test text mail.
$(".support-desc").val("Send this as a test mail to " + $(".support-desc").val(
"configured support mail"); "Send this as a test mail to configured support mail"
);
// Try to send mail, by default a popup will be triggered // Try to send mail, by default a popup will be triggered
// defaulting to form call of 'mailto'. // defaulting to form call of 'mailto'.
await testUtils.dom.click($('button.support-btn'), await testUtils.dom.click($("button.support-btn"), {allowInvisible: true});
{allowInvisible: true});
// Close error dialog // Close error dialog
await testUtils.dom.click($('button.close'), await testUtils.dom.click($("button.close"), {allowInvisible: true});
{allowInvisible: true});
// Confirm dialog was closed // Confirm dialog was closed
assert.containsNone($, $mail_dialog, assert.containsNone($, $mail_dialog, "Error Dialog should be closed");
"Error Dialog should be closed");
actionManager.destroy(); actionManager.destroy();
}); });

View File

@ -8,7 +8,6 @@ odoo.define("web_advanced_search.RelationalOwl", function (require) {
const FieldMany2One = relationalFields.FieldMany2One; const FieldMany2One = relationalFields.FieldMany2One;
const FieldManagerMixin = require("web.FieldManagerMixin"); const FieldManagerMixin = require("web.FieldManagerMixin");
const {useListener} = require("web.custom_hooks"); const {useListener} = require("web.custom_hooks");
/* global owl */
const {Component} = owl; const {Component} = owl;
const {xml} = owl.tags; const {xml} = owl.tags;

View File

@ -15,6 +15,10 @@ odoo.define("web_calendar_color_field.CalendarModel", function (require) {
* *
* If the field is also added to filters, and a color field is defined, * If the field is also added to filters, and a color field is defined,
* we use that color field as colorIndex. * we use that color field as colorIndex.
*
* @param {Object} element: ''
* @param {Array} events: ''
* @returns {Promise}
*/ */
_loadColors: function (element, events) { _loadColors: function (element, events) {
var self = this; var self = this;

View File

@ -11,7 +11,7 @@ odoo.define("web_calendar_slot_duration.CalendarModel", function (require) {
* @override * @override
*/ */
_getFullCalendarOptions: function () { _getFullCalendarOptions: function () {
var result = this._super.call(this, arguments); var result = this._super.apply(this, arguments);
result.slotDuration = result.slotDuration =
this.data.context.calendar_slot_duration || this.data.context.calendar_slot_duration ||
result.slotDuration || result.slotDuration ||

View File

@ -1,4 +1,4 @@
/* global Uint8Array, base64js */ /* global base64js */
// Copyright 2018 Therp BV <https://therp.nl> // Copyright 2018 Therp BV <https://therp.nl>
// Copyright 2021 Tecnativa - Alexandre D. Díaz // Copyright 2021 Tecnativa - Alexandre D. Díaz
// License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). // License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
@ -24,7 +24,8 @@ odoo.define("web_drop_target", function (require) {
*/ */
start: function () { start: function () {
const $body = $("body"); const $body = $("body");
this._dropZoneNS = _.uniqueId("o_dz_"); // For event namespace used when multiple chat window is open // For event namespace used when multiple chat window is open
this._dropZoneNS = _.uniqueId("o_dz_");
$body.on( $body.on(
"dragleave." + this._dropZoneNS, "dragleave." + this._dropZoneNS,
this._onBodyFileDragLeave.bind(this) this._onBodyFileDragLeave.bind(this)
@ -159,7 +160,7 @@ odoo.define("web_drop_target", function (require) {
if ( if (
_.isEmpty(this._get_drop_items(ev)) && _.isEmpty(this._get_drop_items(ev)) &&
this._checkDragOver() && this._checkDragOver() &&
(controller == undefined || controller.jsID === this.controllerID) (controller === undefined || controller.jsID === this.controllerID)
) { ) {
const drop_zone_offset = this.$drop_zone.offset(); const drop_zone_offset = this.$drop_zone.offset();
const overlay_css = { const overlay_css = {
@ -212,6 +213,7 @@ odoo.define("web_drop_target", function (require) {
* *
* @private * @private
* @param {MouseEvent} ev * @param {MouseEvent} ev
* @returns {Object} drop items
*/ */
_get_drop_items: function (ev) { _get_drop_items: function (ev) {
let drop_items = []; let drop_items = [];
@ -250,6 +252,7 @@ odoo.define("web_drop_target", function (require) {
* @param {String} res_model * @param {String} res_model
* @param {Number} res_id * @param {Number} res_id
* @param {Object} extra_data * @param {Object} extra_data
* @returns {Void}
*/ */
_create_attachment: function (file, reader, res_model, res_id, extra_data) { _create_attachment: function (file, reader, res_model, res_id, extra_data) {
// Helper to upload an attachment and update the sidebar // Helper to upload an attachment and update the sidebar

View File

@ -134,7 +134,7 @@ odoo.define("web_m2x_options.web_m2x_options", function (require) {
if (blacklisted_ids.length > 0) { if (blacklisted_ids.length > 0) {
domain.push(["id", "not in", blacklisted_ids]); domain.push(["id", "not in", blacklisted_ids]);
} }
/* eslint-disable complexity */
self._rpc({ self._rpc({
model: self.field.relation, model: self.field.relation,
method: "name_search", method: "name_search",
@ -201,16 +201,15 @@ odoo.define("web_m2x_options.web_m2x_options", function (require) {
// 3- if not set locally, check if it's set globally via ir.config_parameter // 3- if not set locally, check if it's set globally via ir.config_parameter
// 4- if set globally, apply its value // 4- if set globally, apply its value
// 5- if not set globally either, check if returned values are more than node's limit // 5- if not set globally either, check if returned values are more than node's limit
var search_more = values.length > self.limit;
if (!_.isUndefined(self.nodeOptions.search_more)) { if (!_.isUndefined(self.nodeOptions.search_more)) {
var search_more = is_option_set(self.nodeOptions.search_more); search_more = is_option_set(self.nodeOptions.search_more);
} else if ( } else if (
!_.isUndefined(ir_options["web_m2x_options.search_more"]) !_.isUndefined(ir_options["web_m2x_options.search_more"])
) { ) {
var search_more = is_option_set( search_more = is_option_set(
ir_options["web_m2x_options.search_more"] ir_options["web_m2x_options.search_more"]
); );
} else {
var search_more = values.length > self.limit;
} }
if (search_more) { if (search_more) {
@ -349,6 +348,7 @@ odoo.define("web_m2x_options.web_m2x_options", function (require) {
resolve(values); resolve(values);
} }
}); });
/* eslint-enable complexity */
}); });
this.orderer.add(def); this.orderer.add(def);
@ -483,7 +483,7 @@ odoo.define("web_m2x_options.web_m2x_options", function (require) {
this._super(attrs); this._super(attrs);
var limit = ir_options["web_m2x_options.field_limit_entries"]; var limit = ir_options["web_m2x_options.field_limit_entries"];
if (!_.isUndefined(limit)) { if (!_.isUndefined(limit)) {
attrs.limit = parseInt(limit); attrs.limit = parseInt(limit, 10);
} }
}, },
}); });

View File

@ -21,7 +21,8 @@ odoo.define("web_pwa_oca.PWAManager", function (require) {
"Service workers are not supported! Maybe you are not using HTTPS or you work in private mode." "Service workers are not supported! Maybe you are not using HTTPS or you work in private mode."
) )
); );
} else { }
if ("serviceWorker" in navigator) {
this._service_worker = navigator.serviceWorker; this._service_worker = navigator.serviceWorker;
this.registerServiceWorker("/service-worker.js"); this.registerServiceWorker("/service-worker.js");
} }

View File

@ -61,13 +61,15 @@
"click .o_kanban_mobile_tab": "_onMobileTabClicked", "click .o_kanban_mobile_tab": "_onMobileTabClicked",
"click .o_kanban_mobile_add_column": "_onMobileQuickCreateClicked", "click .o_kanban_mobile_add_column": "_onMobileQuickCreateClicked",
}), }),
ANIMATE: true, // Allows to disable animations for the tests // Allows to disable animations for the tests
ANIMATE: true,
/** /**
* @override * @override
*/ */
init: function () { init: function () {
this._super.apply(this, arguments); this._super.apply(this, arguments);
this.activeColumnIndex = 0; // Index of the currently displayed column // Index of the currently displayed column
this.activeColumnIndex = 0;
this._scrollPosition = null; this._scrollPosition = null;
}, },
/** /**
@ -377,7 +379,8 @@
db_id: column.db_id, db_id: column.db_id,
onSuccess: () => self._layoutUpdate(animate), onSuccess: () => self._layoutUpdate(animate),
}); });
} else { }
if (column.data.isOpen) {
this._layoutUpdate(animate); this._layoutUpdate(animate);
} }
return Promise.resolve(); return Promise.resolve();
@ -396,16 +399,19 @@
_renderGrouped: function (fragment) { _renderGrouped: function (fragment) {
var self = this; var self = this;
var newFragment = document.createDocumentFragment(); var newFragment = document.createDocumentFragment();
this._super.apply(this, [newFragment]); var fragment_change = [newFragment];
this._super.apply(this, fragment_change);
this.defs.push( this.defs.push(
Promise.all(this.defs).then(function () { Promise.all(this.defs).then(function () {
var data = []; var data = [];
_.each(self.state.data, function (group) { _.each(self.state.data, function (group) {
if (!group.value) { var grp = group;
group = _.extend({}, group, {value: _t("Undefined")}); if (!grp.value) {
data.unshift(group); grp = _.extend({}, grp, {value: _t("Undefined")});
} else { data.unshift(grp);
data.push(group); }
if (grp.value) {
data.push(grp);
} }
}); });
@ -445,7 +451,7 @@
* Retrieve the Jquery node (.o_kanban_group) for a list of a given widgets * Retrieve the Jquery node (.o_kanban_group) for a list of a given widgets
* *
* @private * @private
* @param widgets * @param {Object} widgets: ''
* @returns {jQuery} the matching .o_kanban_group widgets * @returns {jQuery} the matching .o_kanban_group widgets
*/ */
_toNode: function (widgets) { _toNode: function (widgets) {
@ -462,8 +468,8 @@
* Update the given column to the updated positions * Update the given column to the updated positions
* *
* @private * @private
* @param $column The jquery column * @param {Object} $column The jquery column
* @param cssProperties Use to update column * @param {Object} cssProperties Use to update column
* @param {Boolean} [animate=false] set to true to animate * @param {Boolean} [animate=false] set to true to animate
* @returns {Promise} * @returns {Promise}
*/ */
@ -493,6 +499,7 @@
/** /**
* @private * @private
* @param {MouseEvent} event
*/ */
_onMobileQuickCreateClicked: function (event) { _onMobileQuickCreateClicked: function (event) {
if (event) { if (event) {

View File

@ -21,7 +21,6 @@ odoo.define("web_responsive", function (require) {
const PatchableAttachmentViewer = patchMixin(AttachmentViewer); const PatchableAttachmentViewer = patchMixin(AttachmentViewer);
const ControlPanel = require("web.ControlPanel"); const ControlPanel = require("web.ControlPanel");
const SearchPanel = require("web/static/src/js/views/search_panel.js"); const SearchPanel = require("web/static/src/js/views/search_panel.js");
/* global owl */
const {QWeb, Context} = owl; const {QWeb, Context} = owl;
const {useState, useContext} = owl.hooks; const {useState, useContext} = owl.hooks;

View File

@ -20,22 +20,12 @@ odoo.define(
isShiftKey, isShiftKey,
}) { }) {
const queryElem = this.state.query.find( const queryElem = this.state.query.find(
(queryElem) => (queryElem_val) =>
queryElem.filterId === filterId && queryElem_val.filterId === filterId &&
queryElem.value === value && queryElem_val.value === value &&
queryElem.operator === operator queryElem_val.operator === operator
); );
if (!queryElem) { if (!queryElem) {
if (isShiftKey) {
const groupId = Math.random();
this.state.query.push({
filterId,
groupId,
label,
value,
operator,
});
} else {
const {groupId} = this.state.filters[filterId]; const {groupId} = this.state.filters[filterId];
this.state.query.push({ this.state.query.push({
filterId, filterId,
@ -44,8 +34,18 @@ odoo.define(
value, value,
operator, operator,
}); });
if (isShiftKey) {
const group_id = Math.random();
this.state.query.push({
filterId,
group_id,
label,
value,
operator,
});
} }
} else { }
if (queryElem) {
queryElem.label = label; queryElem.label = label;
} }
}, },

View File

@ -36,6 +36,8 @@ odoo.define("web_search_with_and/static/src/js/search_bar.js", function (require
this._closeAutoComplete(); this._closeAutoComplete();
}, },
/* eslint-disable complexity */
/** /**
* @private * @private
* @param {KeyboardEvent} ev * @param {KeyboardEvent} ev
@ -100,7 +102,7 @@ odoo.define("web_search_with_and/static/src/js/search_bar.js", function (require
} }
} }
break; break;
case "ArrowUp": case "ArrowUp": {
ev.preventDefault(); ev.preventDefault();
let previousIndex = this.state.focusedItem - 1; let previousIndex = this.state.focusedItem - 1;
if (previousIndex < 0) { if (previousIndex < 0) {
@ -108,6 +110,7 @@ odoo.define("web_search_with_and/static/src/js/search_bar.js", function (require
} }
this.state.focusedItem = previousIndex; this.state.focusedItem = previousIndex;
break; break;
}
case "Backspace": case "Backspace":
if (!this.state.inputValue.length) { if (!this.state.inputValue.length) {
const facets = this.model.get("facets"); const facets = this.model.get("facets");
@ -124,7 +127,8 @@ odoo.define("web_search_with_and/static/src/js/search_bar.js", function (require
/* Falls through */ /* Falls through */
case "Tab": case "Tab":
if (this.state.inputValue.length) { if (this.state.inputValue.length) {
ev.preventDefault(); // Keep the focus inside the search bar // Keep the focus inside the search bar
ev.preventDefault();
this._selectSource(currentItem); this._selectSource(currentItem);
} }
break; break;
@ -135,5 +139,6 @@ odoo.define("web_search_with_and/static/src/js/search_bar.js", function (require
break; break;
} }
}, },
/* eslint-enable complexity */
}); });
}); });

View File

@ -1,8 +1,8 @@
// Show a big banner in the top of the page if the context has been // Show a big banner in the top of the page if the context has been
// Changed in another tab or window (in the same browser) // Changed in another tab or window (in the same browser)
var con = []; window.con = [];
var lastCtx = null; window.lastCtx = null;
addEventListener( addEventListener(
"connect", "connect",
@ -10,21 +10,21 @@ addEventListener(
"use strict"; "use strict";
var port = ee.ports[0]; var port = ee.ports[0];
con.push(port); window.con.push(port);
port.onmessage = function (e) { port.onmessage = function (e) {
var newCtx = e.data; var newCtx = e.data;
if (lastCtx && newCtx !== lastCtx) { if (window.lastCtx && newCtx !== window.lastCtx) {
con.forEach(function (eport) { window.con.forEach(function (eport) {
eport.postMessage({ eport.postMessage({
type: "newCtx", type: "newCtx",
newCtx: newCtx, newCtx: newCtx,
lastCtx: lastCtx, lastCtx: window.lastCtx,
}); });
}); });
} }
lastCtx = newCtx; window.lastCtx = newCtx;
}; };
}, },
false false

View File

@ -159,21 +159,23 @@ odoo.define("web_widget_numeric_step.field", function (require) {
* @param {String} mode can be "plus" or "minus" * @param {String} mode can be "plus" or "minus"
*/ */
_doStep: function (mode) { _doStep: function (mode) {
let mode_val = mode;
let cval = 0; let cval = 0;
try { try {
const field = this.record.fields[this.name]; const field = this.record.fields[this.name];
cval = field_utils.parse[field.type](this.$input.val()); cval = field_utils.parse[field.type](this.$input.val());
} catch (e) { } catch (e) {
cval = this.value; cval = this.value;
mode = false; // Only set the value in this case // Only set the value in this case
mode_val = false;
} }
if (mode === "plus") { if (mode_val === "plus") {
cval += this._config.step; cval += this._config.step;
} else if (mode === "minus") { } else if (mode_val === "minus") {
cval -= this._config.step; cval -= this._config.step;
} }
const nval = this._sanitizeNumberValue(cval); const nval = this._sanitizeNumberValue(cval);
if (nval !== this.lastSetValue || !mode) { if (nval !== this.lastSetValue || !mode_val) {
this.$input.val(nval); this.$input.val(nval);
// Every time that user update the value we must trigger an // Every time that user update the value we must trigger an
// onchange method. // onchange method.

View File

@ -176,6 +176,9 @@ odoo.define("web_widget_x2many_2d_matrix.widget", function (require) {
/** /**
* Determine if a field represented by field_def can be aggregated * Determine if a field represented by field_def can be aggregated
*
* @param {Object} field_def: field def
* @returns {Boolean} if field def is aggregatable
*/ */
is_aggregatable: function (field_def) { is_aggregatable: function (field_def) {
return field_def.type in {float: 1, monetary: 1, integer: 1}; return field_def.type in {float: 1, monetary: 1, integer: 1};