From 018496a0790c1e5ec011d3bfefa6f4ccadf7883f Mon Sep 17 00:00:00 2001 From: David Date: Tue, 9 Jul 2024 11:40:59 +0200 Subject: [PATCH] [MIG] stock_vlm_mgmt: Migration to 16.0 TT48109 --- .../stock_vlm_mgmt/odoo/addons/stock_vlm_mgmt | 1 + setup/stock_vlm_mgmt/setup.py | 6 + stock_vlm_mgmt/README.rst | 11 +- stock_vlm_mgmt/__manifest__.py | 14 +- stock_vlm_mgmt/models/stock_location.py | 7 +- .../models/stock_location_vlm_tray.py | 18 +- .../models/stock_location_vlm_tray_type.py | 15 +- stock_vlm_mgmt/models/stock_quant.py | 4 +- .../models/vlm_tray_cell_position_mixin.py | 39 ++- stock_vlm_mgmt/readme/ROADMAP.rst | 1 - stock_vlm_mgmt/static/description/index.html | 7 +- .../stock_location_tray.esm.js | 62 ++++ .../stock_location_tray.scss | 24 ++ .../stock_location_tray_views.xml | 33 ++ .../static/src/js/stock_location_tray.js | 284 ------------------ .../vlm_request_views.esm.js | 30 ++ .../vlm_request_button/vlm_request_views.xml | 24 ++ .../src/js/vlm_task_tree_action_buttons.js | 48 --- .../static/src/scss/stock_vlm_mgmt.scss | 5 - .../vlm_task_tree_action_buttons_views.xml | 11 - stock_vlm_mgmt/views/assets.xml | 20 -- .../views/stock_location_vlm_tray_views.xml | 3 +- stock_vlm_mgmt/views/stock_quant_views.xml | 17 ++ stock_vlm_mgmt/views/stock_vlm_task_views.xml | 3 +- 24 files changed, 278 insertions(+), 409 deletions(-) create mode 120000 setup/stock_vlm_mgmt/odoo/addons/stock_vlm_mgmt create mode 100644 setup/stock_vlm_mgmt/setup.py create mode 100644 stock_vlm_mgmt/static/src/js/location_tray_matrix/stock_location_tray.esm.js create mode 100644 stock_vlm_mgmt/static/src/js/location_tray_matrix/stock_location_tray.scss create mode 100644 stock_vlm_mgmt/static/src/js/location_tray_matrix/stock_location_tray_views.xml delete mode 100644 stock_vlm_mgmt/static/src/js/stock_location_tray.js create mode 100644 stock_vlm_mgmt/static/src/js/vlm_request_button/vlm_request_views.esm.js create mode 100644 stock_vlm_mgmt/static/src/js/vlm_request_button/vlm_request_views.xml delete mode 100644 stock_vlm_mgmt/static/src/js/vlm_task_tree_action_buttons.js delete mode 100644 stock_vlm_mgmt/static/src/xml/vlm_task_tree_action_buttons_views.xml delete mode 100644 stock_vlm_mgmt/views/assets.xml diff --git a/setup/stock_vlm_mgmt/odoo/addons/stock_vlm_mgmt b/setup/stock_vlm_mgmt/odoo/addons/stock_vlm_mgmt new file mode 120000 index 000000000..9da14c6ef --- /dev/null +++ b/setup/stock_vlm_mgmt/odoo/addons/stock_vlm_mgmt @@ -0,0 +1 @@ +../../../../stock_vlm_mgmt \ No newline at end of file diff --git a/setup/stock_vlm_mgmt/setup.py b/setup/stock_vlm_mgmt/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/stock_vlm_mgmt/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_vlm_mgmt/README.rst b/stock_vlm_mgmt/README.rst index 0ecd66035..c31772ef7 100644 --- a/stock_vlm_mgmt/README.rst +++ b/stock_vlm_mgmt/README.rst @@ -17,13 +17,13 @@ Vertical Lift Module management :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--warehouse-lightgray.png?logo=github - :target: https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_vlm_mgmt + :target: https://github.com/OCA/stock-logistics-warehouse/tree/16.0/stock_vlm_mgmt :alt: OCA/stock-logistics-warehouse .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-14-0/stock-logistics-warehouse-14-0-stock_vlm_mgmt + :target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-16-0/stock-logistics-warehouse-16-0-stock_vlm_mgmt :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-warehouse&target_branch=14.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-warehouse&target_branch=16.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| @@ -57,7 +57,6 @@ Known issues / Roadmap the proper links. * Not a requiste right now, but we could need to support batch pickings. Let's deal with the basics for now anyway. -* Support inventories. Bug Tracker =========== @@ -65,7 +64,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. @@ -106,6 +105,6 @@ Current `maintainer `__: |maintainer-chienandalu| -This module is part of the `OCA/stock-logistics-warehouse `_ project on GitHub. +This module is part of the `OCA/stock-logistics-warehouse `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_vlm_mgmt/__manifest__.py b/stock_vlm_mgmt/__manifest__.py index c552ce316..b4ab9707f 100644 --- a/stock_vlm_mgmt/__manifest__.py +++ b/stock_vlm_mgmt/__manifest__.py @@ -3,16 +3,15 @@ { "name": "Vertical Lift Module management", "summary": "Light self contained alternative for VLM integrations", - "version": "14.0.1.0.0", + "version": "16.0.1.0.0", "author": "Tecnativa, Odoo Community Association (OCA)", "website": "https://github.com/OCA/stock-logistics-warehouse", "maintainers": ["chienandalu"], "license": "AGPL-3", "category": "Stock", - "depends": ["stock"], + "depends": ["stock", "base_sparse_field"], "data": [ "security/ir.model.access.csv", - "views/assets.xml", "views/stock_location_vlm_tray_views.xml", "views/stock_location_views.xml", "views/stock_picking_views.xml", @@ -22,7 +21,10 @@ "views/stock_location_tray_type_views.xml", "wizards/stock_vlm_task_action_views.xml", ], - "qweb": [ - "static/src/xml/vlm_task_tree_action_buttons_views.xml", - ], + "assets": { + "web.assets_backend": [ + "stock_vlm_mgmt/static/src/scss/stock_vlm_mgmt.scss", + "stock_vlm_mgmt/static/src/js/**/*", + ], + }, } diff --git a/stock_vlm_mgmt/models/stock_location.py b/stock_vlm_mgmt/models/stock_location.py index 9d1876786..8e7925e92 100644 --- a/stock_vlm_mgmt/models/stock_location.py +++ b/stock_vlm_mgmt/models/stock_location.py @@ -13,7 +13,12 @@ class StockLocation(models.Model): ("test", "Test"), ], ) - vlm_address = fields.Char() + vlm_address = fields.Char( + help=( + "An VLM normally will be behind some propietary proxy that handles several " + "VLMs at once, so we need to set which one corresponds to this location" + ) + ) vlm_hostname = fields.Char() vlm_port = fields.Char() vlm_removal_strategy = fields.Selection( diff --git a/stock_vlm_mgmt/models/stock_location_vlm_tray.py b/stock_vlm_mgmt/models/stock_location_vlm_tray.py index ff33a398b..418c68a0c 100644 --- a/stock_vlm_mgmt/models/stock_location_vlm_tray.py +++ b/stock_vlm_mgmt/models/stock_location_vlm_tray.py @@ -1,6 +1,7 @@ # Copyright 2023 Tecnativa - David Vidal # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import _, api, fields, models +from odoo.osv import expression class StockLocationVlmTray(models.Model): @@ -11,7 +12,9 @@ class StockLocationVlmTray(models.Model): location_id = fields.Many2one( comodel_name="stock.location", domain=[("is_vlm", "=", True)] ) - tray_type_id = fields.Many2one(comodel_name="stock.location.vlm.tray.type") + tray_type_id = fields.Many2one( + comodel_name="stock.location.vlm.tray.type", required=True + ) tray_matrix = fields.Serialized(compute="_compute_tray_matrix") is_full = fields.Boolean() @@ -29,7 +32,12 @@ class StockLocationVlmTray(models.Model): "first_empty_cell": [], } for position in cell_not_empty: - tray_matrix["cells"][position["pos_y"] - 1][position["pos_x"] - 1] = 1 + # Let's be gentle with positioning errors. + try: + tray_matrix["cells"][position["pos_y"]][position["pos_x"]] = 1 + # pylint: disable=except-pass + except IndexError: + pass for row, cells in enumerate(tray_matrix["cells"]): if 0 not in cells: continue @@ -41,8 +49,10 @@ class StockLocationVlmTray(models.Model): """See the vlm quants belonging to the tray""" self.ensure_one() domain = [("tray_id", "=", self.id)] - if pos_x and pos_y: - domain += [("pos_x", "=", pos_x), ("pos_y", "=", pos_y)] + if (pos_x is not None) and (pos_y is not None): + domain = expression.AND( + [domain, [("pos_x", "=", pos_x), ("pos_y", "=", pos_y)]] + ) vlm_quant = self.env["stock.quant.vlm"].search(domain) action = self.env["ir.actions.act_window"]._for_xml_id( "stock_vlm_mgmt.location_quant_vlm_action" diff --git a/stock_vlm_mgmt/models/stock_location_vlm_tray_type.py b/stock_vlm_mgmt/models/stock_location_vlm_tray_type.py index 6dcb76943..616a275a6 100644 --- a/stock_vlm_mgmt/models/stock_location_vlm_tray_type.py +++ b/stock_vlm_mgmt/models/stock_location_vlm_tray_type.py @@ -2,12 +2,12 @@ # Copyright 2024 Tecnativa - David Vidal # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models -from odoo.osv import expression class StockLocationVlmTrayType(models.Model): _name = "stock.location.vlm.tray.type" _description = "VLM Tray configuration" + _rec_names_search = ["name", "code"] active = fields.Boolean(default=True) name = fields.Char(required=True) @@ -49,18 +49,5 @@ class StockLocationVlmTrayType(models.Model): cells = self._generate_cells_matrix(default_state=1) record.tray_matrix = {"selected": [], "cells": cells} - @api.model - def _name_search( - self, name, args=None, operator="ilike", limit=100, name_get_uid=None - ): - args = args or [] - domain = [] - if name: - domain = ["|", ("name", operator, name), ("code", operator, name)] - - return self._search( - expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid - ) - def _generate_cells_matrix(self, default_state=0): return [[default_state] * self.cols for __ in range(self.rows)] diff --git a/stock_vlm_mgmt/models/stock_quant.py b/stock_vlm_mgmt/models/stock_quant.py index 2ea1044bd..30d81481c 100644 --- a/stock_vlm_mgmt/models/stock_quant.py +++ b/stock_vlm_mgmt/models/stock_quant.py @@ -77,6 +77,7 @@ class StockQuantVlm(models.Model): ) if quant: quant.inventory_quantity = quant_quantity + quant._apply_inventory() else: vlm_quant.quant_id = quant.create( { @@ -85,6 +86,7 @@ class StockQuantVlm(models.Model): "inventory_quantity": quant_quantity, } ) + vlm_quant.quant_id._apply_inventory() def write(self, vals): if self._is_inventory_mode() and "quantity" in vals: @@ -101,7 +103,7 @@ class StockQuantVlm(models.Model): return vlm_quant def unlink(self): - """We need to trigger the quantities update whenever this happens""" + # We need to trigger the quantities update whenever this happens for vlm_quant in self: vlm_quant.with_context(vlm_inventory_mode=True).quantity = 0 return super().unlink() diff --git a/stock_vlm_mgmt/models/vlm_tray_cell_position_mixin.py b/stock_vlm_mgmt/models/vlm_tray_cell_position_mixin.py index 2ad399c18..3fdce5fa3 100644 --- a/stock_vlm_mgmt/models/vlm_tray_cell_position_mixin.py +++ b/stock_vlm_mgmt/models/vlm_tray_cell_position_mixin.py @@ -11,8 +11,42 @@ class VlmTrayCellPositionMixin(models.AbstractModel): tray_id = fields.Many2one(comodel_name="stock.location.vlm.tray") tray_type_id = fields.Many2one(comodel_name="stock.location.vlm.tray.type") tray_matrix = fields.Serialized(compute="_compute_tray_matrix") - pos_x = fields.Integer() - pos_y = fields.Integer() + pos_x = fields.Integer(compute="_compute_pos", readonly=False, store=True) + pos_y = fields.Integer(compute="_compute_pos", readonly=False, store=True) + human_pos_x = fields.Integer( + string="X", + compute="_compute_human_pos_x", + inverse="_inverse_human_pos_x", + readonly=False, + ) + human_pos_y = fields.Integer( + string="Y", + compute="_compute_human_pos_y", + inverse="_inverse_human_pos_y", + readonly=False, + ) + + @api.depends("pos_x") + def _compute_human_pos_x(self): + for record in self: + record.human_pos_x = record.pos_x + 1 + + @api.depends("pos_y") + def _compute_human_pos_y(self): + for record in self: + record.human_pos_y = record.pos_y + 1 + + @api.depends("tray_matrix") + def _compute_pos(self): + for record in self: + if not record.tray_matrix["selected"]: + continue + record.update( + { + "pos_x": record.tray_matrix["selected"][0], + "pos_y": record.tray_matrix["selected"][1], + } + ) @api.depends("pos_x", "pos_y", "tray_type_id", "tray_id") def _compute_tray_matrix(self): @@ -30,6 +64,7 @@ class VlmTrayCellPositionMixin(models.AbstractModel): # Let's be gentle with positioning errors. try: tray_matrix["cells"][position["pos_y"]][position["pos_x"]] = 1 + # pylint: disable=except-pass except IndexError: pass for row, cells in enumerate(tray_matrix["cells"]): diff --git a/stock_vlm_mgmt/readme/ROADMAP.rst b/stock_vlm_mgmt/readme/ROADMAP.rst index a9d02326a..be62e684b 100644 --- a/stock_vlm_mgmt/readme/ROADMAP.rst +++ b/stock_vlm_mgmt/readme/ROADMAP.rst @@ -15,4 +15,3 @@ the proper links. * Not a requiste right now, but we could need to support batch pickings. Let's deal with the basics for now anyway. -* Support inventories. diff --git a/stock_vlm_mgmt/static/description/index.html b/stock_vlm_mgmt/static/description/index.html index 9c2eed41f..346d0ee5a 100644 --- a/stock_vlm_mgmt/static/description/index.html +++ b/stock_vlm_mgmt/static/description/index.html @@ -368,7 +368,7 @@ ul.auto-toc { !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! source digest: sha256:16cc58033099be982092f3cf06236fc4a8ab693fcfa4ff09ff5555062362ce43 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

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

