From 5afdd8a09759fcc5f54fd516bd2e4f06587a2323 Mon Sep 17 00:00:00 2001 From: Francois Poizat Date: Wed, 28 Feb 2024 16:04:19 +0100 Subject: [PATCH] [MIG] stock_barcodes: Migration to 16.0 --- stock_barcodes/README.rst | 12 +- stock_barcodes/__manifest__.py | 21 +- .../migrations/15.0.1.0.0/pre-migration.py | 14 - .../models/stock_barcodes_read_log.py | 2 +- stock_barcodes/models/stock_move_line.py | 4 +- stock_barcodes/static/description/index.html | 8 +- .../static/src/barcodes_models_utils.esm.js | 19 + .../static/src/boolean_toggle.esm.js | 17 + stock_barcodes/static/src/form_view.esm.js | 15 + .../static/src/js/barcodes_models_mixin.js | 34 -- .../static/src/js/basic_controller.js | 402 --------------- stock_barcodes/static/src/js/basic_fields.js | 59 --- stock_barcodes/static/src/js/form_view.js | 24 - .../static/src/js/kanban_renderer.js | 45 -- stock_barcodes/static/src/js/numeric_step.js | 43 -- .../static/src/kanban_renderer.esm.js | 163 ++++++ stock_barcodes/static/src/numeric_step.esm.js | 80 +++ stock_barcodes/static/src/numeric_step.xml | 17 + stock_barcodes/static/src/{css => }/stock.css | 0 .../static/src/{css => }/stock.scss | 7 + stock_barcodes/static/src/view_button.esm.js | 8 + stock_barcodes/static/src/view_button.xml | 14 + .../static/src/view_compiler.esm.js | 16 + stock_barcodes/static/src/views.esm.js | 178 +++++++ stock_barcodes/tests/common.py | 165 +++++++ stock_barcodes/tests/test_stock_barcodes.py | 173 +------ .../tests/test_stock_barcodes_new_lot.py | 4 +- .../tests/test_stock_barcodes_picking.py | 16 +- stock_barcodes/views/stock_picking_views.xml | 1 - stock_barcodes/wizard/stock_barcodes_read.py | 29 +- .../stock_barcodes_read_inventory_views.xml | 20 +- .../wizard/stock_barcodes_read_picking.py | 20 +- .../stock_barcodes_read_picking_views.xml | 218 ++++----- .../wizard/stock_barcodes_read_todo.py | 18 +- .../wizard/stock_barcodes_read_todo_view.xml | 21 +- .../wizard/stock_barcodes_read_views.xml | 463 +++++++++--------- stock_barcodes/wizard/stock_production_lot.py | 4 +- 37 files changed, 1125 insertions(+), 1229 deletions(-) delete mode 100644 stock_barcodes/migrations/15.0.1.0.0/pre-migration.py create mode 100644 stock_barcodes/static/src/barcodes_models_utils.esm.js create mode 100644 stock_barcodes/static/src/boolean_toggle.esm.js create mode 100644 stock_barcodes/static/src/form_view.esm.js delete mode 100644 stock_barcodes/static/src/js/barcodes_models_mixin.js delete mode 100644 stock_barcodes/static/src/js/basic_controller.js delete mode 100644 stock_barcodes/static/src/js/basic_fields.js delete mode 100644 stock_barcodes/static/src/js/form_view.js delete mode 100644 stock_barcodes/static/src/js/kanban_renderer.js delete mode 100644 stock_barcodes/static/src/js/numeric_step.js create mode 100644 stock_barcodes/static/src/kanban_renderer.esm.js create mode 100644 stock_barcodes/static/src/numeric_step.esm.js create mode 100644 stock_barcodes/static/src/numeric_step.xml rename stock_barcodes/static/src/{css => }/stock.css (100%) rename stock_barcodes/static/src/{css => }/stock.scss (90%) create mode 100644 stock_barcodes/static/src/view_button.esm.js create mode 100644 stock_barcodes/static/src/view_button.xml create mode 100644 stock_barcodes/static/src/view_compiler.esm.js create mode 100644 stock_barcodes/static/src/views.esm.js create mode 100644 stock_barcodes/tests/common.py diff --git a/stock_barcodes/README.rst b/stock_barcodes/README.rst index 30ff3959b7f1..b0039fe43677 100644 --- a/stock_barcodes/README.rst +++ b/stock_barcodes/README.rst @@ -7,7 +7,7 @@ Stock Barcodes !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:525a93165bdee89662d7cde6315ac154e43ad2bb1db6fd2b6c4f72847a16ac6d + !! source digest: sha256:cc8a4769a4d49396466d2fe0d4ee151e77ecf646a27d11a3700c9bb5c1855b1f !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png @@ -17,13 +17,13 @@ Stock Barcodes :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--barcode-lightgray.png?logo=github - :target: https://github.com/OCA/stock-logistics-barcode/tree/15.0/stock_barcodes + :target: https://github.com/OCA/stock-logistics-barcode/tree/16.0/stock_barcodes :alt: OCA/stock-logistics-barcode .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/stock-logistics-barcode-15-0/stock-logistics-barcode-15-0-stock_barcodes + :target: https://translation.odoo-community.org/projects/stock-logistics-barcode-16-0/stock-logistics-barcode-16-0-stock_barcodes :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/stock-logistics-barcode&target_branch=15.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-barcode&target_branch=16.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| @@ -159,7 +159,7 @@ 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -209,6 +209,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/stock-logistics-barcode `_ project on GitHub. +This module is part of the `OCA/stock-logistics-barcode `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_barcodes/__manifest__.py b/stock_barcodes/__manifest__.py index 2101ea3f26a9..0002d26d8f8c 100644 --- a/stock_barcodes/__manifest__.py +++ b/stock_barcodes/__manifest__.py @@ -3,12 +3,12 @@ { "name": "Stock Barcodes", "summary": "It provides read barcode on stock operations.", - "version": "15.0.2.0.0", + "version": "16.0.1.0.0", "author": "Tecnativa, " "Odoo Community Association (OCA)", "website": "https://github.com/OCA/stock-logistics-barcode", "license": "AGPL-3", "category": "Extra Tools", - "depends": ["barcodes", "stock", "web_widget_numeric_step"], + "depends": ["barcodes", "stock", "web_widget_numeric_step", "web"], "data": [ "security/ir.model.access.csv", "views/stock_barcodes_action_view.xml", @@ -27,13 +27,16 @@ ], "assets": { "web.assets_backend": [ - "/stock_barcodes/static/src/js/barcodes_models_mixin.js", - "/stock_barcodes/static/src/js/basic_controller.js", - "/stock_barcodes/static/src/js/kanban_renderer.js", - "/stock_barcodes/static/src/js/basic_fields.js", - "/stock_barcodes/static/src/js/form_view.js", - "/stock_barcodes/static/src/js/numeric_step.js", - "/stock_barcodes/static/src/css/stock.scss", + "/stock_barcodes/static/src/barcodes_models_utils.esm.js", + "/stock_barcodes/static/src/kanban_renderer.esm.js", + "/stock_barcodes/static/src/boolean_toggle.esm.js", + "/stock_barcodes/static/src/views.esm.js", + "/stock_barcodes/static/src/form_view.esm.js", + "/stock_barcodes/static/src/numeric_step.esm.js", + "/stock_barcodes/static/src/view_button.esm.js", + "/stock_barcodes/static/src/view_compiler.esm.js", + "/stock_barcodes/static/src/view_button.xml", + "/stock_barcodes/static/src/stock.scss", ], }, "installable": True, diff --git a/stock_barcodes/migrations/15.0.1.0.0/pre-migration.py b/stock_barcodes/migrations/15.0.1.0.0/pre-migration.py deleted file mode 100644 index 8df703cba910..000000000000 --- a/stock_barcodes/migrations/15.0.1.0.0/pre-migration.py +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright 2023 ForgeFlow -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -from openupgradelib import openupgrade - - -def delete_fk_constraints(env): - # delete obsolete model references - openupgrade.remove_tables_fks(env.cr, ["wiz_stock_barcodes_read_inventory"]) - - -@openupgrade.migrate() -def migrate(env, version): - delete_fk_constraints(env) diff --git a/stock_barcodes/models/stock_barcodes_read_log.py b/stock_barcodes/models/stock_barcodes_read_log.py index fd536e288a88..448ec58c4c22 100644 --- a/stock_barcodes/models/stock_barcodes_read_log.py +++ b/stock_barcodes/models/stock_barcodes_read_log.py @@ -12,7 +12,7 @@ class StockBarcodesReadLog(models.Model): res_model_id = fields.Many2one(comodel_name="ir.model", index=True) res_id = fields.Integer(index=True) product_id = fields.Many2one(comodel_name="product.product", index=True) - lot_id = fields.Many2one(comodel_name="stock.production.lot", string="Lot scanned") + lot_id = fields.Many2one(comodel_name="stock.lot", string="Lot scanned") location_id = fields.Many2one(comodel_name="stock.location") packaging_id = fields.Many2one(comodel_name="product.packaging") packaging_qty = fields.Float(string="Package Qty", digits="Product Unit of Measure") diff --git a/stock_barcodes/models/stock_move_line.py b/stock_barcodes/models/stock_move_line.py index 0b4d553ae686..c2f887b66ca4 100644 --- a/stock_barcodes/models/stock_move_line.py +++ b/stock_barcodes/models/stock_move_line.py @@ -15,10 +15,10 @@ class StockMoveLine(models.Model): store=True, ) - @api.depends("qty_done", "product_uom_qty") + @api.depends("qty_done", "reserved_uom_qty") def _compute_barcode_scan_state(self): for line in self: - if line.qty_done >= line.product_uom_qty: + if line.qty_done >= line.reserved_uom_qty: line.barcode_scan_state = "done" else: line.barcode_scan_state = "pending" diff --git a/stock_barcodes/static/description/index.html b/stock_barcodes/static/description/index.html index 9e72786dce66..56380bc3a4c2 100644 --- a/stock_barcodes/static/description/index.html +++ b/stock_barcodes/static/description/index.html @@ -367,9 +367,9 @@

