feat: 物料导入模板增加编号列
This commit is contained in:
parent
27c60ff973
commit
a9acf6d187
|
@ -63,26 +63,29 @@ def daoru_material(path: str):
|
|||
from apps.utils.snowflake import idWorker
|
||||
from openpyxl import load_workbook
|
||||
wb = load_workbook(path)
|
||||
sheet = wb.get_sheet_by_name('物料')
|
||||
sheet = wb['物料']
|
||||
process_l = Process.objects.all()
|
||||
process_d = {p.name: p for p in process_l}
|
||||
i = 3
|
||||
while sheet[f'a{i}'].value is not None:
|
||||
type_str = sheet[f'a{i}'].value.replace(' ', '')
|
||||
if sheet['a2'].value != '物料编号':
|
||||
raise ParseError('列错误导入失败')
|
||||
while sheet[f'b{i}'].value is not None:
|
||||
type_str = sheet[f'b{i}'].value.replace(' ', '')
|
||||
try:
|
||||
type = type_dict[type_str]
|
||||
name = sheet[f'b{i}'].value.replace(' ', '')
|
||||
specification = sheet[f'c{i}'].value.replace(
|
||||
number = sheet[f'a{i}'].value.replace(' ', '')
|
||||
name = sheet[f'c{i}'].value.replace(' ', '')
|
||||
specification = sheet[f'd{i}'].value.replace(
|
||||
'×', '*').replace(' ', '')
|
||||
model = sheet[f'd{i}'].value.replace(' ', '')
|
||||
unit = sheet[f'e{i}'].value.replace(' ', '')
|
||||
count_safe = sheet[f'g{i}'].value
|
||||
unit_price = sheet[f'h{i}'].value
|
||||
model = sheet[f'e{i}'].value.replace(' ', '')
|
||||
unit = sheet[f'f{i}'].value.replace(' ', '')
|
||||
count_safe = sheet[f'h{i}'].value
|
||||
unit_price = sheet[f'i{i}'].value
|
||||
except Exception as e:
|
||||
raise ParseError(f'{i}行物料信息错误: {str(e)}')
|
||||
if type in [20, 30]:
|
||||
try:
|
||||
process = process_d[sheet[f'f{i}'].value.replace(' ', '')]
|
||||
process = process_d[sheet[f'g{i}'].value.replace(' ', '')]
|
||||
except Exception as e:
|
||||
raise ParseError(f'{i}行物料信息错误: {str(e)}')
|
||||
try:
|
||||
|
@ -91,7 +94,7 @@ 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(),
|
||||
'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}
|
||||
material, is_created = Material.objects.get_or_create(
|
||||
**filters, defaults=default)
|
||||
|
@ -101,7 +104,7 @@ def daoru_material(path: str):
|
|||
except Exception as e:
|
||||
raise ParseError(f'{i}行物料有误, 导入失败--{e}')
|
||||
i = i + 1
|
||||
print(type, name, specification, model, unit, '导入成功')
|
||||
print(number, type, name, specification, model, unit, '导入成功')
|
||||
|
||||
|
||||
def mgroup_run_change(mgroup: Mgroup, new_run: bool, last_timex: datetime):
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue