diff --git a/pos_product_label/README.rst b/pos_product_label/README.rst new file mode 100644 index 0000000000..10e474f115 --- /dev/null +++ b/pos_product_label/README.rst @@ -0,0 +1,97 @@ +================= +POS Product Label +================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:5217f4106aa43ecfb2135d79ed024b49dc510929a619defd7e8f0609e23c74b1 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :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/16.0/pos_product_label + :alt: OCA/pos +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/pos-16-0/pos-16-0-pos_product_label + :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=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Adds a "Print Labels" button to print the product labels for the ordered products. +The button opens a wizard that allows to configure the label layout and quantities. +The behavior is similar to the core "Print Labels" button in Stock Pickings. + +.. image:: https://raw.githubusercontent.com/OCA/pos/16.0/pos_product_label/static/description/preview.png + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +#. Add products to the order +#. Click on the "Print Labels" button +#. Choose the label layout and confirm + +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Camptocamp + +Contributors +~~~~~~~~~~~~ + +* `Camptocamp `_ + + * Iván Todorovich + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +.. |maintainer-ivantodorovich| image:: https://github.com/ivantodorovich.png?size=40px + :target: https://github.com/ivantodorovich + :alt: ivantodorovich + +Current `maintainer `__: + +|maintainer-ivantodorovich| + +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_product_label/__init__.py b/pos_product_label/__init__.py new file mode 100644 index 0000000000..aee8895e7a --- /dev/null +++ b/pos_product_label/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizards diff --git a/pos_product_label/__manifest__.py b/pos_product_label/__manifest__.py new file mode 100644 index 0000000000..3aea7c9941 --- /dev/null +++ b/pos_product_label/__manifest__.py @@ -0,0 +1,22 @@ +# Copyright 2023 Camptocamp SA (https://www.camptocamp.com). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "POS Product Label", + "summary": "Print product labels from the POS", + "version": "16.0.1.0.0", + "author": "Camptocamp, Odoo Community Association (OCA)", + "maintainers": ["ivantodorovich"], + "website": "https://github.com/OCA/pos", + "license": "AGPL-3", + "category": "Point of Sale", + "depends": ["point_of_sale"], + "data": ["views/res_config_settings.xml"], + "assets": { + "point_of_sale.assets": [ + "pos_product_label/static/src/**/*.js", + "pos_product_label/static/src/**/*.xml", + "pos_product_label/static/src/**/*.scss", + ], + }, +} diff --git a/pos_product_label/models/__init__.py b/pos_product_label/models/__init__.py new file mode 100644 index 0000000000..55380fe35a --- /dev/null +++ b/pos_product_label/models/__init__.py @@ -0,0 +1,3 @@ +from . import pos_config +from . import pos_session +from . import res_config_settings diff --git a/pos_product_label/models/pos_config.py b/pos_product_label/models/pos_config.py new file mode 100644 index 0000000000..1cbf447f41 --- /dev/null +++ b/pos_product_label/models/pos_config.py @@ -0,0 +1,14 @@ +# Copyright 2023 Camptocamp SA (https://www.camptocamp.com). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class PosConfig(models.Model): + _inherit = "pos.config" + + iface_product_label = fields.Boolean( + string="Print Product Labels", + help="Display a button to print Product Labels for ordered products", + default=True, + ) diff --git a/pos_product_label/models/pos_session.py b/pos_product_label/models/pos_session.py new file mode 100644 index 0000000000..e8f5b323cd --- /dev/null +++ b/pos_product_label/models/pos_session.py @@ -0,0 +1,38 @@ +# Copyright 2023 Camptocamp SA (https://www.camptocamp.com). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import Command, models +from odoo.tools import plaintext2html + + +class PosSession(models.Model): + _inherit = "pos.session" + + def print_product_labels(self, data): + """Print product labels from the POS. + + :param data: dict with the following keys: + - pos_quantity: either 'order' or 'custom' + - order_quantity_by_product: dict of {product_id: quantity} + - product_ids: list of product ids + - custom_quantity: int + - print_format: str + - extra_html: str + """ + wizard = self.env["product.label.layout"].create( + { + "product_ids": [Command.set(data["product_ids"])], + "custom_quantity": data["custom_quantity"], + "print_format": data["print_format"], + "extra_html": ( + plaintext2html(data["extra_html"]) + if data.get("extra_html") + else False + ), + } + ) + if data.get("pos_quantity") == "order": + wizard = wizard.with_context( + force_label_qty_by_product=data.get("order_quantity_by_product", {}) + ) + return wizard.process() diff --git a/pos_product_label/models/res_config_settings.py b/pos_product_label/models/res_config_settings.py new file mode 100644 index 0000000000..d8ebc8c237 --- /dev/null +++ b/pos_product_label/models/res_config_settings.py @@ -0,0 +1,13 @@ +# Copyright 2023 Camptocamp SA (https://www.camptocamp.com). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + iface_product_label = fields.Boolean( + related="pos_config_id.iface_product_label", + readonly=False, + ) diff --git a/pos_product_label/readme/CONTRIBUTORS.rst b/pos_product_label/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..a1e0a83952 --- /dev/null +++ b/pos_product_label/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Camptocamp `_ + + * Iván Todorovich diff --git a/pos_product_label/readme/DESCRIPTION.rst b/pos_product_label/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..6e59560a73 --- /dev/null +++ b/pos_product_label/readme/DESCRIPTION.rst @@ -0,0 +1,5 @@ +Adds a "Print Labels" button to print the product labels for the ordered products. +The button opens a wizard that allows to configure the label layout and quantities. +The behavior is similar to the core "Print Labels" button in Stock Pickings. + +.. image:: ../static/description/preview.png diff --git a/pos_product_label/readme/USAGE.rst b/pos_product_label/readme/USAGE.rst new file mode 100644 index 0000000000..f47451772e --- /dev/null +++ b/pos_product_label/readme/USAGE.rst @@ -0,0 +1,3 @@ +#. Add products to the order +#. Click on the "Print Labels" button +#. Choose the label layout and confirm diff --git a/pos_product_label/static/description/index.html b/pos_product_label/static/description/index.html new file mode 100644 index 0000000000..cc8b75d1e3 --- /dev/null +++ b/pos_product_label/static/description/index.html @@ -0,0 +1,438 @@ + + + + + + +POS Product Label + + + +
+