+

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

This module adds basic a management system for Vertical Lift Modules. It’s thought as a simpler alternative attemp to stock_vertical_lift and all the dependencies that come with it.

@@ -405,7 +405,6 @@ pending assignation, so when we finally validate the picking we just have to per the proper links.
  • Not a requiste right now, but we could need to support batch pickings. Let’s deal with the basics for now anyway.
  • -
  • Support inventories.
  • @@ -413,7 +412,7 @@ with the basics for now anyway.

    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.

    @@ -443,7 +442,7 @@ mission is to support the collaborative development of Odoo features and promote its widespread use.

    Current maintainer:

    chienandalu

    -

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

    +

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

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

    diff --git a/stock_vlm_mgmt/static/src/js/location_tray_matrix/stock_location_tray.esm.js b/stock_vlm_mgmt/static/src/js/location_tray_matrix/stock_location_tray.esm.js new file mode 100644 index 000000000..089a477bc --- /dev/null +++ b/stock_vlm_mgmt/static/src/js/location_tray_matrix/stock_location_tray.esm.js @@ -0,0 +1,62 @@ +/** @odoo-module **/ +/* Copyright 2024 Tecnativa - David Vidal + License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).*/ +import {Component, useState} from "@odoo/owl"; + +import {_lt} from "@web/core/l10n/translation"; +import {registry} from "@web/core/registry"; +import {standardFieldProps} from "@web/views/fields/standard_field_props"; +import {useService} from "@web/core/utils/hooks"; + +export class LocationTrayMatrixField extends Component { + setup() { + this.state = useState(this.props.value); + this.orm = useService("orm"); + this.action = useService("action"); + } + /** + * + * @param {Event} event + * @returns {Object} Odoo action + */ + async onClickCell(event) { + const coordinates = event.currentTarget.dataset.coordinates + .split(",") + .map((x) => { + return parseInt(x, 10); + }); + if (this.props.click_action) { + const action = this.orm.call( + this.props.record.resModel, + this.props.click_action, + [[this.props.record.data.id]], + {pos_x: coordinates[0], pos_y: coordinates[1]} + ); + return this.action.doAction(action); + } + // This is for responsiveness + this.state.selected = coordinates; + // And here we propagate the changes to the field + this.props.value.selected = coordinates; + this.props.update(this.props.value); + } +} + +LocationTrayMatrixField.template = "stock_vlm_mgmt.location_tray_matrix"; +LocationTrayMatrixField.props = { + ...standardFieldProps, + click_action: { + type: String, + optional: true, + }, +}; +LocationTrayMatrixField.extractProps = ({attrs}) => { + if ("click_action" in attrs.options) { + return {click_action: attrs.options.click_action}; + } +}; + +LocationTrayMatrixField.displayName = _lt("Tray storage layout"); +LocationTrayMatrixField.supportedTypes = ["serialized"]; + +registry.category("fields").add("location_tray_matrix", LocationTrayMatrixField); diff --git a/stock_vlm_mgmt/static/src/js/location_tray_matrix/stock_location_tray.scss b/stock_vlm_mgmt/static/src/js/location_tray_matrix/stock_location_tray.scss new file mode 100644 index 000000000..7ddd0dd15 --- /dev/null +++ b/stock_vlm_mgmt/static/src/js/location_tray_matrix/stock_location_tray.scss @@ -0,0 +1,24 @@ +// Widget in form view +.o_field_location_tray_matrix { + table { + height: 200px; + tr { + td { + min-width: 250px; + } + } + } +} +// Widget in list view +.o_location_tray_matrix_cell { + .o_field_location_tray_matrix { + table { + height: 70px; + tr { + td { + min-width: 25px; + } + } + } + } +} diff --git a/stock_vlm_mgmt/static/src/js/location_tray_matrix/stock_location_tray_views.xml b/stock_vlm_mgmt/static/src/js/location_tray_matrix/stock_location_tray_views.xml new file mode 100644 index 000000000..4498fed80 --- /dev/null +++ b/stock_vlm_mgmt/static/src/js/location_tray_matrix/stock_location_tray_views.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + +
    ·
    +
    +
    diff --git a/stock_vlm_mgmt/static/src/js/stock_location_tray.js b/stock_vlm_mgmt/static/src/js/stock_location_tray.js deleted file mode 100644 index 05de24521..000000000 --- a/stock_vlm_mgmt/static/src/js/stock_location_tray.js +++ /dev/null @@ -1,284 +0,0 @@ -/* Copyright 2019 Camptocamp SA - Copyright 2024 Tecnativa - David Vidal - License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).*/ -odoo.define("stock_location_tray.tray", function (require) { - "use strict"; - - var basicFields = require("web.basic_fields"); - var field_registry = require("web.field_registry"); - var DebouncedField = basicFields.DebouncedField; - - /** - * Shows a canvas with the Tray's cells - * - * An action can be configured which is called when a cell is clicked. - * The action must be an action.multi, it will receive the x and y positions - * of the cell clicked (starting from 0). The action must be configured in - * the options of the field and be on the same model: - * - * - * - */ - var LocationTrayMatrixField = DebouncedField.extend({ - className: "o_field_location_tray_matrix", - tagName: "canvas", - supportedFieldTypes: ["serialized"], - events: { - click: "_onClick", - }, - - cellColorEmpty: "#ffffff", - cellColorNotEmpty: "#00A09D", - selectedColor: "#ffc107", - selectedLineWidth: 5, - globalAlpha: 0.8, - cellPadding: 2, - - init: function (parent, name, record, options) { - this._super.apply(this, arguments); - this.nodeOptions = _.defaults(this.nodeOptions, {}); - if ("clickAction" in (options || {})) { - this.clickAction = options.clickAction; - } else { - this.clickAction = this.nodeOptions.click_action; - } - this.liveCellEdit = - !this.clickAction && - this.nodeOptions.live_cell_edit && - this.getParent().mode === "edit"; - }, - - isSet: function () { - if (Object.keys(this.value).length === 0) { - return false; - } - if (this.value.cells.length === 0) { - return false; - } - return this._super.apply(this, arguments); - }, - - start: function () { - // Setup resize events to redraw the canvas - this._resizeDebounce = this._resizeDebounce.bind(this); - this._resizePromise = null; - $(window).on("resize", this._resizeDebounce); - return this._super.apply(this, arguments).then(() => { - if (this.clickAction || this.liveCellEdit) { - this.$el.css("cursor", "pointer"); - } - // _super calls _render(), but the function - // resizeCanvasToDisplaySize would resize the canvas - // to 0 because the actual canvas would still be unknown. - // Call again _render() here but through a setTimeout to - // let the js renderer thread catch up. - this._ready = true; - return this._resizeDebounce(); - }); - }, - - _onClick: function (ev) { - ev.preventDefault(); - if (!this.isSet()) { - return; - } - if (!this.clickAction && !this.liveCellEdit) { - return; - } - var width = this.canvas.width, - height = this.canvas.height, - rect = this.canvas.getBoundingClientRect(); - - var clickX = ev.clientX - rect.left, - clickY = ev.clientY - rect.top; - - var cells = this.value.cells, - cols = cells[0].length, - rows = cells.length; - - // We remove 1 to start counting from 0 - var coordX = Math.ceil((clickX * cols) / width) - 1, - coordY = Math.ceil((clickY * rows) / height) - 1; - // If we click on the last pixel on the bottom or the right - // we would get an offset index - if (coordX >= cols) { - coordX = cols - 1; - } - if (coordY >= rows) { - coordY = rows - 1; - } - // The coordinate we get when we click is from top, - // but we are looking for the coordinate from the bottom - // to match the user's expectations, invert Y - coordY = Math.abs(coordY - rows + 1); - // Allow to edit the position on the tray - if (this.liveCellEdit) { - this.value.selected = [coordX, coordY]; - this.trigger_up("field_changed", { - dataPointID: this.dataPointID, - changes: { - pos_x: coordX, - pos_y: coordY, - }, - }); - this._render(); - } - // Perform an action over the cell when it has contents - if (this.clickAction && this.value.cells[coordY][coordX] === 1) { - ev.stopPropagation(); - this.trigger_up("button_clicked", { - attrs: { - type: "object", - name: this.clickAction, - args: `[${coordX}, ${coordY}]`, - }, - record: this.record, - }); - } - }, - - /** - * Debounce the rendering on resize. - * It is useless to render on each resize event. - * - */ - _resizeDebounce: function () { - clearTimeout(this._resizePromise); - this._resizePromise = setTimeout(() => { - this._render(); - }, 20); - }, - - destroy: function () { - $(window).off("resize", this._resizeDebounce); - this._super.apply(this, arguments); - }, - - /** - * Render the widget only when it is in the DOM. - * We need the width and height of the widget to draw the canvas. - * - * @returns {Promise} - */ - _render: function () { - if (this._ready) { - return this._renderInDOM(); - } - return $.when(); - }, - - /** - * Resize the canvas width and height to the actual size. - * If we don't do that, it will automatically scale to the - * CSS size with blurry squares. - * - * @param {jQueryElement} canvas - the DOM canvas to draw - * @returns {Boolean} - */ - resizeCanvasToDisplaySize: function (canvas) { - // Look up the size the canvas is being displayed - var width = canvas.clientWidth; - var height = canvas.clientHeight; - - // If it's resolution does not match change it - if (canvas.width !== width || canvas.height !== height) { - canvas.width = width; - canvas.height = height; - return true; - } - return false; - }, - - /** - * Resize the canvas, clear it and redraw the cells - * Should be called only if the canvas is already in DOM - * - */ - _renderInDOM: function () { - this.canvas = this.$el[0]; - var canvas = this.canvas; - var ctx = canvas.getContext("2d"); - this.resizeCanvasToDisplaySize(ctx.canvas); - ctx.clearRect(0, 0, canvas.width, canvas.height); - ctx.save(); - if (this.isSet()) { - var selected = this.value.selected || []; - var cells = this.value.cells; - this._drawMatrix(canvas, ctx, cells, selected); - } - }, - - /** - * Draw the cells in the canvas. - * - * @param {jQueryElement} canvas - the DOM canvas to draw - * @param {Object} ctx - the canvas 2d context - * @param {List} cells - A 2-dimensional list of cells - * @param {List} selected - A list containing the position (x,y) of the - * selected cell (can be empty if no cell is selected) - */ - _drawMatrix: function (canvas, ctx, cells, selected) { - var colors = { - 0: this.cellColorEmpty, - 1: this.cellColorNotEmpty, - }; - var cols = cells[0].length; - var rows = cells.length; - var selectedX = null, - selectedY = null; - if (selected.length) { - selectedX = selected[0]; - // We draw top to bottom, but the highlighted cell should - // be a coordinate from bottom to top: reverse the y axis - selectedY = Math.abs(selected[1] - rows + 1); - } - var padding = this.cellPadding; - var padding_width = padding * cols; - var padding_height = padding * rows; - var w = (canvas.width - padding_width) / cols; - var h = (canvas.height - padding_height) / rows; - ctx.globalAlpha = this.globalAlpha; - // Again, our matrix is top to bottom (0 is the first line) - // but visually, we want them bottom to top - var reversed_cells = cells.slice().reverse(); - for (var y = 0; y < rows; y++) { - for (var x = 0; x < cols; x++) { - ctx.fillStyle = colors[reversed_cells[y][x]]; - var fillWidth = w; - var fillHeight = h; - // Cheat: remove the padding at bottom and right - // the cells will be a bit larger but not really noticeable - if (x === cols - 1) { - fillWidth += padding; - } - if (y === rows - 1) { - fillHeight += padding; - } - ctx.fillRect( - x * (w + padding), - y * (h + padding), - fillWidth, - fillHeight - ); - if (selected && selectedX === x && selectedY === y) { - ctx.globalAlpha = 1.0; - ctx.strokeStyle = this.selectedColor; - ctx.lineWidth = this.selectedLineWidth; - ctx.strokeRect(x * (w + padding), y * (h + padding), w, h); - ctx.globalAlpha = this.globalAlpha; - } - } - } - ctx.restore(); - }, - }); - - field_registry.add("location_tray_matrix", LocationTrayMatrixField); - - return { - LocationTrayMatrixField: LocationTrayMatrixField, - }; -}); diff --git a/stock_vlm_mgmt/static/src/js/vlm_request_button/vlm_request_views.esm.js b/stock_vlm_mgmt/static/src/js/vlm_request_button/vlm_request_views.esm.js new file mode 100644 index 000000000..0aff4a857 --- /dev/null +++ b/stock_vlm_mgmt/static/src/js/vlm_request_button/vlm_request_views.esm.js @@ -0,0 +1,30 @@ +/** @odoo-module **/ + +import {ListController} from "@web/views/list/list_controller"; +import {listView} from "@web/views/list/list_view"; +import {registry} from "@web/core/registry"; +import {useService} from "@web/core/utils/hooks"; + +export class VlmRequestListController extends ListController { + setup() { + super.setup(); + this.orm = useService("orm"); + this.action = useService("action"); + } + async onClickVlmRequest() { + const resIds = this.model.root.selection.map((record) => record.resId); + const action = await this.orm.call( + "stock.vlm.task", + "action_do_tasks", + [resIds], + {} + ); + this.action.doAction(action); + } +} + +registry.category("views").add("stock_vlm_task_action_tree", { + ...listView, + Controller: VlmRequestListController, + buttonTemplate: "VlmTaskRequestListView.buttons", +}); diff --git a/stock_vlm_mgmt/static/src/js/vlm_request_button/vlm_request_views.xml b/stock_vlm_mgmt/static/src/js/vlm_request_button/vlm_request_views.xml new file mode 100644 index 000000000..ee3781a64 --- /dev/null +++ b/stock_vlm_mgmt/static/src/js/vlm_request_button/vlm_request_views.xml @@ -0,0 +1,24 @@ + + + + + + + + diff --git a/stock_vlm_mgmt/static/src/js/vlm_task_tree_action_buttons.js b/stock_vlm_mgmt/static/src/js/vlm_task_tree_action_buttons.js deleted file mode 100644 index 6f42ddd7d..000000000 --- a/stock_vlm_mgmt/static/src/js/vlm_task_tree_action_buttons.js +++ /dev/null @@ -1,48 +0,0 @@ -odoo.define("crm.leads.tree", function (require) { - "use strict"; - const ListController = require("web.ListController"); - const ListView = require("web.ListView"); - const viewRegistry = require("web.view_registry"); - const core = require("web.core"); - const qweb = core.qweb; - - function renderVlmTasksActionButton() { - if (this.$buttons) { - this.$buttons.on("click", ".o_button_perform_vlm_tasks", async () => { - const resIds = await this.getSelectedIdsWithDomain(); - this._rpc({ - model: "stock.vlm.task", - method: "action_do_tasks", - args: [resIds], - }).then((action) => { - this.do_action(action); - }); - }); - } - } - - var VlmTaskRequestListController = ListController.extend({ - _updateSelectionBox: function () { - this._super.apply(this, arguments); - if (this.$performTasksButtons) { - this.$performTasksButtons.remove(); - this.$performTasksButtons = null; - } - this.$performTasksButtons = $( - qweb.render("VlmTaskAction.perform_vlm_tasks_button") - ); - if (this.$selectionBox) { - this.$performTasksButtons.insertAfter(this.$selectionBox); - renderVlmTasksActionButton.apply(this, arguments); - } - }, - }); - - var VlmTaskRequestListView = ListView.extend({ - config: _.extend({}, ListView.prototype.config, { - Controller: VlmTaskRequestListController, - }), - }); - - viewRegistry.add("stock_vlm_task_action_tree", VlmTaskRequestListView); -}); diff --git a/stock_vlm_mgmt/static/src/scss/stock_vlm_mgmt.scss b/stock_vlm_mgmt/static/src/scss/stock_vlm_mgmt.scss index 44af648c4..8455272e2 100644 --- a/stock_vlm_mgmt/static/src/scss/stock_vlm_mgmt.scss +++ b/stock_vlm_mgmt/static/src/scss/stock_vlm_mgmt.scss @@ -1,8 +1,3 @@ -// VLM tray matrix default colors -.o_field_location_tray_matrix { - background-color: $o-brand-lightsecondary; - border: 2px $o-main-color-muted solid; -} // Product image hint in the wizard .o_form_view { .vlm_task_image { diff --git a/stock_vlm_mgmt/static/src/xml/vlm_task_tree_action_buttons_views.xml b/stock_vlm_mgmt/static/src/xml/vlm_task_tree_action_buttons_views.xml deleted file mode 100644 index 8e532582c..000000000 --- a/stock_vlm_mgmt/static/src/xml/vlm_task_tree_action_buttons_views.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - diff --git a/stock_vlm_mgmt/views/assets.xml b/stock_vlm_mgmt/views/assets.xml deleted file mode 100644 index 95a563521..000000000 --- a/stock_vlm_mgmt/views/assets.xml +++ /dev/null @@ -1,20 +0,0 @@ - - -