diff --git a/pos_price_to_weight/README.rst b/pos_price_to_weight/README.rst index be2f56e844..453383dbb7 100644 --- a/pos_price_to_weight/README.rst +++ b/pos_price_to_weight/README.rst @@ -17,13 +17,13 @@ Point of Sale - Price to Weight :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github - :target: https://github.com/OCA/pos/tree/12.0/pos_price_to_weight + :target: https://github.com/OCA/pos/tree/16.0/pos_price_to_weight :alt: OCA/pos .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/pos-12-0/pos-12-0-pos_price_to_weight + :target: https://translation.odoo-community.org/projects/pos-16-0/pos-16-0-pos_price_to_weight :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/pos&target_branch=12.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/pos&target_branch=16.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| @@ -33,47 +33,47 @@ with price and to compute according quantity. In Odoo by default, there are three types of barcode rules for products. -* 'Unit Product' (type='product'). Scanning a product will add a unit of this +* 'Unit Product' (``type=product``). Scanning a product will add a unit of this product to the current order. -* 'Priced product' (type='price'). A price is extracted from the barcode, and +* 'Priced product' (``type=price``). A price is extracted from the barcode, and a new line with the given price and a quantity = 1 is added to the current order. -* 'Weighted product' (type='weight). A weight is extracted from the barcode, +* 'Weighted product' (``type=weight``). A weight is extracted from the barcode, and a new line with the given weight, and a computed price (quantity * Unit price) is added to the current order. This module add a new option: -* 'Priced Product (Computed Weight)' (type='price_to_weight'). A price is +* 'Priced Product (Computed Weight)' (``type=price_to_weight``). A price is extracted from the barcode, and a new line with the given price, and a computed quantity (Price / Unit Price) is added to the current order. -.. image:: https://raw.githubusercontent.com/OCA/pos/12.0/pos_price_to_weight/static/description/barcode_rule.png - :width: 800 px - This module is usefull in shops with products scaled, to manage correctly stock quantities. -Samples +**Samples** * Given a product with a unit price of 1,50€ / kg + * The barcode is 0212345{NNNDD}x where: * 02 is the prefix of the barcode rule * 12345 is the product number * {NNNDD} is the price of the scaled product * x is the control digit -if {NNNDD} is 00265, the price is so 2,65€ and the according quantity is -2,65€ / 1,5 €/kg = 1,767 kg +* On the product we so set '0212345000007' in the barcode field. -.. image:: https://raw.githubusercontent.com/OCA/pos/12.0/pos_price_to_weight/static/description/pos_test_1.png - :width: 800 px +* if the scanned barcode is 0212345002650: + * {NNNDD} is 00265, the price is so 2,65€ + * the according quantity is 2,65€ / 1,5 €/kg = 1,767 kg -if {NNNDD} is 00810, the price is so 8,10€ and the according quantity is -8,10€ / 1,5 €/kg = 5,400 kg +.. figure:: https://raw.githubusercontent.com/OCA/pos/16.0/pos_price_to_weight/static/description/pos_test_1.png -.. image:: https://raw.githubusercontent.com/OCA/pos/12.0/pos_price_to_weight/static/description/pos_test_2.png - :width: 800 px +* if the scanned barcode is 0212345008102: + * {NNNDD} is 00810, the price is so 8,10€ + * the according quantity is 8,10€ / 1,5 €/kg = 5,400 kg + +.. figure:: https://raw.githubusercontent.com/OCA/pos/16.0/pos_price_to_weight/static/description/pos_test_2.png **Table of contents** @@ -86,18 +86,7 @@ Configuration * Go to Point of Sale > Configuration > Barcode Nomenclatures * Edit your barcode rules, according to your barcodes settings -* Go to Point of Sale > Configuration > Point of Sale -* Select the 'Unit Price' field that will be used to convert the price to weight. - -.. image:: https://raw.githubusercontent.com/OCA/pos/12.0/pos_price_to_weight/static/description/pos_config_form.png - :width: 800 px - -**Note:** - -By default, this is the field ``list_price`` that will be used. -If you want to use a custom field, it should be loaded in the javascript file calling - -``models.load_fields("product.product", ['my_custom_field']);`` +.. figure:: https://raw.githubusercontent.com/OCA/pos/16.0/pos_price_to_weight/static/description/barcode_rule.png Bug Tracker =========== @@ -105,7 +94,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. @@ -122,7 +111,6 @@ Contributors ~~~~~~~~~~~~ * Sylvain LE GAL -* Druidoo Other credits ~~~~~~~~~~~~~ @@ -142,6 +130,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/pos `_ project on GitHub. +This module is part of the `OCA/pos `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/pos_price_to_weight/__manifest__.py b/pos_price_to_weight/__manifest__.py index 0f8bce318c..7b3ffc8bd7 100644 --- a/pos_price_to_weight/__manifest__.py +++ b/pos_price_to_weight/__manifest__.py @@ -1,5 +1,5 @@ # Copyright (C) 2017-Today: La Louve () -# Copyright (C) 2019-Today: Druidoo () +# Copyright (C) 2019-Today: GRAP (http://www.grap.coop) # @author: Sylvain LE GAL (https://twitter.com/legalsylvain) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). @@ -11,16 +11,16 @@ "author": "La Louve, GRAP, Odoo Community Association (OCA)", "website": "https://github.com/OCA/pos", "license": "AGPL-3", - "depends": [ - "point_of_sale", - ], - "data": [ - "data/barcode_rule.xml", - "views/assets.xml", - "views/view_pos_config.xml", - ], + "depends": ["point_of_sale"], + "data": [], "demo": [ + "demo/barcode_rule.xml", "demo/product_product.xml", ], + "assets": { + "point_of_sale.assets": [ + "pos_price_to_weight/static/src/js/ProductScreen.js", + ], + }, "installable": True, } diff --git a/pos_price_to_weight/data/barcode_rule.xml b/pos_price_to_weight/data/barcode_rule.xml deleted file mode 100644 index a5b2ce8d1a..0000000000 --- a/pos_price_to_weight/data/barcode_rule.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - Price Barcodes (Computed Weight) 2 Decimals - - price_to_weight - 02.....{NNNDD} - 15 - ean13 - - - - - diff --git a/pos_price_to_weight/demo/barcode_rule.xml b/pos_price_to_weight/demo/barcode_rule.xml new file mode 100644 index 0000000000..f7b29dfdeb --- /dev/null +++ b/pos_price_to_weight/demo/barcode_rule.xml @@ -0,0 +1,21 @@ + + + + + + Price Barcodes (Computed Weight) 2 Decimals + + price_to_weight + 02.....{NNNDD} + 15 + ean13 + + + diff --git a/pos_price_to_weight/models/__init__.py b/pos_price_to_weight/models/__init__.py index d050eecaaa..ba6651a1f0 100644 --- a/pos_price_to_weight/models/__init__.py +++ b/pos_price_to_weight/models/__init__.py @@ -1,2 +1 @@ from . import barcode_rule -from . import pos_config diff --git a/pos_price_to_weight/models/barcode_rule.py b/pos_price_to_weight/models/barcode_rule.py index ff6827395b..f15653fbba 100644 --- a/pos_price_to_weight/models/barcode_rule.py +++ b/pos_price_to_weight/models/barcode_rule.py @@ -1,4 +1,5 @@ # Copyright (C) 2017-Today: La Louve () +# Copyright (C) 2019-Today: GRAP (http://www.grap.coop) # @author: Sylvain LE GAL (https://twitter.com/legalsylvain) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). @@ -9,5 +10,6 @@ class BarcodeRule(models.Model): _inherit = "barcode.rule" type = fields.Selection( - selection_add=[("price_to_weight", "Priced Product (Computed Weight)")] + selection_add=[("price_to_weight", "Priced Product (Computed Weight)")], + ondelete={"price_to_weight": "cascade"}, ) diff --git a/pos_price_to_weight/models/pos_config.py b/pos_price_to_weight/models/pos_config.py deleted file mode 100644 index 77e7a3440f..0000000000 --- a/pos_price_to_weight/models/pos_config.py +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright 2020 Coop IT Easy - Manuel Claeys Bouuaert -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -from odoo import fields, models - - -class PosConfig(models.Model): - _inherit = "pos.config" - - pos_price_to_weight_price_field_id = fields.Many2one( - string="Price To Weight Field", - comodel_name="ir.model.fields", - domain=[("model", "=", "product.product"), ("ttype", "=", "float")], - required=True, - default=lambda x: x._default_pos_price_to_weight_price_field_id(), - ) - - pos_price_to_weight_price_field_name = fields.Char( - related="pos_price_to_weight_price_field_id.name" - ) - - def _default_pos_price_to_weight_price_field_id(self): - return self.env.ref("product.field_product_product__list_price") diff --git a/pos_price_to_weight/readme/CONFIGURE.rst b/pos_price_to_weight/readme/CONFIGURE.rst index cfdb4b36c8..9e85c17f35 100644 --- a/pos_price_to_weight/readme/CONFIGURE.rst +++ b/pos_price_to_weight/readme/CONFIGURE.rst @@ -1,15 +1,4 @@ * Go to Point of Sale > Configuration > Barcode Nomenclatures * Edit your barcode rules, according to your barcodes settings -* Go to Point of Sale > Configuration > Point of Sale -* Select the 'Unit Price' field that will be used to convert the price to weight. - -.. image:: ../static/description/pos_config_form.png - :width: 800 px - -**Note:** - -By default, this is the field ``list_price`` that will be used. -If you want to use a custom field, it should be loaded in the javascript file calling - -``models.load_fields("product.product", ['my_custom_field']);`` +.. figure:: ../static/description/barcode_rule.png diff --git a/pos_price_to_weight/readme/CONTRIBUTORS.rst b/pos_price_to_weight/readme/CONTRIBUTORS.rst index 61ae03c1f9..9f76a75bc1 100644 --- a/pos_price_to_weight/readme/CONTRIBUTORS.rst +++ b/pos_price_to_weight/readme/CONTRIBUTORS.rst @@ -1,2 +1 @@ * Sylvain LE GAL -* Druidoo diff --git a/pos_price_to_weight/readme/DESCRIPTION.rst b/pos_price_to_weight/readme/DESCRIPTION.rst index bab66fa204..bfeeb5280a 100644 --- a/pos_price_to_weight/readme/DESCRIPTION.rst +++ b/pos_price_to_weight/readme/DESCRIPTION.rst @@ -3,44 +3,44 @@ with price and to compute according quantity. In Odoo by default, there are three types of barcode rules for products. -* 'Unit Product' (type='product'). Scanning a product will add a unit of this +* 'Unit Product' (``type=product``). Scanning a product will add a unit of this product to the current order. -* 'Priced product' (type='price'). A price is extracted from the barcode, and +* 'Priced product' (``type=price``). A price is extracted from the barcode, and a new line with the given price and a quantity = 1 is added to the current order. -* 'Weighted product' (type='weight). A weight is extracted from the barcode, +* 'Weighted product' (``type=weight``). A weight is extracted from the barcode, and a new line with the given weight, and a computed price (quantity * Unit price) is added to the current order. This module add a new option: -* 'Priced Product (Computed Weight)' (type='price_to_weight'). A price is +* 'Priced Product (Computed Weight)' (``type=price_to_weight``). A price is extracted from the barcode, and a new line with the given price, and a computed quantity (Price / Unit Price) is added to the current order. -.. image:: ../static/description/barcode_rule.png - :width: 800 px - This module is usefull in shops with products scaled, to manage correctly stock quantities. -Samples +**Samples** * Given a product with a unit price of 1,50€ / kg + * The barcode is 0212345{NNNDD}x where: * 02 is the prefix of the barcode rule * 12345 is the product number * {NNNDD} is the price of the scaled product * x is the control digit -if {NNNDD} is 00265, the price is so 2,65€ and the according quantity is -2,65€ / 1,5 €/kg = 1,767 kg +* On the product we so set '0212345000007' in the barcode field. + +* if the scanned barcode is 0212345002650: + * {NNNDD} is 00265, the price is so 2,65€ + * the according quantity is 2,65€ / 1,5 €/kg = 1,767 kg -.. image:: ../static/description/pos_test_1.png - :width: 800 px +.. figure:: ../static/description/pos_test_1.png -if {NNNDD} is 00810, the price is so 8,10€ and the according quantity is -8,10€ / 1,5 €/kg = 5,400 kg +* if the scanned barcode is 0212345008102: + * {NNNDD} is 00810, the price is so 8,10€ + * the according quantity is 8,10€ / 1,5 €/kg = 5,400 kg -.. image:: ../static/description/pos_test_2.png - :width: 800 px +.. figure:: ../static/description/pos_test_2.png diff --git a/pos_price_to_weight/static/description/index.html b/pos_price_to_weight/static/description/index.html index 370edde496..fd91d33201 100644 --- a/pos_price_to_weight/static/description/index.html +++ b/pos_price_to_weight/static/description/index.html @@ -1,4 +1,3 @@ - @@ -369,30 +368,29 @@

