diff --git a/pos_default_quantity/README.rst b/pos_default_quantity/README.rst index 8b96f7b9d9..c4c2f28bba 100644 --- a/pos_default_quantity/README.rst +++ b/pos_default_quantity/README.rst @@ -30,7 +30,7 @@ Set Default Product Quantity in POS This module adds a field for a default quantity to Unit of Measure Categories. When this is filled in, and when this functionality is enabled in the Point of -Sale Configuration, then adding that product to an order in the Point of Sale +Sale configuration, then adding that product to an order in the Point of Sale will set the quantity to that value by default. **Table of contents** @@ -38,6 +38,18 @@ will set the quantity to that value by default. .. contents:: :local: +Usage +===== + +In order to set this up, you need to do a few things: + +- Make sure that you have permissions to manage multiple units of measure. +- In the settings of Inventory, enable units of measure. +- For each relevant unit of measure category, determine a default product quantity + (default: 1). +- For each relevant Point of Sale, find 'Set default product quantity' in the + 'Technical' section of its settings, and toggle it on. + Bug Tracker =========== diff --git a/pos_default_quantity/__manifest__.py b/pos_default_quantity/__manifest__.py index 3d281f374b..4c6828ffaf 100644 --- a/pos_default_quantity/__manifest__.py +++ b/pos_default_quantity/__manifest__.py @@ -4,7 +4,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { "name": "Set Default Product Quantity in POS", - "version": "15.0.1.0.0", + "version": "16.0.1.0.0", "author": "Coop IT Easy SC, Odoo Community Association (OCA)", "website": "https://github.com/OCA/pos", "license": "AGPL-3", @@ -15,8 +15,12 @@ """, "depends": ["point_of_sale"], "data": [ - "views/pos_config_views.xml", + "views/res_config_settings_views.xml", "views/uom_category_views.xml", - "static/src/xml/templates.xml", ], + "assets": { + "point_of_sale.assets": [ + "pos_default_quantity/static/src/js/**/*.js", + ] + }, } diff --git a/pos_default_quantity/models/__init__.py b/pos_default_quantity/models/__init__.py index 31beb5976d..3e6ea31b02 100644 --- a/pos_default_quantity/models/__init__.py +++ b/pos_default_quantity/models/__init__.py @@ -1,2 +1,5 @@ from . import pos_config +from . import pos_session +from . import product_template +from . import res_config_settings from . import uom_category diff --git a/pos_default_quantity/models/pos_config.py b/pos_default_quantity/models/pos_config.py index aba94d0d8e..387a8166d1 100644 --- a/pos_default_quantity/models/pos_config.py +++ b/pos_default_quantity/models/pos_config.py @@ -9,5 +9,5 @@ class PosConfig(models.Model): _inherit = "pos.config" set_default_product_quantity = fields.Boolean( - string="Sets default product quantity in POS", default=False + string="Set default product quantity in POS", default=False ) diff --git a/pos_default_quantity/models/pos_session.py b/pos_default_quantity/models/pos_session.py new file mode 100644 index 0000000000..e8b16628c3 --- /dev/null +++ b/pos_default_quantity/models/pos_session.py @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2024 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from odoo import models + + +class PosSession(models.Model): + _inherit = "pos.session" + + def _loader_params_product_product(self): + result = super()._loader_params_product_product() + result["search_params"]["fields"].append("pos_default_qty") + return result diff --git a/pos_default_quantity/models/product_template.py b/pos_default_quantity/models/product_template.py new file mode 100644 index 0000000000..416f966afb --- /dev/null +++ b/pos_default_quantity/models/product_template.py @@ -0,0 +1,11 @@ +# SPDX-FileCopyrightText: 2024 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from odoo import fields, models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + pos_default_qty = fields.Float(related="uom_id.category_id.pos_default_qty") diff --git a/pos_default_quantity/models/res_config_settings.py b/pos_default_quantity/models/res_config_settings.py new file mode 100644 index 0000000000..7e1ae7f51f --- /dev/null +++ b/pos_default_quantity/models/res_config_settings.py @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2024 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + pos_set_default_product_quantity = fields.Boolean( + related="pos_config_id.set_default_product_quantity", + readonly=False, + ) diff --git a/pos_default_quantity/models/uom_category.py b/pos_default_quantity/models/uom_category.py index 99a9d2e1cc..78f1ce85cb 100644 --- a/pos_default_quantity/models/uom_category.py +++ b/pos_default_quantity/models/uom_category.py @@ -8,4 +8,9 @@ class UoMCategory(models.Model): _inherit = "uom.category" - pos_default_qty = fields.Float(string="POS Default Quantity", default=1) + # TODO: Should this be hidden behind a boolean toggle? + pos_default_qty = fields.Float( + string="POS Default Quantity", + required=True, + default=1, + ) diff --git a/pos_default_quantity/readme/DESCRIPTION.rst b/pos_default_quantity/readme/DESCRIPTION.rst index eb53c274e5..2f4aa20c4c 100644 --- a/pos_default_quantity/readme/DESCRIPTION.rst +++ b/pos_default_quantity/readme/DESCRIPTION.rst @@ -1,4 +1,4 @@ This module adds a field for a default quantity to Unit of Measure Categories. When this is filled in, and when this functionality is enabled in the Point of -Sale Configuration, then adding that product to an order in the Point of Sale +Sale configuration, then adding that product to an order in the Point of Sale will set the quantity to that value by default. diff --git a/pos_default_quantity/readme/USAGE.rst b/pos_default_quantity/readme/USAGE.rst new file mode 100644 index 0000000000..b4194c6294 --- /dev/null +++ b/pos_default_quantity/readme/USAGE.rst @@ -0,0 +1,8 @@ +In order to set this up, you need to do a few things: + +- Make sure that you have permissions to manage multiple units of measure. +- In the settings of Inventory, enable units of measure. +- For each relevant unit of measure category, determine a default product quantity + (default: 1). +- For each relevant Point of Sale, find 'Set default product quantity' in the + 'Technical' section of its settings, and toggle it on. diff --git a/pos_default_quantity/static/description/index.html b/pos_default_quantity/static/description/index.html index 0a9ae974a0..1e42f47e4b 100644 --- a/pos_default_quantity/static/description/index.html +++ b/pos_default_quantity/static/description/index.html @@ -371,22 +371,35 @@

Set Default Product Quantity in POS

Beta License: AGPL-3 OCA/pos Translate me on Weblate Try me on Runboat

This module adds a field for a default quantity to Unit of Measure Categories. When this is filled in, and when this functionality is enabled in the Point of -Sale Configuration, then adding that product to an order in the Point of Sale +Sale configuration, then adding that product to an order in the Point of Sale will set the quantity to that value by default.

Table of contents

+
+

Usage

+

In order to set this up, you need to do a few things:

+ +
-

Bug Tracker

+

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 @@ -394,22 +407,22 @@

Bug Tracker

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

-

Credits

+

Credits

-

Authors

+

Authors

-

Contributors

+

Contributors

-

Maintainers

+

Maintainers

This module is maintained by the OCA.

Odoo Community Association

OCA, or the Odoo Community Association, is a nonprofit organization whose diff --git a/pos_default_quantity/static/src/js/models.esm.js b/pos_default_quantity/static/src/js/models.esm.js new file mode 100644 index 0000000000..e9ec9e7c2f --- /dev/null +++ b/pos_default_quantity/static/src/js/models.esm.js @@ -0,0 +1,26 @@ +/** @odoo-module alias=pos_default_quantity.models **/ +// SPDX-FileCopyrightText: 2024 Coop IT Easy SC +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +import {Orderline} from "point_of_sale.models"; +import Registries from "point_of_sale.Registries"; + +const DefaultQtyOrderline = (Orderline) => + class DefaultQtyOrderline extends Orderline { + constructor(obj, options) { + super(obj, options); + + // Don't set default quantity on restored lines + if (options.json) { + return; + } + + if (this.pos.config.set_default_product_qty) { + this.set_quantity(this.product.pos_default_qty); + } + } + }; + +Registries.Model.extend(Orderline, DefaultQtyOrderline); +export default DefaultQtyOrderline; diff --git a/pos_default_quantity/static/src/js/pos.js b/pos_default_quantity/static/src/js/pos.js deleted file mode 100644 index 59e16ebfa7..0000000000 --- a/pos_default_quantity/static/src/js/pos.js +++ /dev/null @@ -1,47 +0,0 @@ -/* - Copyright 2019 Coop IT Easy SC - Robin Keunen - License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -*/ - -odoo.define( - "pos_default_quantity.pos_default_quantity", - - function (require) { - "use strict"; - - var models = require("point_of_sale.models"); - - models.load_models({ - model: "uom.category", - fields: ["name", "pos_default_qty"], - loaded: function (self, unit_categories) { - self.unit_categories = unit_categories; - var unit_categories_by_id = {}; - for (var i = 0, len = unit_categories.length; i < len; i++) { - unit_categories_by_id[unit_categories[i].id] = unit_categories[i]; // eslint-disable-line - } - self.unit_categories_by_id = unit_categories_by_id; - }, - }); - - var orderline_prototype = models.Orderline.prototype; - models.Orderline = models.Orderline.extend({ - initialize: function (attr, options) { - orderline_prototype.initialize.call(this, attr, options); - - // Don't set default quantity on restored lines - if (options.json) { - return; - } - - var unit = this.get_unit(); - var category = this.pos.unit_categories_by_id[unit.category_id[0]]; - - if (this.pos.config.set_default_product_quantity) { - this.set_quantity(category.pos_default_qty); - } - }, - }); - } -); diff --git a/pos_default_quantity/static/src/xml/templates.xml b/pos_default_quantity/static/src/xml/templates.xml deleted file mode 100644 index f51becee32..0000000000 --- a/pos_default_quantity/static/src/xml/templates.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - -