1、处理二维码问题

This commit is contained in:
yuxianghui
2024-06-12 10:02:15 +08:00
parent 7d7f0348d2
commit 469839f38e
2 changed files with 23 additions and 2 deletions

View File

@@ -3,6 +3,7 @@ import base64
import qrcode
from collections import defaultdict, namedtuple
import logging
import io
import json
from re import split as regex_split
from re import findall as regex_findall
@@ -709,6 +710,25 @@ class ReStockMove(models.Model):
datetime.now().strftime("%Y%m%d"), origin), 1)
move_lines_commands = self._generate_serial_move_line_commands_tool_lot(lot_names)
self.write({'move_line_nosuggest_ids': move_lines_commands})
for item in self.move_line_nosuggest_ids:
if item.lot_name:
item.lot_qr_code = self.compute_lot_qr_code(item.lot_name)
def compute_lot_qr_code(self, lot_name):
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(lot_name)
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")
buffer = io.BytesIO()
img.save(buffer, format="PNG")
binary_data = buffer.getvalue()
data = base64.b64encode(binary_data).decode() # 确保返回的是字符串形式的数据
return data
def _get_tool_next_serial(self, company, product, origin):
"""Return the next serial number to be attributed to the product."""