POS Product Label

+ + +

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

+

Adds a “Print Labels” button to print the product labels for the ordered products. +The button opens a wizard that allows to configure the label layout and quantities. +The behavior is similar to the core “Print Labels” button in Stock Pickings.

+https://raw.githubusercontent.com/OCA/pos/16.0/pos_product_label/static/description/preview.png +

Table of contents

+ +
+

Usage

+
    +
  1. Add products to the order
  2. +
  3. Click on the “Print Labels” button
  4. +
  5. Choose the label layout and confirm
  6. +
+
+
+

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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Camptocamp
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

Current maintainer:

+

ivantodorovich

+

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_product_label/static/description/preview.png b/pos_product_label/static/description/preview.png new file mode 100644 index 0000000000..007cfb0ac9 Binary files /dev/null and b/pos_product_label/static/description/preview.png differ diff --git a/pos_product_label/static/src/PrintLabelButton.esm.js b/pos_product_label/static/src/PrintLabelButton.esm.js new file mode 100644 index 0000000000..1bd641f020 --- /dev/null +++ b/pos_product_label/static/src/PrintLabelButton.esm.js @@ -0,0 +1,28 @@ +/* @odoo-module */ + +import PosComponent from "point_of_sale.PosComponent"; +import ProductScreen from "point_of_sale.ProductScreen"; +import Registries from "point_of_sale.Registries"; +import {useListener} from "@web/core/utils/hooks"; + +export default class PrintLabelButton extends PosComponent { + setup() { + super.setup(); + useListener("click", this.onClick); + } + async onClick() { + await this.showPopup("PrintLabelPopup"); + } +} + +PrintLabelButton.template = "PrintLabelButton"; + +ProductScreen.addControlButton({ + component: PrintLabelButton, + condition: function () { + return this.env.pos.config.iface_product_label; + }, + position: ["after", "SetFiscalPositionButton"], +}); + +Registries.Component.add(PrintLabelButton); diff --git a/pos_product_label/static/src/PrintLabelButton.xml b/pos_product_label/static/src/PrintLabelButton.xml new file mode 100644 index 0000000000..e7ca374c76 --- /dev/null +++ b/pos_product_label/static/src/PrintLabelButton.xml @@ -0,0 +1,16 @@ + + + + +
+ + Print Labels +
+
+ +
diff --git a/pos_product_label/static/src/PrintLabelPopup.esm.js b/pos_product_label/static/src/PrintLabelPopup.esm.js new file mode 100644 index 0000000000..8da9e03844 --- /dev/null +++ b/pos_product_label/static/src/PrintLabelPopup.esm.js @@ -0,0 +1,60 @@ +/* @odoo-module */ + +import AbstractAwaitablePopup from "point_of_sale.AbstractAwaitablePopup"; +import Registries from "point_of_sale.Registries"; +const {onWillStart, useState} = owl; + +export default class PrintLabelPopup extends AbstractAwaitablePopup { + setup() { + super.setup(); + this.data = useState({ + quantityToPrint: "order", + quantity: 1, + format: null, + extraContent: null, + }); + onWillStart(async () => { + const data = await this.rpc({ + model: "product.label.layout", + method: "fields_get", + kwargs: { + allfields: ["print_format"], + attributes: ["selection"], + }, + }); + this.printFormatOptions = Object.fromEntries(data.print_format.selection); + this.data.format = data.print_format.selection[0][0]; + }); + } + async confirm() { + const order = this.env.pos.get_order(); + const productIds = [ + ...new Set(order.get_orderlines().map((line) => line.product.id)), + ]; + const data = { + product_ids: productIds, + pos_quantity: this.data.quantityToPrint, + custom_quantity: this.data.quantity, + order_quantity_by_product: + this.data.quantityToPrint === "order" + ? Object.fromEntries( + order + .get_orderlines() + .map((line) => [line.product.id, line.quantity]) + ) + : undefined, + print_format: this.data.format, + extra_html: this.data.extraContent, + }; + const response = await this.rpc({ + model: "pos.session", + method: "print_product_labels", + args: [odoo.pos_session_id, data], + }); + this.env.legacyActionManager.do_action(response); + return super.confirm(); + } +} + +PrintLabelPopup.template = "PrintLabelPopup"; +Registries.Component.add(PrintLabelPopup); diff --git a/pos_product_label/static/src/PrintLabelPopup.scss b/pos_product_label/static/src/PrintLabelPopup.scss new file mode 100644 index 0000000000..9ab5a770f2 --- /dev/null +++ b/pos_product_label/static/src/PrintLabelPopup.scss @@ -0,0 +1,82 @@ +/* + Copyright 2023 Camptocamp SA (https://www.camptocamp.com). + License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +*/ + +.pos .popup.product-label-popup { + form { + display: grid; + grid-template-columns: 1fr; + gap: 1em; + text-align: left; + font-size: 1rem; + + @media (min-width: 992px) { + grid-template-columns: 1fr 1fr; + } + + & > section { + height: fit-content; + display: grid; + grid-template-columns: fit-content(150px) 1fr; + gap: 1em; + padding: 0.5em; + + & > div { + display: contents; + } + } + + label { + line-height: 1.75em; + font-family: inherit; + font-weight: bold; + } + + input, + textarea, + select { + font-size: 1em; + font-family: inherit; + border: none; + background: white; + width: auto; + min-height: auto; + padding: 0.25em 0.5em; + border-radius: 0.2em; + box-shadow: 0px 0px 0px 1px gainsboro inset; + + &:focus { + outline: none; + box-shadow: 0px 0px 0px 3px $primary; + } + } + + textarea { + resize: vertical; + } + + select { + padding: 0.25em; + } + + fieldset { + margin: 0; + padding: 0; + border: none; + display: grid; + grid-template-columns: fit-content(2em) auto; + row-gap: 0.5em; + + & > label { + font-weight: normal; + } + } + + input[type="radio"] { + box-shadow: none; + margin: 0; + margin-right: 0.5em; + } + } +} diff --git a/pos_product_label/static/src/PrintLabelPopup.xml b/pos_product_label/static/src/PrintLabelPopup.xml new file mode 100644 index 0000000000..e74e147bcb --- /dev/null +++ b/pos_product_label/static/src/PrintLabelPopup.xml @@ -0,0 +1,70 @@ + + + + +