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