This commit is contained in:
zty 2025-09-10 14:26:25 +08:00
commit 71bc4e76f0
6 changed files with 69 additions and 10 deletions

View File

@ -175,7 +175,7 @@ class MIOItemCreateSerializer(CustomModelSerializer):
count = validated_data["count"]
batch = validated_data["batch"]
mioitemw = validated_data.pop('mioitemw', [])
instance = super().create(validated_data)
instance:MIOItem = super().create(validated_data)
assemb_dict = {}
for i in assemb:
assemb_dict[i['material'].id] = i
@ -210,6 +210,13 @@ class MIOItemCreateSerializer(CustomModelSerializer):
raise ParseError('不支持自动生成请提供产品明细')
elif len(mioitemw) >= 1:
mio_type = mio.type
if mio_type != "pur_in" and mio_type != "other_in":
wprIds = [i["wpr"].id for i in mioitemw]
mb_ids = list(Wpr.objects.filter(id__in=wprIds).values_list("mb__id", flat=True).distinct())
if len(mb_ids) == 1 and mb_ids[0] == instance.mb.id:
pass
else:
raise ParseError(f'{batch}物料明细中存在{len(mb_ids)}个不同物料批次')
for item in mioitemw:
if item.get("wpr", None) is None and mio_type != "pur_in" and mio_type != "other_in":
raise ParseError(f'{item["number"]}_请提供产品明细ID')

View File

@ -117,6 +117,11 @@ def do_out(item: MIOItem):
mioitemws = MIOItemw.objects.filter(mioitem=item)
if mioitemws.count() != item.count:
raise ParseError("出入库与明细数量不一致,操作失败")
mb_ids = list(Wpr.objects.filter(wpr_mioitemw__in=mioitemws).values_list("mb__id", flat=True).distinct())
if len(mb_ids) == 1 and mb_ids[0] == mb.id:
pass
else:
raise ParseError(f'{xbatch}物料明细中存在{len(mb_ids)}个不同物料批次')
for mioitemw in mioitemws:
Wpr.change_or_new(wpr=mioitemw.wpr, wm=wm, old_mb=mb)
@ -229,6 +234,11 @@ def do_in(item: MIOItem):
mioitemws = MIOItemw.objects.filter(mioitem=item)
if mioitemws.count() != item.count:
raise ParseError("出入库与明细数量不一致,操作失败")
wm_ids = list(Wpr.objects.filter(wpr_mioitemw__in=mioitemws).values_list("wm__id", flat=True).distinct())
if len(wm_ids) == 1 and wm_ids[0] == wm.id:
pass
else:
raise ParseError(f'{xbatch}物料明细中存在{len(wm_ids)}个不同物料批次')
for mioitemw in mioitemws:
Wpr.change_or_new(wpr=mioitemw.wpr, mb=mb, old_wm=wm)

View File

@ -188,6 +188,8 @@ class Mgroup(CommonBModel):
w_s_time = timezone.localtime(w_s_time)
shifts = Shift.objects.filter(rule=self.shift_rule).order_by('sort')
if not shifts:
raise ParseError(f"工段{self.name}未配置班次")
# 处理跨天班次的情况
for shift in shifts:
# 如果开始时间小于结束时间,表示班次在同一天内
@ -202,7 +204,7 @@ class Mgroup(CommonBModel):
# 如果当前时间在结束时间之前,属于前一天
else:
return (w_s_time - timedelta(days=1)).date(), shift
return w_s_time.date(), None
# return w_s_time.date(), None
class TeamMember(BaseModel):

View File

@ -1273,7 +1273,15 @@ class HandoverSerializer(CustomModelSerializer):
if tracking == Material.MA_TRACKING_SINGLE:
handoverbw = item.get("handoverbw", [])
if handoverbw:
item["count"] = len(handoverbw)
t_count += len(handoverbw)
wprIds = [i["wpr"].id for i in handoverbw]
wm_ids = list(Wpr.objects.filter(id__in=wprIds).values_list("wm_id", flat=True).distinct())
if len(wm_ids) == 1 and wm_ids[0] == wm.id:
pass
else:
raise ParseError(f'{wm.batch}物料明细中存在{len(wm_ids)}个不同物料批次')
elif wm.count == item["count"]:
t_count += item["count"]
else:

View File

@ -756,7 +756,7 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime,
raise ParseError('拆批请选择车间库存')
batches_to_limit = BatchLog.batches_to(batch=handover.wm.batch)["batches"]
source_b, _ = BatchSt.g_create(batch=handover.wm.batch)
for item in handoverb_list:
for indx, item in enumerate(handoverb_list):
wmId, xcount, handover_or_b = item
if xcount <= 0:
raise ParseError("存在非正数!")
@ -926,9 +926,16 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime,
handoverbws = Handoverbw.objects.filter(handoverb=handover_or_b)
if handoverbws.count() != xcount:
raise ParseError("交接与明细数量不一致,操作失败")
wm_ids = list(Wpr.objects.filter(wpr_handoverbw__in=handoverbws).values_list("wm_id", flat=True).distinct())
if len(wm_ids) == 1 and wm_ids[0] == wm_from.id:
pass
else:
raise ParseError(f'{batch}物料明细中存在{len(wm_ids)}个不同物料批次')
for item in handoverbws:
wpr:Wpr = item.wpr
Wpr.change_or_new(wpr=wpr, wm=wm_to, old_wm=wpr.wm, old_mb=wpr.mb)
if wm_to.count != Wpr.objects.filter(wm=wm_to).count():
raise ParseError("交接与明细数量不一致2,操作失败")
handover.submit_user = user
handover.submit_time = now

View File

@ -40,6 +40,8 @@ from datetime import datetime, timedelta
from apps.utils.lock import lock_model_record_d_method
from apps.em.models import Equipment
from django.db.models import Prefetch
from drf_yasg.utils import swagger_auto_schema
from drf_yasg import openapi
@ -212,6 +214,14 @@ class MlogViewSet(CustomModelViewSet):
return MlogSerializer
return super().get_serializer_class()
@swagger_auto_schema(manual_parameters=[
openapi.Parameter(name="query", in_=openapi.IN_QUERY, description="定制返回数据",
type=openapi.TYPE_STRING, required=False),
openapi.Parameter(name="with_children", in_=openapi.IN_QUERY, description="带有children(yes/no/count)",
type=openapi.TYPE_STRING, required=False),
openapi.Parameter(name="with_mlogbw", in_=openapi.IN_QUERY, description="带有个列表(out)",
type=openapi.TYPE_STRING, required=False),
])
def list(self, request, *args, **kwargs):
from django.db import connection
from django.conf import settings
@ -261,6 +271,15 @@ class MlogViewSet(CustomModelViewSet):
# if item.get("material_out", None):
# data_dict[item_dict["mlog"]]["mlogb"].append(item_dict)
# data = list(data_dict.values())
if self.request.query_params.get('with_mlogbw', False) == 'out':
wpr_dict = {item["id"]: [] for item in data}
wpr_out_qs = Mlogbw.objects.filter(mlogb__mlog__id__in=wpr_dict.keys(),
mlogb__material_out__isnull=False).values('mlogb__mlog__id', 'number')
for item in wpr_out_qs:
wpr_dict[item["mlogb__mlog__id"]].append(item["number"])
for item in data:
item["mlogbw_number_list"] = wpr_dict.get(item["id"], None)
return data
@lock_model_record_d_method(Mlog)
@ -827,13 +846,13 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust
number = mlogbin.number_from
if d_count_real == 1:
if wpr_number_rule:
number = MlogbInViewSet.gen_number_with_rule(wpr_number_rule, material_out)
number = MlogbInViewSet.gen_number_with_rule(wpr_number_rule, material_out, mlog)
if number_to_batch:
mlogbout, _ = Mlogb.objects.get_or_create(mlogb_from=mlogbin, defaults=update_dict(m_dict, {"count_real": 1, "count_ok": 1, "count_ok_full": 1, "batch": number}))
Mlogbw.objects.get_or_create(number=number, mlogb=mlogbout)
else:
if wpr_number_rule:
number_list = MlogbInViewSet.gen_number_with_rule(wpr_number_rule, material_out, gen_count=d_count_real)
number_list = MlogbInViewSet.gen_number_with_rule(wpr_number_rule, material_out, mlog, gen_count=d_count_real)
for i in range(d_count_real):
if wpr_number_rule:
numberx = number_list[i]
@ -852,14 +871,20 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust
MlogbInViewSet.p_create_after(mlogbin)
@classmethod
def gen_number_with_rule(cls, rule, material_out:Material, gen_count=1):
def gen_number_with_rule(cls, rule, material_out:Material, mlog:Mlog, gen_count=1):
from apps.wpmw.models import Wpr
now = datetime.now() - timedelta(hours=6, minutes=20)
c_year = now.year
handle_date = mlog.handle_date
c_year = handle_date.year
c_year2 = str(c_year)[-2:]
c_month = now.month
c_month = handle_date.month
m_model = material_out.model
wpr = Wpr.objects.filter(material_start=material_out, create_time__year=c_year, create_time__month=c_month).order_by("number").last()
# 按生产日志查询
wpr = Wpr.objects.filter(wpr_mlogbw__mlogb__material_out__isnull=False,
wpr_mlogbw__mlogb__mlog__mgroup=mlog.mgroup,
wpr_mlogbw__mlogb__mlog__is_fix=False,
wpr_mlogbw__mlogb__mlog__submit_time__isnull=False,
wpr_mlogbw__mlogb__mlog__handle_date__year=c_year,
wpr_mlogbw__mlogb__mlog__handle_date__month=c_month).order_by("number").last()
cq_w = 4
if '02d' in rule:
cq_w = 2