diff options
Diffstat (limited to 'fixco_custom/models/product_product.py')
| -rw-r--r-- | fixco_custom/models/product_product.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/fixco_custom/models/product_product.py b/fixco_custom/models/product_product.py new file mode 100644 index 0000000..2e571a8 --- /dev/null +++ b/fixco_custom/models/product_product.py @@ -0,0 +1,41 @@ +from odoo import fields, models, api, tools, _ +from datetime import datetime, timedelta, date +from odoo.exceptions import UserError +import logging +import requests +import json +import re +import qrcode, base64 +from bs4 import BeautifulSoup +from io import BytesIO + + +class ProductProduct(models.Model): + _inherit = "product.product" + + qty_pcs_box = fields.Float("Pcs Box") + barcode_box = fields.Char("Barcode Box") + qr_code_variant = fields.Binary("QR Code Variant", compute='_compute_qr_code_variant') + + def _compute_qr_code_variant(self): + for rec in self: + # Skip inactive variants + if not rec.active: + rec.qr_code_variant = False # Clear the QR Code for archived variants + continue + + qr = qrcode.QRCode( + version=1, + error_correction=qrcode.constants.ERROR_CORRECT_L, + box_size=5, + border=4, + ) + qr.add_data(rec.barcode if rec.barcode else rec.default_code) + qr.make(fit=True) + img = qr.make_image(fill_color="black", back_color="white") + + buffer = BytesIO() + img.save(buffer, format="PNG") + qr_code_img = base64.b64encode(buffer.getvalue()).decode() + + rec.qr_code_variant = qr_code_img
\ No newline at end of file |
