diff --git a/apps/mtm/services.py b/apps/mtm/services.py index 6ed55575..8f4155f1 100644 --- a/apps/mtm/services.py +++ b/apps/mtm/services.py @@ -51,8 +51,8 @@ def daoru_material(path: str): '辅助材料': 40, '加工工具': 50, '辅助工装': 60, '办公用品': 70} from apps.utils.snowflake import idWorker from openpyxl import load_workbook - wb = load_workbook(path) - sheet = wb['物料'] + wb = load_workbook(path, read_only=True) + sheet = wb.active process_l = Process.objects.all() process_d = {p.name: p for p in process_l} i = 3 @@ -62,22 +62,24 @@ def daoru_material(path: str): type_str = sheet[f'b{i}'].value.replace(' ', '') try: type = type_dict[type_str] + cate = sheet[f'c{i}'].value.replace(' ', '') if sheet[f'c{i}'].value else "" number = str(sheet[f'a{i}'].value).replace(' ', '') if sheet[f'a{i}'].value else None - if sheet[f'c{i}'].value: - name = str(sheet[f'c{i}'].value).replace(' ', '') + if sheet[f'd{i}'].value: + name = str(sheet[f'd{i}'].value).replace(' ', '') else: raise ParseError(f'{i}行物料信息错误: 物料名称必填') - specification = str(sheet[f'd{i}'].value).replace( - '×', '*').replace(' ', '') if sheet[f'd{i}'].value else None - model = str(sheet[f'e{i}'].value).replace(' ', '') if sheet[f'e{i}'].value else None - unit = sheet[f'f{i}'].value.replace(' ', '') - count_safe = float(sheet[f'h{i}'].value) if sheet[f'h{i}'].value else None - unit_price = float(sheet[f'i{i}'].value) if sheet[f'i{i}'].value else None + specification = str(sheet[f'e{i}'].value).replace( + '×', '*').replace(' ', '') if sheet[f'e{i}'].value else None + model = str(sheet[f'f{i}'].value).replace(' ', '') if sheet[f'f{i}'].value else None + unit = sheet[f'g{i}'].value.replace(' ', '') + count_safe = float(sheet[f'i{i}'].value) if sheet[f'i{i}'].value else None + unit_price = float(sheet[f'j{i}'].value) if sheet[f'j{i}'].value else None + bin_number_main = sheet[f'k{i}'].value.replace(' ', '') if sheet[f'k{i}'].value else None except Exception as e: raise ParseError(f'{i}行物料信息错误: {e}') if type in [20, 30]: try: - process = process_d[sheet[f'g{i}'].value.replace(' ', '')] + process = process_d[sheet[f'h{i}'].value.replace(' ', '')] except Exception as e: raise ParseError(f'{i}行物料信息错误: {e}') try: @@ -87,7 +89,7 @@ def daoru_material(path: str): filters['process'] = process default = {'type': type, 'name': name, 'specification': specification, 'model': model, 'unit': unit, 'number': number if number else f'm{type}_{ranstr(6)}', 'id': idWorker.get_id(), - 'count_safe': count_safe, 'unit_price': unit_price} + 'count_safe': count_safe, 'unit_price': unit_price, 'cate': cate, 'bin_number_main': bin_number_main} material, is_created = Material.objects.get_or_create( **filters, defaults=default) if not is_created: diff --git a/media/default/template/material.xlsx b/media/default/template/material.xlsx index db0a83ff..291a3067 100644 Binary files a/media/default/template/material.xlsx and b/media/default/template/material.xlsx differ