summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/product_template.py
diff options
context:
space:
mode:
Diffstat (limited to 'indoteknik_custom/models/product_template.py')
-rwxr-xr-xindoteknik_custom/models/product_template.py48
1 files changed, 47 insertions, 1 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py
index 6fb8c7a0..5bedae13 100755
--- a/indoteknik_custom/models/product_template.py
+++ b/indoteknik_custom/models/product_template.py
@@ -5,7 +5,9 @@ import logging
import requests
import json
import re
+import qrcode, base64
from bs4 import BeautifulSoup
+from io import BytesIO
_logger = logging.getLogger(__name__)
@@ -58,10 +60,30 @@ class ProductTemplate(models.Model):
('sp', 'Spare Part'),
('acc', 'Accessories')
], string='Kind of', copy=False)
- sni = fields.Boolean(string='SNI')
+ sni = fields.Boolean(string='SNI')
tkdn = fields.Boolean(string='TKDN')
short_spesification = fields.Char(string='Short Spesification')
merchandise_ok = fields.Boolean(string='Product Promotion')
+ print_barcode = fields.Boolean(string='Print Barcode', default=True)
+ # qr_code = fields.Binary("QR Code", compute='_compute_qr_code')
+
+ # def _compute_qr_code(self):
+ # for rec in self.product_variant_ids:
+ # qr = qrcode.QRCode(
+ # version=1,
+ # error_correction=qrcode.constants.ERROR_CORRECT_L,
+ # box_size=5,
+ # border=4,
+ # )
+ # qr.add_data(rec.display_name)
+ # 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 = qr_code_img
@api.constrains('name', 'internal_reference', 'x_manufacture')
def required_public_categ_ids(self):
@@ -379,6 +401,30 @@ class ProductProduct(models.Model):
qty_rpo = fields.Float(string='Qty RPO', compute='_get_qty_rpo')
plafon_qty = fields.Float(string='Max Plafon', compute='_get_plafon_qty_product')
merchandise_ok = fields.Boolean(string='Product Promotion')
+ 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.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
def _get_clean_website_description(self):
for rec in self: