feat: daoru棒管test
This commit is contained in:
parent
a672a76eee
commit
dbea38f82b
|
@ -1,9 +1,8 @@
|
||||||
from apps.inm.models import (MIO, MIOItem,
|
from apps.inm.models import (MIO, MIOItem,
|
||||||
MaterialBatch, MaterialBatchA,
|
MaterialBatch, MaterialBatchA,
|
||||||
MIOItemA, WareHouse, MIOItemw)
|
MIOItemA, MIOItemw)
|
||||||
from rest_framework.exceptions import ParseError
|
from rest_framework.exceptions import ParseError
|
||||||
from apps.mtm.models import Material, Process
|
from apps.mtm.models import Material
|
||||||
from apps.utils.tools import ranstr
|
|
||||||
from apps.mtm.services_2 import cal_material_count
|
from apps.mtm.services_2 import cal_material_count
|
||||||
from apps.wpm.models import WMaterial, BatchSt, BatchLog
|
from apps.wpm.models import WMaterial, BatchSt, BatchLog
|
||||||
from apps.wpm.services_2 import ana_batch_thread
|
from apps.wpm.services_2 import ana_batch_thread
|
||||||
|
@ -438,60 +437,4 @@ class InmService:
|
||||||
# 批次统计分析
|
# 批次统计分析
|
||||||
ana_batch_thread(xbatchs)
|
ana_batch_thread(xbatchs)
|
||||||
|
|
||||||
def daoru_mb(path: str):
|
|
||||||
"""
|
|
||||||
导入物料批次(如没有物料自动创建)
|
|
||||||
"""
|
|
||||||
# 注释的是初次导入时做的数据矫正
|
|
||||||
# objs1 = Material.objects.filter(specification__contains=' ')
|
|
||||||
# for i in objs1:
|
|
||||||
# i.specification = i.specification.replace(' ', '')
|
|
||||||
# i.save()
|
|
||||||
# objs2 = Material.objects.filter(specification__contains='×')
|
|
||||||
# for i in objs2:
|
|
||||||
# i.specification = i.specification.replace('×', '*')
|
|
||||||
# i.save()
|
|
||||||
# objs3 = (Material.objects.filter(
|
|
||||||
# specification__contains='优级') | Material.objects.filter(specification__contains='一级')).exclude(specification__contains='|')
|
|
||||||
# for i in objs3:
|
|
||||||
# i.specification = i.specification.replace(
|
|
||||||
# '优级', '|优级').replace('一级', '|一级')
|
|
||||||
# i.save()
|
|
||||||
type_dict = {"主要原料": 30, "半成品": 20, "成品": 10, "辅助材料": 40, "加工工具": 50, "辅助工装": 60, "办公用品": 70}
|
|
||||||
from apps.utils.snowflake import idWorker
|
|
||||||
from openpyxl import load_workbook
|
|
||||||
|
|
||||||
wb = load_workbook(path)
|
|
||||||
process_l = Process.objects.all()
|
|
||||||
process_d = {p.name: p for p in process_l}
|
|
||||||
warehouse_l = WareHouse.objects.all()
|
|
||||||
warehouse_d = {w.name: w for w in warehouse_l}
|
|
||||||
for sheet in wb.worksheets:
|
|
||||||
i = 3
|
|
||||||
while sheet[f"a{i}"].value:
|
|
||||||
try:
|
|
||||||
type = type_dict[sheet[f"a{i}"].value.replace(" ", "")]
|
|
||||||
name = sheet[f"b{i}"].value.replace(" ", "")
|
|
||||||
specification = sheet[f"c{i}"].value.replace(" ", "")
|
|
||||||
if sheet[f"d{i}"].value and sheet[f"d{i}"].value.replace(" ", ""):
|
|
||||||
specification = specification + "|" + sheet[f"d{i}"].value.replace(" ", "")
|
|
||||||
model = sheet[f"e{i}"].value.replace(" ", "")
|
|
||||||
process = process_d[sheet[f"f{i}"].value.replace(" ", "")]
|
|
||||||
batch = sheet[f"g{i}"].value.replace(" ", "")
|
|
||||||
count = int(sheet[f"h{i}"].value)
|
|
||||||
warehouse = warehouse_d[sheet[f"i{i}"].value.replace(" ", "")]
|
|
||||||
except KeyError as e:
|
|
||||||
raise ParseError(f"第{i}行数据有误:{str(e)}")
|
|
||||||
material, _ = Material.objects.get_or_create(
|
|
||||||
type=type,
|
|
||||||
name=name,
|
|
||||||
specification=specification,
|
|
||||||
model=model,
|
|
||||||
process=process,
|
|
||||||
defaults={"type": type, "name": name, "specification": specification, "model": model, "process": process, "number": ranstr(6), "id": idWorker.get_id()},
|
|
||||||
)
|
|
||||||
MaterialBatch.objects.get_or_create(
|
|
||||||
material=material, batch=batch, warehouse=warehouse, defaults={"material": material, "batch": batch, "warehouse": warehouse, "count": count, "id": idWorker.get_id()}
|
|
||||||
)
|
|
||||||
cal_material_count([material.id])
|
|
||||||
i = i + 1
|
|
||||||
|
|
|
@ -0,0 +1,104 @@
|
||||||
|
from rest_framework.exceptions import ParseError
|
||||||
|
from apps.mtm.models import Process, Material
|
||||||
|
from apps.inm.models import WareHouse, MaterialBatch, MIOItem
|
||||||
|
from apps.utils.tools import ranstr
|
||||||
|
from apps.mtm.services_2 import cal_material_count
|
||||||
|
|
||||||
|
def daoru_mb(path: str):
|
||||||
|
"""
|
||||||
|
导入物料批次(如没有物料自动创建)
|
||||||
|
"""
|
||||||
|
# 注释的是初次导入时做的数据矫正
|
||||||
|
# objs1 = Material.objects.filter(specification__contains=' ')
|
||||||
|
# for i in objs1:
|
||||||
|
# i.specification = i.specification.replace(' ', '')
|
||||||
|
# i.save()
|
||||||
|
# objs2 = Material.objects.filter(specification__contains='×')
|
||||||
|
# for i in objs2:
|
||||||
|
# i.specification = i.specification.replace('×', '*')
|
||||||
|
# i.save()
|
||||||
|
# objs3 = (Material.objects.filter(
|
||||||
|
# specification__contains='优级') | Material.objects.filter(specification__contains='一级')).exclude(specification__contains='|')
|
||||||
|
# for i in objs3:
|
||||||
|
# i.specification = i.specification.replace(
|
||||||
|
# '优级', '|优级').replace('一级', '|一级')
|
||||||
|
# i.save()
|
||||||
|
type_dict = {"主要原料": 30, "半成品": 20, "成品": 10, "辅助材料": 40, "加工工具": 50, "辅助工装": 60, "办公用品": 70}
|
||||||
|
from apps.utils.snowflake import idWorker
|
||||||
|
from openpyxl import load_workbook
|
||||||
|
|
||||||
|
wb = load_workbook(path)
|
||||||
|
process_l = Process.objects.all()
|
||||||
|
process_d = {p.name: p for p in process_l}
|
||||||
|
warehouse_l = WareHouse.objects.all()
|
||||||
|
warehouse_d = {w.name: w for w in warehouse_l}
|
||||||
|
for sheet in wb.worksheets:
|
||||||
|
i = 3
|
||||||
|
while sheet[f"a{i}"].value:
|
||||||
|
try:
|
||||||
|
type = type_dict[sheet[f"a{i}"].value.replace(" ", "")]
|
||||||
|
name = sheet[f"b{i}"].value.replace(" ", "")
|
||||||
|
specification = sheet[f"c{i}"].value.replace(" ", "")
|
||||||
|
if sheet[f"d{i}"].value and sheet[f"d{i}"].value.replace(" ", ""):
|
||||||
|
specification = specification + "|" + sheet[f"d{i}"].value.replace(" ", "")
|
||||||
|
model = sheet[f"e{i}"].value.replace(" ", "")
|
||||||
|
process = process_d[sheet[f"f{i}"].value.replace(" ", "")]
|
||||||
|
batch = sheet[f"g{i}"].value.replace(" ", "")
|
||||||
|
count = int(sheet[f"h{i}"].value)
|
||||||
|
warehouse = warehouse_d[sheet[f"i{i}"].value.replace(" ", "")]
|
||||||
|
except KeyError as e:
|
||||||
|
raise ParseError(f"第{i}行数据有误:{str(e)}")
|
||||||
|
material, _ = Material.objects.get_or_create(
|
||||||
|
type=type,
|
||||||
|
name=name,
|
||||||
|
specification=specification,
|
||||||
|
model=model,
|
||||||
|
process=process,
|
||||||
|
defaults={"type": type, "name": name, "specification": specification, "model": model, "process": process, "number": ranstr(6), "id": idWorker.get_id()},
|
||||||
|
)
|
||||||
|
MaterialBatch.objects.get_or_create(
|
||||||
|
material=material, batch=batch, warehouse=warehouse, defaults={"material": material, "batch": batch, "warehouse": warehouse, "count": count, "id": idWorker.get_id()}
|
||||||
|
)
|
||||||
|
cal_material_count([material.id])
|
||||||
|
i = i + 1
|
||||||
|
|
||||||
|
def daoru_mioitem_test(path:str, mioitem:MIOItem):
|
||||||
|
from apps.utils.snowflake import idWorker
|
||||||
|
from openpyxl import load_workbook
|
||||||
|
from apps.qm.models import TestItem, Ftest, Qct, FtestItem
|
||||||
|
|
||||||
|
qct = Qct.get(mioitem.material)
|
||||||
|
ptxh = TestItem.objects.get(name="配套序号")
|
||||||
|
bbh = TestItem.objects.get(name="棒编号")
|
||||||
|
bzdwj = TestItem.object.get(name="棒最大外径/mm")
|
||||||
|
zd = TestItem.object.get(name="锥度/mm")
|
||||||
|
gbh = TestItem.objects.get(name="管编号")
|
||||||
|
gzdnj = TestItem.objects.get(name="管最大内径/mm")
|
||||||
|
phjx = TestItem.objects.get(name="配合间隙")
|
||||||
|
test_user = mioitem.mio.mio_user
|
||||||
|
|
||||||
|
wb = load_workbook(path)
|
||||||
|
sheet = wb["Sheet1"]
|
||||||
|
i = 4
|
||||||
|
n = 1
|
||||||
|
while sheet[f"c{i}"].value:
|
||||||
|
number = mioitem.number + "-" + str(n)
|
||||||
|
ftest, _ = Ftest.objects.get_or_create(
|
||||||
|
type="purin",
|
||||||
|
test_numer=number, defaults={
|
||||||
|
"qct": qct,
|
||||||
|
"test_user": test_user,
|
||||||
|
"is_ok": True
|
||||||
|
})
|
||||||
|
FtestItem.objects.filter(ftest=ftest).delete()
|
||||||
|
ftestitems = []
|
||||||
|
ftestitems.append(FtestItem(ftest=ftest, testitem=ptxh, test_val_json=sheet[f"b{i}"].value, test_user=test_user, id=idWorker.get_id()))
|
||||||
|
ftestitems.append(FtestItem(ftest=ftest, testitem=bbh, test_val_json=sheet[f"c{i}"].value, test_user=test_user, id=idWorker.get_id()))
|
||||||
|
ftestitems.append(FtestItem(ftest=ftest, testitem=bzdwj, test_val_json=sheet[f"e{i}"].value, test_user=test_user, id=idWorker.get_id()))
|
||||||
|
ftestitems.append(FtestItem(ftest=ftest, testitem=zd, test_val_json=sheet[f"f{i}"].value, test_user=test_user, id=idWorker.get_id()))
|
||||||
|
ftestitems.append(FtestItem(ftest=ftest, testitem=gbh, test_val_json=sheet[f"g{i}"].value, test_user=test_user, id=idWorker.get_id()))
|
||||||
|
ftestitems.append(FtestItem(ftest=ftest, testitem=gzdnj, test_val_json=sheet[f"j{i}"].value, test_user=test_user, id=idWorker.get_id()))
|
||||||
|
ftestitems.append(FtestItem(ftest=ftest, testitem=phjx, test_val_json=sheet[f"k{i}"].value, test_user=test_user, id=idWorker.get_id()))
|
||||||
|
FtestItem.objects.bulk_create(ftestitems)
|
||||||
|
i = i + 1
|
||||||
|
n = n + 1
|
|
@ -17,7 +17,8 @@ from apps.inm.serializers import (
|
||||||
MIOItemwSerializer)
|
MIOItemwSerializer)
|
||||||
from apps.inm.serializers2 import MIOItemwCreateUpdateSerializer
|
from apps.inm.serializers2 import MIOItemwCreateUpdateSerializer
|
||||||
from apps.utils.viewsets import CustomGenericViewSet, CustomModelViewSet
|
from apps.utils.viewsets import CustomGenericViewSet, CustomModelViewSet
|
||||||
from apps.inm.services import InmService, daoru_mb
|
from apps.inm.services import InmService
|
||||||
|
from apps.inm.services_daoru import daoru_mb, daoru_mioitem_test
|
||||||
from apps.utils.mixins import (BulkCreateModelMixin, BulkDestroyModelMixin, BulkUpdateModelMixin,
|
from apps.utils.mixins import (BulkCreateModelMixin, BulkDestroyModelMixin, BulkUpdateModelMixin,
|
||||||
CustomListModelMixin)
|
CustomListModelMixin)
|
||||||
from apps.utils.permission import has_perm
|
from apps.utils.permission import has_perm
|
||||||
|
@ -351,6 +352,16 @@ class MIOItemViewSet(CustomListModelMixin, BulkCreateModelMixin, BulkDestroyMode
|
||||||
res[i] = 0
|
res[i] = 0
|
||||||
return Response(res)
|
return Response(res)
|
||||||
|
|
||||||
|
@action(methods=['post'], detail=True, perms_map={'post': 'mioitem.update'}, serializer_class=serializers.Serializer)
|
||||||
|
@transaction.atomic
|
||||||
|
def test_daoru_bg(self, request, *args, **kwargs):
|
||||||
|
"""导入棒管检验
|
||||||
|
|
||||||
|
导入棒管检验
|
||||||
|
"""
|
||||||
|
daoru_mioitem_test(path=settings.BASE_DIR + request.data.get('path', ''), mioitem=self.get_object())
|
||||||
|
return Response()
|
||||||
|
|
||||||
|
|
||||||
class MIOItemwViewSet(CustomModelViewSet):
|
class MIOItemwViewSet(CustomModelViewSet):
|
||||||
perms_map = {'get': '*', 'post': 'mio.update', 'put': 'mio.update', 'delete': 'mio.update'}
|
perms_map = {'get': '*', 'post': 'mio.update', 'put': 'mio.update', 'delete': 'mio.update'}
|
||||||
|
|
Loading…
Reference in New Issue