From 469839f38e7b0af7c582e07a950fa4433e658c34 Mon Sep 17 00:00:00 2001 From: yuxianghui <3437689193@qq.com> Date: Wed, 12 Jun 2024 10:02:15 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=A4=84=E7=90=86=E4=BA=8C=E7=BB=B4?= =?UTF-8?q?=E7=A0=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/stock.py | 20 ++++++++++++++++++++ sf_warehouse/models/model.py | 5 +++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/sf_manufacturing/models/stock.py b/sf_manufacturing/models/stock.py index f0961947..950e0948 100644 --- a/sf_manufacturing/models/stock.py +++ b/sf_manufacturing/models/stock.py @@ -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.""" diff --git a/sf_warehouse/models/model.py b/sf_warehouse/models/model.py index 286cdf88..1c9b11f4 100644 --- a/sf_warehouse/models/model.py +++ b/sf_warehouse/models/model.py @@ -968,8 +968,9 @@ class SfStockPicking(models.Model): if move and move.product_id.cutting_tool_material_id.name == '刀柄' or '托盘' in ( move.product_id.fixture_material_id.name or ''): for item in move.move_line_nosuggest_ids: - if self.env['stock.lot'].search([('rfid', '=', item.rfid)]): - raise ValidationError('该Rfid【%s】在系统中已经存在,请重新录入!' % item.rfid) + if item.rfid: + if self.env['stock.lot'].search([('rfid', '=', item.rfid)]): + raise ValidationError('该Rfid【%s】在系统中已经存在,请重新录入!' % item.rfid) if item.location_dest_id.name == '进货': if not item.rfid: raise ValidationError('你需要提供%s的Rfid' % move.product_id.name)