Stock Barcodes

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:525a93165bdee89662d7cde6315ac154e43ad2bb1db6fd2b6c4f72847a16ac6d +!! source digest: sha256:cc8a4769a4d49396466d2fe0d4ee151e77ecf646a27d11a3700c9bb5c1855b1f !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 OCA/stock-logistics-barcode Translate me on Weblate Try me on Runboat

+

Beta License: AGPL-3 OCA/stock-logistics-barcode Translate me on Weblate Try me on Runboat

This module provides a barcode reader interface for stock module.

This module contains a base wizard read barcode that can be extended by other modules.

@@ -518,7 +518,7 @@

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.

+feedback.

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

@@ -561,7 +561,7 @@

Maintainers

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/stock-logistics-barcode project on GitHub.

+

This module is part of the OCA/stock-logistics-barcode project on GitHub.

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

diff --git a/stock_barcodes/static/src/barcodes_models_utils.esm.js b/stock_barcodes/static/src/barcodes_models_utils.esm.js new file mode 100644 index 000000000000..1bdc048ba349 --- /dev/null +++ b/stock_barcodes/static/src/barcodes_models_utils.esm.js @@ -0,0 +1,19 @@ +/** @odoo-module */ +/* Copyright 2022 Tecnativa - Alexandre D. Díaz + * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ + +const barcodeModels = [ + "stock.barcodes.action", + "stock.picking", + "stock.picking.type", + "wiz.candidate.picking", + "wiz.stock.barcodes.new.lot", + "wiz.stock.barcodes.read", + "wiz.stock.barcodes.read.inventory", + "wiz.stock.barcodes.read.picking", + "wiz.stock.barcodes.read.todo", +]; + +export function isAllowedBarcodeModel(modelName) { + return barcodeModels.indexOf(modelName) !== -1; +} diff --git a/stock_barcodes/static/src/boolean_toggle.esm.js b/stock_barcodes/static/src/boolean_toggle.esm.js new file mode 100644 index 000000000000..f8e063abab81 --- /dev/null +++ b/stock_barcodes/static/src/boolean_toggle.esm.js @@ -0,0 +1,17 @@ +/** @odoo-module */ +/* Copyright 2018-2019 Sergio Teruel . + * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ + +import {BooleanToggleField} from "@web/views/fields/boolean_toggle/boolean_toggle_field"; +import {registry} from "@web/core/registry"; + +class BarcodeBooleanToggleField extends BooleanToggleField { + onChange(newValue) { + super.onChange(newValue); + requestIdleCallback(() => { + document.activeElement.blur(); + }); + } +} + +registry.category("fields").add("barcode_boolean_toggle", BarcodeBooleanToggleField); diff --git a/stock_barcodes/static/src/form_view.esm.js b/stock_barcodes/static/src/form_view.esm.js new file mode 100644 index 000000000000..fd0584082b52 --- /dev/null +++ b/stock_barcodes/static/src/form_view.esm.js @@ -0,0 +1,15 @@ +/** @odoo-module */ +/* Copyright 2021 Tecnativa - Alexandre D. Díaz + * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ + +import {FormController} from "@web/views/form/form_controller"; +import {patch} from "@web/core/utils/patch"; + +patch(FormController.prototype, "Allow display.controlPanel overriding", { + setup() { + this._super(...arguments); + if (this.props.context.control_panel_hidden) { + this.display.controlPanel = false; + } + }, +}); diff --git a/stock_barcodes/static/src/js/barcodes_models_mixin.js b/stock_barcodes/static/src/js/barcodes_models_mixin.js deleted file mode 100644 index 310cdb612f97..000000000000 --- a/stock_barcodes/static/src/js/barcodes_models_mixin.js +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright 2022 Tecnativa - Alexandre D. Díaz - * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ - -// eslint-disable-next-line no-unused-vars -odoo.define("stock_barcodes.BarcodesModelsMixin", function (require) { - "use strict"; - - const BarcodesModelsMixin = { - // Models allowed to have extra keybinding features - _barcode_models: [ - "stock.barcodes.action", - "stock.picking", - "stock.picking.type", - "wiz.candidate.picking", - "wiz.stock.barcodes.new.lot", - "wiz.stock.barcodes.read", - "wiz.stock.barcodes.read.inventory", - "wiz.stock.barcodes.read.picking", - "wiz.stock.barcodes.read.todo", - ], - - /** - * Helper to know if the given model is allowed - * - * @private - * @returns {Boolean} - */ - _isAllowedBarcodeModel: function (model_name) { - return this._barcode_models.indexOf(model_name) !== -1; - }, - }; - - return BarcodesModelsMixin; -}); diff --git a/stock_barcodes/static/src/js/basic_controller.js b/stock_barcodes/static/src/js/basic_controller.js deleted file mode 100644 index df9c4324ce6c..000000000000 --- a/stock_barcodes/static/src/js/basic_controller.js +++ /dev/null @@ -1,402 +0,0 @@ -/* Copyright 2018-2019 Sergio Teruel . - * Copyright 2022 Tecnativa - Alexandre D. Díaz - * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ - -odoo.define("stock_barcodes.BasicController", function (require) { - "use strict"; - - const BasicController = require("web.BasicController"); - const BrowserDetection = require("web.BrowserDetection"); - const BarcodesModelsMixin = require("stock_barcodes.BarcodesModelsMixin"); - const ui = require("@web/core/utils/ui"); - const getVisibleElements = ui.getVisibleElements; - - BasicController.include(BarcodesModelsMixin); - BasicController.include({ - /** - * @override - */ - init: function () { - this._super.apply(this, arguments); - this._is_valid_barcode_model = this._isAllowedBarcodeModel( - this.initialState.model - ); - if (this._is_valid_barcode_model) { - this.BrowserDetection = new BrowserDetection(); - this._keybind_selectable_index = -1; - this._keybind_selectable_items = []; - this._is_browser_chrome = this.BrowserDetection.isBrowserChrome(); - const state_id = this.initialState.data.id; - this._areAccessKeyVisible = false; - if (state_id) { - this._channel_barcode = `stock_barcodes-${this.initialState.data.id}`; - - if (this.call("bus_service", "isMasterTab")) { - this.call("bus_service", "addChannel", this._channel_barcode); - } - } - } - }, - - /** - * @override - */ - destroy: function () { - this._super.apply(this, arguments); - if (this._is_valid_barcode_model) { - if (this.$sound_ok) { - this.$sound_ok.remove(); - } - if (this.$sound_ko) { - this.$sound_ko.remove(); - } - } - }, - - /** - * @override - */ - on_detach_callback: function () { - this._super.apply(this, arguments); - if ( - this._is_valid_barcode_model && - ["form", "kanban"].indexOf(this.initialState.viewType) !== -1 - ) { - $(document).off("keydown", this._onDocumentKeyDown); - $(document).off("keyup", this._onDocumentKeyUp); - this.call( - "bus_service", - "off", - "notification", - this, - this.onBusNotificationBarcode - ); - } - }, - - /** - * @override - */ - on_attach_callback: function () { - this._super.apply(this, arguments); - if ( - this._is_valid_barcode_model && - ["form", "kanban"].indexOf(this.initialState.viewType) !== -1 - ) { - this._appendBarcodesSounds(); - $(document).on("keydown", {controller: this}, this._onDocumentKeyDown); - $(document).on("keyup", {controller: this}, this._onDocumentKeyUp); - this.call( - "bus_service", - "on", - "notification", - this, - this.onBusNotificationBarcode - ); - this._update_selectable_items(); - } - }, - - /** - * Longpolling messages - * - * @param {Array} notifications - */ - onBusNotificationBarcode: function (notifications) { - for (const notif of notifications) { - const notif_type = notif.type; - const message = notif.payload; - if (notif_type === "stock_barcodes_read-" + this.initialState.data.id) { - if (message.action === "focus") { - setTimeout(() => { - this.$(`[name=${message.field_name}] input`).select(); - }, 400); - } - } else if ( - notif_type === - "stock_barcodes_sound-" + this.initialState.data.id - ) { - if (message.sound === "ok") { - this.$sound_ok[0].play(); - } else if (message.sound === "ko") { - this.$sound_ko[0].play(); - } - } - } - }, - - _addHotkeyOverlays: function () { - if (this._areAccessKeyVisible) { - return; - } - for (const el of getVisibleElements( - document, - "[data-hotkey]:not(:disabled)" - )) { - const hotkey = el.dataset.hotkey; - const overlay = document.createElement("div"); - overlay.className = "o_web_hotkey_overlay"; - overlay.appendChild(document.createTextNode(hotkey.toUpperCase())); - - let overlayParent = false; - if (el.tagName.toUpperCase() === "INPUT") { - // Special case for the search input that has an access key - // defined. We cannot set the overlay on the input itself, - // only on its parent. - overlayParent = el.parentElement; - } else { - overlayParent = el; - } - - if (overlayParent.style.position !== "absolute") { - overlayParent.style.position = "relative"; - } - overlayParent.appendChild(overlay); - } - this._areAccessKeyVisible = true; - }, - - _removeHotkeyOverlays: function () { - if (!this._areAccessKeyVisible) { - return; - } - for (const overlay of document.querySelectorAll(".o_web_hotkey_overlay")) { - overlay.remove(); - } - this._areAccessKeyVisible = false; - }, - /** - * Helper to toggle access keys panel visibility - * - * @param {Boolean} status - */ - _toggleAccessKeys: function (status) { - if (status) { - this._addHotkeyOverlays(); - } else { - this._removeHotkeyOverlays(); - } - }, - - /** - * Used to manipulate fields - * - * @private - */ - _postProcessFields: function () { - // Set tabindex for readonly elements - // this is necessary to don't block the elements chain - const $fields = $("span.o_readonly_modifier"); - $fields.attr("tabindex", "-1"); - }, - - /** - * Append the audio elements to play the sounds. - * This is here because only must exists one controller at time - * - * @private - */ - _appendBarcodesSounds: function () { - this.$sound_ok = $("