Point of Sale - Price to Weight

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! source digest: sha256:b0443f725649e14ed47bb43b7e7815d98a6f850cf45bffdd6f66b8eee3ac1b76 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

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

+

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

This module extends Odoo Point Of Sale features, to allow to scan barcode with price and to compute according quantity.

In Odoo by default, there are three types of barcode rules for products.

    -
  • ‘Unit Product’ (type=’product’). Scanning a product will add a unit of this +
  • ‘Unit Product’ (type=product). Scanning a product will add a unit of this product to the current order.
  • -
  • ‘Priced product’ (type=’price’). A price is extracted from the barcode, and +
  • ‘Priced product’ (type=price). A price is extracted from the barcode, and a new line with the given price and a quantity = 1 is added to the current order.
  • -
  • ‘Weighted product’ (type=’weight). A weight is extracted from the barcode, +
  • ‘Weighted product’ (type=weight). A weight is extracted from the barcode, and a new line with the given weight, and a computed price (quantity * Unit price) is added to the current order.

This module add a new option:

    -
  • ‘Priced Product (Computed Weight)’ (type=’price_to_weight’). A price is +
  • ‘Priced Product (Computed Weight)’ (type=price_to_weight). A price is extracted from the barcode, and a new line with the given price, and a computed quantity (Price / Unit Price) is added to the current order.
