Skip to content

Commit

Permalink
[ADD] product_product_qr_code: Create field qr_code in product.product
Browse files Browse the repository at this point in the history
  • Loading branch information
unaiberis committed Jan 23, 2025
1 parent 65e5c6d commit 8748f27
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 0 deletions.
70 changes: 70 additions & 0 deletions product_product_qr_code/README.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/avanzosc/odoo-addons/issues>`_.

Credits
=======

Contributors
------------

* Ana Juaristi <[email protected]>
* Unai Beristain <[email protected]>

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 <https://opensource.org/licenses/LGPL-3.0>.
1 change: 1 addition & 0 deletions product_product_qr_code/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
14 changes: 14 additions & 0 deletions product_product_qr_code/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "Product QR Code",
"version": "16.0.1.0.0",
"category": "Product",
"author": "Avanzosc",
"license": "LGPL-3",
"depends": ["product"],
"data": [
"views/product_product_views.xml",
],
"installable": True,
"application": False,
"website": "https://github.com/avanzosc/odoo-addons",
}
1 change: 1 addition & 0 deletions product_product_qr_code/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import product_product
33 changes: 33 additions & 0 deletions product_product_qr_code/models/product_product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import base64
from io import BytesIO

import qrcode

from odoo import api, fields, models


class ProductProduct(models.Model):
_inherit = "product.product"

qr_code = fields.Char("QR Code", compute="_compute_qr_code", store=True)

@api.depends("barcode")
def _compute_qr_code(self):
for product in self:
if product.barcode:
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(product.barcode)
qr.make(fit=True)

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")
product.qr_code = qr_image
else:
product.qr_code = False
17 changes: 17 additions & 0 deletions product_product_qr_code/views/product_product_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<odoo>
<record id="view_product_form_inherit" model="ir.ui.view">
<field name="name">product.product.form.inherit.qr</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view" />
<field name="arch" type="xml">
<xpath expr="//field[@name='barcode']" position="after">
<field
name="qr_code"
widget="image"
class="oe_avatar"
options="{'preview_image': 'qr_code'}"
/>
</xpath>
</field>
</record>
</odoo>
6 changes: 6 additions & 0 deletions setup/product_product_qr_code/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 8748f27

Please sign in to comment.