From eecda9e5a66038504a5c8960f7de17c4b708d628 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 4 Mar 2024 10:44:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20material=E5=AF=BC=E5=85=A5=E5=8F=AF?= =?UTF-8?q?=E6=9B=B4=E6=94=B9count=5Fsafe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/mtm/services.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/mtm/services.py b/apps/mtm/services.py index 26130462..2322dbac 100644 --- a/apps/mtm/services.py +++ b/apps/mtm/services.py @@ -49,6 +49,7 @@ def daoru_material(path: str): '×', '*').replace(' ', '') model = sheet[f'd{i}'].value.replace(' ', '') unit = sheet[f'e{i}'].value.replace(' ', '') + count_safe = sheet[f'g{i}'].value except Exception as e: raise ParseError(f'{i}行物料信息错误: {str(e)}') if type in [20, 30]: @@ -62,11 +63,12 @@ def daoru_material(path: str): if type in [20, 30]: filters['process'] = process default = {'type': type, 'name': name, 'specification': specification, - 'model': model, 'unit': unit, 'number': f'm{type}_{ranstr(6)}', 'id': idWorker.get_id()} - Material.objects.update_or_create( - defaults=default, - **filters - ) + 'model': model, 'unit': unit, 'number': f'm{type}_{ranstr(6)}', 'id': idWorker.get_id(), 'count_safe': count_safe} + material, is_created = Material.objects.get_or_create( + **filters, defaults=default) + if not is_created: + material.count_safe = count_safe + material.save() except Exception as e: raise ParseError(f'{i}行物料有误, 导入失败--{e}') i = i + 1