-https://raw.githubusercontent.com/OCA/pos/12.0/pos_price_to_weight/static/description/barcode_rule.png

This module is usefull in shops with products scaled, to manage correctly stock quantities.

-

Samples

+

Samples

  • Given a product with a unit price of 1,50€ / kg
  • @@ -406,13 +404,34 @@

    Point of Sale - Price to Weight

  • +
  • On the product we so set ‘0212345000007’ in the barcode field.
  • +
  • +
    if the scanned barcode is 0212345002650:
    +
      +
    • {NNNDD} is 00265, the price is so 2,65€
    • +
    • the according quantity is 2,65€ / 1,5 €/kg = 1,767 kg
    -

    if {NNNDD} is 00265, the price is so 2,65€ and the according quantity is -2,65€ / 1,5 €/kg = 1,767 kg

    -https://raw.githubusercontent.com/OCA/pos/12.0/pos_price_to_weight/static/description/pos_test_1.png -

    if {NNNDD} is 00810, the price is so 8,10€ and the according quantity is -8,10€ / 1,5 €/kg = 5,400 kg

    -https://raw.githubusercontent.com/OCA/pos/12.0/pos_price_to_weight/static/description/pos_test_2.png +
    +
    +
  • +
+
+https://raw.githubusercontent.com/OCA/pos/16.0/pos_price_to_weight/static/description/pos_test_1.png +
+
    +
  • +
    if the scanned barcode is 0212345008102:
    +
      +
    • {NNNDD} is 00810, the price is so 8,10€
    • +
    • the according quantity is 8,10€ / 1,5 €/kg = 5,400 kg
    • +
    +
    +
    +
  • +
