From d0cc15553bc0e642a4227aa037fe097a5c910501 Mon Sep 17 00:00:00 2001 From: Unai Beristain Date: Thu, 23 Jan 2025 17:13:45 +0100 Subject: [PATCH] [ADD] product_product_qr_code: Create field qr_code in product.product --- mrp_workorder_qr_code/README.rst | 70 +++++++++++++++++++ mrp_workorder_qr_code/__init__.py | 1 + mrp_workorder_qr_code/__manifest__.py | 14 ++++ mrp_workorder_qr_code/models/__init__.py | 1 + mrp_workorder_qr_code/models/mrp_workorder.py | 59 ++++++++++++++++ .../views/mrp_workorder_views.xml | 17 +++++ .../odoo/addons/mrp_workorder_qr_code | 1 + setup/mrp_workorder_qr_code/setup.py | 6 ++ 8 files changed, 169 insertions(+) create mode 100644 mrp_workorder_qr_code/README.rst create mode 100644 mrp_workorder_qr_code/__init__.py create mode 100644 mrp_workorder_qr_code/__manifest__.py create mode 100644 mrp_workorder_qr_code/models/__init__.py create mode 100644 mrp_workorder_qr_code/models/mrp_workorder.py create mode 100644 mrp_workorder_qr_code/views/mrp_workorder_views.xml create mode 120000 setup/mrp_workorder_qr_code/odoo/addons/mrp_workorder_qr_code create mode 100644 setup/mrp_workorder_qr_code/setup.py diff --git a/mrp_workorder_qr_code/README.rst b/mrp_workorder_qr_code/README.rst new file mode 100644 index 0000000000..058a3f5fd7 --- /dev/null +++ b/mrp_workorder_qr_code/README.rst @@ -0,0 +1,70 @@ +.. image:: https://img.shields.io/badge/license-LGPL--3-blue.svg + :target: https://opensource.org/licenses/LGPL-3.0 + :alt: License: LGPL-3 + +======================= +Product QR Code +======================= + +Overview +======== + +The **Product QR Code** module adds the capability to generate and display QR codes for products based on their barcodes. This is particularly useful for inventory management, product identification, and streamlined operations. + +Features +======== + +- **Automatic QR Code Generation**: + - QR codes are generated automatically for products with a barcode. +- **QR Code Display**: + - The QR code is displayed in the product form view for easy access. +- **Integrated Design**: + - The module integrates seamlessly into the existing product management system. + +Usage +===== + +1. **Install the Module**: + - Install the **Product QR Code** module from the Apps menu. + +2. **Generate QR Codes**: + - Open any product with a barcode. + - The QR code is automatically generated and displayed in the form view. + +3. **QR Code Preview**: + - The QR code can be previewed directly from the product form view. + +Configuration +============= + +No additional configuration is required. The module works automatically once installed. + +Testing +======= + +To verify the module's functionality: + +1. Create or edit a product and ensure it has a barcode. +2. Save the product. +3. Check the QR code field to confirm the QR code is generated. + +Bug Tracker +=========== + +If you encounter any issues, please report them on the GitHub repository at `GitHub Issues `_. + +Credits +======= + +Contributors +------------ + +* Ana Juaristi +* Unai Beristain + +For specific questions or support, please contact the contributors. + +License +======= + +This project is licensed under the LGPL-3 License. For more details, refer to the LICENSE file or visit . diff --git a/mrp_workorder_qr_code/__init__.py b/mrp_workorder_qr_code/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/mrp_workorder_qr_code/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mrp_workorder_qr_code/__manifest__.py b/mrp_workorder_qr_code/__manifest__.py new file mode 100644 index 0000000000..53f11236de --- /dev/null +++ b/mrp_workorder_qr_code/__manifest__.py @@ -0,0 +1,14 @@ +{ + "name": "Product QR Code", + "version": "16.0.1.0.0", + "category": "Product", + "author": "Avanzosc", + "license": "LGPL-3", + "depends": ["mrp"], + "data": [ + "views/mrp_workorder_views.xml", + ], + "installable": True, + "application": False, + "website": "https://github.com/avanzosc/odoo-addons", +} diff --git a/mrp_workorder_qr_code/models/__init__.py b/mrp_workorder_qr_code/models/__init__.py new file mode 100644 index 0000000000..ddc78464d7 --- /dev/null +++ b/mrp_workorder_qr_code/models/__init__.py @@ -0,0 +1 @@ +from . import mrp_workorder diff --git a/mrp_workorder_qr_code/models/mrp_workorder.py b/mrp_workorder_qr_code/models/mrp_workorder.py new file mode 100644 index 0000000000..935fda0e46 --- /dev/null +++ b/mrp_workorder_qr_code/models/mrp_workorder.py @@ -0,0 +1,59 @@ +import base64 +import logging +from io import BytesIO + +import qrcode + +from odoo import api, fields, models + +# Configurar el logger +_logger = logging.getLogger(__name__) + + +class MrpWorkorder(models.Model): + _inherit = "mrp.workorder" + + qr_code = fields.Char( + "QR Code", + compute="_compute_qr_code", + store=True, + ) + + @api.depends("sequence") + def _compute_qr_code(self): + for workorder in self: + if workorder.sequence: + sequence_str = str(workorder.sequence) + + # Log de la secuencia + _logger.info( + f"Generating QR code for Workorder with sequence: {sequence_str}" + ) + + qr = qrcode.QRCode( + version=1, + error_correction=qrcode.constants.ERROR_CORRECT_L, + box_size=10, + border=4, + ) + qr.add_data(sequence_str) + qr.make(fit=True) + + # Crear la imagen QR + img = qr.make_image(fill_color="black", back_color="white") + buffer = BytesIO() + img.save(buffer, format="PNG") + qr_image = base64.b64encode(buffer.getvalue()).decode("utf-8") + + # Log de la imagen QR generada + _logger.info( + f"QR code generated for Workorder with sequence: {sequence_str}" + ) + + workorder.qr_code = qr_image + else: + # Log si no hay secuencia + _logger.warning( + f"Workorder with ID {workorder.id} does not have a sequence value. QR code not generated." + ) + workorder.qr_code = False diff --git a/mrp_workorder_qr_code/views/mrp_workorder_views.xml b/mrp_workorder_qr_code/views/mrp_workorder_views.xml new file mode 100644 index 0000000000..a1c3846f64 --- /dev/null +++ b/mrp_workorder_qr_code/views/mrp_workorder_views.xml @@ -0,0 +1,17 @@ + + + mrp.workorder.form.inherit.qr + mrp.workorder + + + + + + + + diff --git a/setup/mrp_workorder_qr_code/odoo/addons/mrp_workorder_qr_code b/setup/mrp_workorder_qr_code/odoo/addons/mrp_workorder_qr_code new file mode 120000 index 0000000000..2860f51401 --- /dev/null +++ b/setup/mrp_workorder_qr_code/odoo/addons/mrp_workorder_qr_code @@ -0,0 +1 @@ +../../../../mrp_workorder_qr_code \ No newline at end of file diff --git a/setup/mrp_workorder_qr_code/setup.py b/setup/mrp_workorder_qr_code/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/mrp_workorder_qr_code/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)