Merge branch 'master' of http://gitea.xxhhcty.xyz:8080/zcdsj/factory
This commit is contained in:
commit
79c8115445
|
|
@ -122,7 +122,13 @@ def daoru_mioitem_test(path:str, mioitem:MIOItem):
|
|||
FtestItem.objects.bulk_create(ftestitems)
|
||||
else:
|
||||
break
|
||||
|
||||
|
||||
mioitem.test_date = test_date
|
||||
mioitem.test_user = test_user
|
||||
mioitem.count = MIOItemw.objects.filter(mioitem=mioitem).count()
|
||||
mioitem.count_tested = MIOItemw.objects.filter(mioitem=mioitem, ftest__isnull=False).count()
|
||||
mioitem.count_notok = MIOItemw.objects.filter(mioitem=mioitem, ftest__is_ok=False).count()
|
||||
mioitem.save()
|
||||
|
||||
def daoru_mioitems(path:str, mio:MIO):
|
||||
from apps.utils.snowflake import idWorker
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ from apps.mtm.models import Material
|
|||
from drf_yasg.utils import swagger_auto_schema
|
||||
from drf_yasg import openapi
|
||||
from django.db import connection
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
# Create your views here.
|
||||
|
|
@ -508,6 +509,10 @@ class MIOItemwViewSet(CustomModelViewSet):
|
|||
mioitem.count = count
|
||||
mioitem.count_tested = MIOItemw.objects.filter(mioitem=mioitem, ftest__isnull=False).count()
|
||||
mioitem.count_notok = MIOItemw.objects.filter(mioitem=mioitem, ftest__is_ok=False).count()
|
||||
if mioitem.test_date is None:
|
||||
mioitem.test_date = datetime.now()
|
||||
if mioitem.test_user is None:
|
||||
mioitem.test_user = self.request.user
|
||||
mioitem.save()
|
||||
|
||||
def perform_create(self, serializer):
|
||||
|
|
|
|||
|
|
@ -706,12 +706,15 @@ class BatchSt(BaseModel):
|
|||
unique_together = [("batch", "version")]
|
||||
|
||||
@classmethod
|
||||
def g_create(cls, batch:str, mio=None, mioitem=None, handover=None, mlog=None, material_start=None, check_mat_start=False, exclude_batchst_ids=[]):
|
||||
def g_create(cls, batch:str, mio=None, mioitem=None, handover=None, mlog=None, material_start=None, check_mat_start=False, exclude_batchst_ids=[], check_batch_exist=False):
|
||||
"""
|
||||
创建新的批次
|
||||
"""
|
||||
if mioitem:
|
||||
mio = mioitem.mio
|
||||
if check_batch_exist:
|
||||
if cls.objects.filter(batch=batch).exclude(id__in=exclude_batchst_ids).exists():
|
||||
raise ParseError(f"{batch}-该批次号已存在不可使用")
|
||||
node, created = cls.safe_get_or_create(batch=batch, version=1, defaults={
|
||||
"mio":mio, "mioitem":mioitem, "handover":handover, "mlog":mlog, "material_start":material_start})
|
||||
if not created and check_mat_start:
|
||||
|
|
|
|||
|
|
@ -500,12 +500,15 @@ def main(batch: str, mgroup_obj=None):
|
|||
data["销售发货_小日期"] = max(data["销售发货_日期"]).strftime("%Y-%m-%d")
|
||||
data["销售发货_大日期"] = min(data["销售发货_日期"]).strftime("%Y-%m-%d")
|
||||
data["销售发货_日期"] = ";".join([item.strftime("%Y-%m-%d") for item in data["销售发货_日期"]])
|
||||
if data.get("六车间领料_count", 0) > 0:
|
||||
data["六车间_批次生产合格率"] = round(data["销售发货_count"] * 100/ data["六车间领料_count"], 1)
|
||||
if data.get("棒料成型_count_real", 0) > 0:
|
||||
data["七车间_批次应出合格率"] = round(data["销售发货_count"] * 100/ data["棒料成型_count_real"], 1)
|
||||
if data.get("管料成型_count_real", 0) > 0:
|
||||
data["十车间_批次应出合格率"] = round(data["销售发货_count"] * 100/ data["管料成型_count_real"], 1)
|
||||
|
||||
# if data.get("六车间领料_count", 0) > 0 or data.get("六车间交接领料_count", 0) > 0:
|
||||
# data["六车间总领料_count"] = data.get("六车间领料_count", 0) + data.get("六车间交接领料_count", 0)
|
||||
# data["六车间_批次生产合格率"] = round((data.get("销售发货_count", 0) + data["六车间库存_count"]) * 100/ data["六车间总领料_count"], 1)
|
||||
# if data.get("棒料成型_count_real", 0) > 0:
|
||||
# data["七车间_批次应出合格率"] = round(data.get("销售发货_count", 0) * 100/ data["棒料成型_count_real"], 1)
|
||||
# if data.get("管料成型_count_real", 0) > 0:
|
||||
# data["十车间_批次应出合格率"] = round(data.get("销售发货_count", 0) * 100/ data["管料成型_count_real"], 1)
|
||||
data["六车间总领料_count"] = data.get("六车间领料_count", 0) + data.get("六车间交接领料_count", 0)
|
||||
|
||||
res = get_f_l_date(data)
|
||||
|
||||
|
|
|
|||
|
|
@ -1197,23 +1197,19 @@ class HandoverSerializer(CustomModelSerializer):
|
|||
attrs['type'] = Handover.H_NORMAL
|
||||
|
||||
mtype = attrs["mtype"]
|
||||
|
||||
new_wm:WMaterial = attrs.get("new_wm", None)
|
||||
if new_wm:
|
||||
attrs['new_batch'] = new_wm.batch
|
||||
if attrs["type"] == Handover.H_CHANGE:
|
||||
attrs["material_changed"] = new_wm.material
|
||||
attrs["state_changed"] = new_wm.state
|
||||
|
||||
if mtype == Handover.H_MERGE:
|
||||
new_state = None
|
||||
new_wm:WMaterial = attrs.get("new_wm", None)
|
||||
if new_wm:
|
||||
attrs['new_batch'] = new_wm.batch
|
||||
new_state = new_wm.state
|
||||
new_defect = new_wm.defect
|
||||
if attrs["type"] == Handover.H_CHANGE:
|
||||
attrs["material_changed"] = new_wm.material
|
||||
attrs["state_changed"] = new_wm.state
|
||||
if not attrs.get("new_batch", None):
|
||||
raise ParseError("必须指定合并后的批次")
|
||||
if 'undefined' in attrs['new_batch'] or 'null' in attrs['new_batch'] or '#' in attrs['new_batch']:
|
||||
raise ParseError("新批次号含有不允许信息!")
|
||||
else:
|
||||
attrs['new_batch'] = None
|
||||
attrs['new_wm'] = None
|
||||
|
||||
if attrs["type"] == Handover.H_CHANGE:
|
||||
if "material_changed" in attrs and attrs["material_changed"]:
|
||||
|
|
@ -1252,6 +1248,14 @@ class HandoverSerializer(CustomModelSerializer):
|
|||
# raise ParseError('正常交接收料工段与送料工段不能相同')
|
||||
t_count = 0
|
||||
tracking = attrs["material"].tracking
|
||||
|
||||
next_mat = None
|
||||
next_state = None
|
||||
next_defect = None
|
||||
if new_wm and attrs["type"] != Handover.H_CHANGE:
|
||||
next_mat = new_wm.material
|
||||
next_state = new_wm.state
|
||||
next_defect = new_wm.defect
|
||||
for ind, item in enumerate(attrs['handoverb']):
|
||||
if item["count"] > 0:
|
||||
pass
|
||||
|
|
@ -1259,16 +1263,16 @@ class HandoverSerializer(CustomModelSerializer):
|
|||
raise ParseError(f'第{ind+1}行-交接数量必须大于0')
|
||||
wm = item["wm"]
|
||||
if mtype == Handover.H_MERGE:
|
||||
if new_state is None:
|
||||
new_mat = wm.material
|
||||
new_state = wm.state
|
||||
new_defect = wm.defect
|
||||
if next_mat is None:
|
||||
next_mat = wm.material
|
||||
next_state = wm.state
|
||||
next_defect = wm.defect
|
||||
else:
|
||||
if new_mat != wm.material:
|
||||
if next_mat != wm.material:
|
||||
raise ParseError(f'第{ind+1}行-合并的物料不一致')
|
||||
if new_state != wm.state:
|
||||
if next_state != wm.state:
|
||||
raise ParseError(f'第{ind+1}行-合并的物料状态不一致')
|
||||
if new_defect != wm.defect:
|
||||
if next_defect != wm.defect:
|
||||
raise ParseError(f'第{ind+1}行-合并的物料缺陷不一致')
|
||||
if tracking == Material.MA_TRACKING_SINGLE:
|
||||
handoverbw = item.get("handoverbw", [])
|
||||
|
|
|
|||
|
|
@ -727,12 +727,15 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime,
|
|||
batches = []
|
||||
mids = []
|
||||
exclude_batchst_ids = []
|
||||
check_batch_exist = False
|
||||
if mtype == Handover.H_MERGE:
|
||||
if new_batch:
|
||||
batches = [new_batch]
|
||||
else:
|
||||
raise ParseError("合并批次时请提供新批次号")
|
||||
target_b, _ = BatchSt.g_create(batch=new_batch, handover=handover, material_start=material)
|
||||
if handover.new_wm is None:
|
||||
check_batch_exist = True
|
||||
target_b, _ = BatchSt.g_create(batch=new_batch, handover=handover, material_start=material, check_batch_exist=check_batch_exist)
|
||||
exclude_batchst_ids.append(target_b.id)
|
||||
elif mtype == Handover.H_DIV:
|
||||
if handover.wm is None:
|
||||
|
|
@ -761,6 +764,7 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime,
|
|||
batches_to_limit.append(batch)
|
||||
target, _ = BatchSt.g_create(batch=batch, handover=handover, material_start=material)
|
||||
exclude_batchst_ids.append(target.id)
|
||||
# 这里暂时忽略check_batch_exist,因为拆批一般不会重复
|
||||
BatchLog.g_create(source=source_b, target=target, handover=handover, relation_type="split")
|
||||
else:
|
||||
batch = wm_from.batch
|
||||
|
|
@ -867,7 +871,7 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime,
|
|||
elif handover.type == Handover.H_CHANGE:
|
||||
if mtype == Handover.H_MERGE and handover.new_wm:
|
||||
wm_to = handover.new_wm
|
||||
if wm_to.material != handover.material_changed or wm_to.state != handover.state_changed or wm_to.defect != wm_from.defect:
|
||||
if wm_to.material != handover.material_changed or wm_to.state != handover.state_changed:
|
||||
raise ParseError("改版合并到的车间库存状态或物料异常")
|
||||
elif handover.recive_mgroup:
|
||||
wm_to, _ = WMaterial.objects.get_or_create(
|
||||
|
|
|
|||
|
|
@ -625,9 +625,6 @@ class HandoverViewSet(CustomModelViewSet):
|
|||
交接记录撤回
|
||||
"""
|
||||
ins: Handover = self.get_object()
|
||||
if ins.new_batch: # 如果是合批
|
||||
if Handoverb.objects.filter(batch=ins.new_batch, handover__submit_time__isnull=True).exists():
|
||||
raise ParseError("该合批存在未提交的交接记录,不可撤回")
|
||||
if ins.submit_time:
|
||||
handover_revert(ins, handler=request.user)
|
||||
return Response()
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in New Issue