+
+https://raw.githubusercontent.com/OCA/pos/16.0/pos_price_to_weight/static/description/pos_test_2.png +

Table of contents

    @@ -432,21 +451,17 @@

    Configuration

    • Go to Point of Sale > Configuration > Barcode Nomenclatures
    • Edit your barcode rules, according to your barcodes settings
    • -
    • Go to Point of Sale > Configuration > Point of Sale
    • -
    • Select the ‘Unit Price’ field that will be used to convert the price to weight.
    -https://raw.githubusercontent.com/OCA/pos/12.0/pos_price_to_weight/static/description/pos_config_form.png -

    Note:

    -

    By default, this is the field list_price that will be used. -If you want to use a custom field, it should be loaded in the javascript file calling

    -

    models.load_fields("product.product", ['my_custom_field']);

    +
    +https://raw.githubusercontent.com/OCA/pos/16.0/pos_price_to_weight/static/description/barcode_rule.png +

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.

@@ -462,7 +477,6 @@

Authors

Contributors

@@ -476,7 +490,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/pos project on GitHub.

+

This module is part of the OCA/pos project on GitHub.

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

diff --git a/pos_price_to_weight/static/description/pos_config_form.png b/pos_price_to_weight/static/description/pos_config_form.png deleted file mode 100644 index 7ab0234a10..0000000000 Binary files a/pos_price_to_weight/static/description/pos_config_form.png and /dev/null differ diff --git a/pos_price_to_weight/static/src/js/ProductScreen.js b/pos_price_to_weight/static/src/js/ProductScreen.js new file mode 100644 index 0000000000..f28bda0a02 --- /dev/null +++ b/pos_price_to_weight/static/src/js/ProductScreen.js @@ -0,0 +1,59 @@ +/* + Copyright (C) 2024 - Today: GRAP (http://www.grap.coop) + @author: Sylvain LE GAL (https://twitter.com/legalsylvain) + License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +*/ +odoo.define("pos_price_to_weight.ProductScreen", function (require) { + "use strict"; + + const ProductScreen = require("point_of_sale.ProductScreen"); + const Registries = require("point_of_sale.Registries"); + const {useBarcodeReader} = require("point_of_sale.custom_hooks"); + const NumberBuffer = require("point_of_sale.NumberBuffer"); + + const PosPriceToWeightProductScreen = (OriginalProductScreen) => + class extends OriginalProductScreen { + setup() { + super.setup(); + useBarcodeReader({ + price_to_weight: this._barcodeProductAction, + }); + } + async _barcodeProductAction(code) { + if (code.type !== "price_to_weight") { + return await super._barcodeProductAction(...arguments); + } + + // copy of the original function '_barcodeProductAction' + const product = await this._getProductByBarcode(code); + if (!product) { + return; + } + const options = await this._getAddProductOptions(product, code); + // Do not proceed on adding the product when no options is returned. + // This is consistent with _clickProduct. + if (!options) return; + // copy of the original function '_barcodeProductAction' + + // update the options depending on the type of the scanned code + + var quantity = 0; + var barcode_price = parseFloat(code.value, 10) || 0; + var product_price = product.lst_price; + + if (product_price !== 0) { + quantity = barcode_price / product_price; + } + Object.assign(options, { + quantity: quantity, + merge: false, + }); + this.currentOrder.add_product(product, options); + NumberBuffer.reset(); + } + }; + + Registries.Component.extend(ProductScreen, PosPriceToWeightProductScreen); + + return ProductScreen; +}); diff --git a/pos_price_to_weight/static/src/js/models.js b/pos_price_to_weight/static/src/js/models.js deleted file mode 100644 index 6127750886..0000000000 --- a/pos_price_to_weight/static/src/js/models.js +++ /dev/null @@ -1,39 +0,0 @@ -// /* -// Copyright (C) 2017-Today: La Louve () -// @author: Sylvain LE GAL (https://twitter.com/legalsylvain) -// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -//* / - -odoo.define("pos_price_to_weight.models", function (require) { - "use strict"; - - var models = require("point_of_sale.models"); - - var _super_PosModel = models.PosModel.prototype; - - models.PosModel = models.PosModel.extend({ - scan_product: function (parsed_code) { - if (!(parsed_code.type === "price_to_weight")) { - // Normal behaviour - return _super_PosModel.scan_product.apply(this, [parsed_code]); - } - // Compute quantity, based on price and unit price - var selectedOrder = this.get_order(); - var product = this.db.get_product_by_barcode(parsed_code.base_code); - if (!product) { - return false; - } - var quantity = 0; - var price = parseFloat(parsed_code.value) || 0; - - var product_price = - product[this.config.pos_price_to_weight_price_field_name]; - - if (price !== 0 && product_price !== 0) { - quantity = price / product_price; - } - selectedOrder.add_product(product, {quantity: quantity, merge: false}); - return true; - }, - }); -}); diff --git a/pos_price_to_weight/static/src/js/screens.js b/pos_price_to_weight/static/src/js/screens.js deleted file mode 100644 index deec9f4ffd..0000000000 --- a/pos_price_to_weight/static/src/js/screens.js +++ /dev/null @@ -1,23 +0,0 @@ -/* - Copyright (C) 2017-Today: La Louve () - @author: Sylvain LE GAL (https://twitter.com/legalsylvain) - License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -*/ - -odoo.define("pos_price_to_weight.screens", function (require) { - "use strict"; - - var screens = require("point_of_sale.screens"); - - screens.ScreenWidget.include({ - show: function () { - this._super(); - var self = this; - this.pos.barcode_reader.set_action_callback({ - price_to_weight: _.bind(self.barcode_product_action, self), - }); - }, - }); - - return screens; -}); diff --git a/pos_price_to_weight/views/assets.xml b/pos_price_to_weight/views/assets.xml deleted file mode 100644 index f65ebb2c79..0000000000 --- a/pos_price_to_weight/views/assets.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - -