feat: 根据光芯需求对wpm做兼容性处理2
This commit is contained in:
parent
439c8a0f88
commit
a0dae66cf7
|
@ -41,7 +41,7 @@ class WMaterialFilter(filters.FilterSet):
|
||||||
"belong_dept": ["exact"],
|
"belong_dept": ["exact"],
|
||||||
"belong_dept__name": ["exact", "in"],
|
"belong_dept__name": ["exact", "in"],
|
||||||
"batch": ["exact", "contains"],
|
"batch": ["exact", "contains"],
|
||||||
"mgroup": ["exact", "in"],
|
"mgroup": ["exact", "in", "isnull"],
|
||||||
"mgroup__name": ["exact", "in"],
|
"mgroup__name": ["exact", "in"],
|
||||||
"count": ["gte", "lte", "exact"]
|
"count": ["gte", "lte", "exact"]
|
||||||
}
|
}
|
||||||
|
|
|
@ -347,7 +347,7 @@ class HandoverSerializer(CustomModelSerializer):
|
||||||
attrs['send_mgroup'] = attrs['wm'].mgroup
|
attrs['send_mgroup'] = attrs['wm'].mgroup
|
||||||
if material.process and material.process.into_wm_mgroup and 'recive_mgroup' not in attrs:
|
if material.process and material.process.into_wm_mgroup and 'recive_mgroup' not in attrs:
|
||||||
raise ValidationError('必须指定交接工段')
|
raise ValidationError('必须指定交接工段')
|
||||||
if attrs.get('recive_mgroup', None):
|
if 'recive_mgroup' in attrs and attrs['recive_mgroup']:
|
||||||
attrs['recive_dept'] = attrs['recive_mgroup'].belong_dept
|
attrs['recive_dept'] = attrs['recive_mgroup'].belong_dept
|
||||||
if 'recive_dept' not in attrs and 'recive_mgroup' not in attrs:
|
if 'recive_dept' not in attrs and 'recive_mgroup' not in attrs:
|
||||||
raise ValidationError('交送车间和交送工段必须有一个')
|
raise ValidationError('交送车间和交送工段必须有一个')
|
||||||
|
|
|
@ -104,13 +104,15 @@ def do_out(mio: MIO):
|
||||||
action_list = [[item.material, item.batch, item.count]]
|
action_list = [[item.material, item.batch, item.count]]
|
||||||
for al in action_list:
|
for al in action_list:
|
||||||
xmaterial, xbatch, xcount = al
|
xmaterial, xbatch, xcount = al
|
||||||
|
# 领到车间库存(非工段)
|
||||||
wm, new_create = WMaterial.objects.get_or_create(batch=xbatch, material=xmaterial,
|
wm, new_create = WMaterial.objects.get_or_create(batch=xbatch, material=xmaterial,
|
||||||
belong_dept=belong_dept, defaults={
|
belong_dept=belong_dept, mgroup=None, defaults={
|
||||||
"batch": xbatch,
|
"batch": xbatch,
|
||||||
"material": xmaterial,
|
"material": xmaterial,
|
||||||
"count": xcount,
|
"count": xcount,
|
||||||
"create_by": do_user,
|
"create_by": do_user,
|
||||||
"belong_dept": belong_dept
|
"belong_dept": belong_dept,
|
||||||
|
"mgroup": None,
|
||||||
})
|
})
|
||||||
if not new_create:
|
if not new_create:
|
||||||
wm.count = wm.count + item.count
|
wm.count = wm.count + item.count
|
||||||
|
@ -142,13 +144,21 @@ def do_in(mio: MIO):
|
||||||
action_list = [[item.material, item.batch, item.count]]
|
action_list = [[item.material, item.batch, item.count]]
|
||||||
for al in action_list:
|
for al in action_list:
|
||||||
xmaterial, xbatch, xcount = al
|
xmaterial, xbatch, xcount = al
|
||||||
try:
|
# 优先从车间库存里拿
|
||||||
wm = WMaterial.objects.get(
|
wm_qs = WMaterial.objects.filter(batch=xbatch, material=xmaterial, belong_dept=belong_dept, mgroup=None)
|
||||||
batch=xbatch, material=xmaterial, belong_dept=belong_dept)
|
if not wm_qs.exists():
|
||||||
except ObjectDoesNotExist:
|
wm_qs = WMaterial.objects.filter(batch=xbatch, material=xmaterial, belong_dept=belong_dept, mgroup__isnull=False)
|
||||||
raise ParseError(f'{str(xmaterial)}-{xbatch}车间物料不存在!')
|
|
||||||
except MultipleObjectsReturned:
|
count_x = wm_qs.count()
|
||||||
raise ParseError(f'{str(xmaterial)}-{xbatch}存在多行车间物料!')
|
if count_x == 1:
|
||||||
|
wm = wm_qs.first()
|
||||||
|
elif count_x == 0:
|
||||||
|
raise ParseError(
|
||||||
|
f'{str(xmaterial)}-{xbatch}-批次库存不存在!')
|
||||||
|
else:
|
||||||
|
raise ParseError(
|
||||||
|
f'{str(xmaterial)}-{xbatch}-存在多个相同批次!')
|
||||||
|
|
||||||
new_count = wm.count - xcount
|
new_count = wm.count - xcount
|
||||||
if new_count > 0:
|
if new_count > 0:
|
||||||
wm.count = new_count
|
wm.count = new_count
|
||||||
|
@ -177,7 +187,6 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
||||||
material_in = mlog.material_in
|
material_in = mlog.material_in
|
||||||
|
|
||||||
if material_in: # 需要进行车间库存管理
|
if material_in: # 需要进行车间库存管理
|
||||||
into_wm_mgroup = material_in.process.into_wm_mgroup
|
|
||||||
m_ins = Mlogb.objects.filter(mlog=mlog, material_in__isnull=False)
|
m_ins = Mlogb.objects.filter(mlog=mlog, material_in__isnull=False)
|
||||||
if m_ins.exists():
|
if m_ins.exists():
|
||||||
m_ins_list = [(mi.material_in, mi.batch, mi.count_use) for mi in m_ins.all()]
|
m_ins_list = [(mi.material_in, mi.batch, mi.count_use) for mi in m_ins.all()]
|
||||||
|
@ -186,32 +195,33 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
||||||
for mi in m_ins_list:
|
for mi in m_ins_list:
|
||||||
mi_ma, mi_batch, mi_count = mi
|
mi_ma, mi_batch, mi_count = mi
|
||||||
# 需要判断领用数是否合理
|
# 需要判断领用数是否合理
|
||||||
lookup = {'batch': mi_batch, 'material': mi_ma, 'mgroup': None}
|
# 优先使用工段库存
|
||||||
if into_wm_mgroup:
|
wm_qs = WMaterial.objects.filter(batch=mi_batch, material=mi_ma, mgroup=mgroup)
|
||||||
lookup['mgroup'] = mgroup
|
if not wm_qs.exists():
|
||||||
else:
|
wm_qs = WMaterial.objects.filter(batch=mi_batch, material=mi_ma, belong_dept=belong_dept, mgroup=None)
|
||||||
lookup['belong_dept'] = belong_dept
|
|
||||||
material_has_qs = WMaterial.objects.filter(**lookup)
|
count_x = wm_qs.count()
|
||||||
count_x = material_has_qs.count()
|
|
||||||
if count_x == 1:
|
if count_x == 1:
|
||||||
material_has = material_has_qs.first()
|
wm = wm_qs.first()
|
||||||
elif count_x == 0:
|
elif count_x == 0:
|
||||||
raise ParseError(
|
raise ParseError(
|
||||||
f'{str(mi_ma)}-{mi_batch}-批次库存不存在!')
|
f'{str(mi_ma)}-{mi_batch}-批次库存不存在!')
|
||||||
else:
|
else:
|
||||||
raise ParseError(
|
raise ParseError(
|
||||||
f'{str(mi_ma)}-{mi_batch}-存在多个相同批次!')
|
f'{str(mi_ma)}-{mi_batch}-存在多个相同批次!')
|
||||||
if mi_count > material_has.count:
|
|
||||||
|
if mi_count > wm.count:
|
||||||
raise ParseError(
|
raise ParseError(
|
||||||
f'{str(mi_ma)}-{mi_batch}-该批次车间库存不足!')
|
f'{str(mi_ma)}-{mi_batch}-该批次车间库存不足!')
|
||||||
else:
|
else:
|
||||||
material_has.count = material_has.count - mi_count
|
wm.count = wm.count - mi_count
|
||||||
if material_has.count == 0:
|
if wm.count == 0:
|
||||||
material_has.delete()
|
wm.delete()
|
||||||
else:
|
else:
|
||||||
material_has.save()
|
wm.update_by = user
|
||||||
|
wm.save()
|
||||||
if material_out: # 需要入车间库存
|
if material_out: # 需要入车间库存
|
||||||
into_wm_mgroup = material_out.process.into_wm_mgroup
|
into_wm_mgroup = material_out.process.into_wm_mgroup if material_out.process else False
|
||||||
m_outs = Mlogb.objects.filter(mlog=mlog, material_out__isnull=False)
|
m_outs = Mlogb.objects.filter(mlog=mlog, material_out__isnull=False)
|
||||||
if m_outs.exists():
|
if m_outs.exists():
|
||||||
m_outs_list = [(mo.material_out, mo.batch if mo.batch else mlog.batch, mo.count_ok, mlog.count_real_eweight) for mo in m_outs.all()]
|
m_outs_list = [(mo.material_out, mo.batch if mo.batch else mlog.batch, mo.count_ok, mlog.count_real_eweight) for mo in m_outs.all()]
|
||||||
|
@ -226,10 +236,11 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
||||||
else:
|
else:
|
||||||
lookup['belong_dept'] = belong_dept
|
lookup['belong_dept'] = belong_dept
|
||||||
if mo_count > 0:
|
if mo_count > 0:
|
||||||
wmaterial, _ = WMaterial.objects.get_or_create(**lookup, defaults=lookup)
|
wm, _ = WMaterial.objects.get_or_create(**lookup, defaults=lookup)
|
||||||
wmaterial.count = wmaterial.count + mo_count
|
wm.count = wm.count + mo_count
|
||||||
wmaterial.count_eweight = mo_count_eweight
|
wm.count_eweight = mo_count_eweight
|
||||||
wmaterial.save()
|
wm.update_by = user
|
||||||
|
wm.save()
|
||||||
mlog.submit_time = now
|
mlog.submit_time = now
|
||||||
mlog.submit_user = user
|
mlog.submit_user = user
|
||||||
mlog.save()
|
mlog.save()
|
||||||
|
@ -249,7 +260,7 @@ def mlog_revert(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
||||||
material_in = mlog.material_in
|
material_in = mlog.material_in
|
||||||
if material_in:
|
if material_in:
|
||||||
# 领用数退回
|
# 领用数退回
|
||||||
into_wm_mgroup = material_in.process.into_wm_mgroup
|
into_wm_mgroup = material_in.process.into_wm_mgroup if material_in.process else False
|
||||||
m_ins = Mlogb.objects.filter(mlog=mlog, material_in__isnull=False)
|
m_ins = Mlogb.objects.filter(mlog=mlog, material_in__isnull=False)
|
||||||
if m_ins.exists():
|
if m_ins.exists():
|
||||||
m_ins_list = [(mi.material_in, mi.batch, mi.count_use) for mi in m_ins.all()]
|
m_ins_list = [(mi.material_in, mi.batch, mi.count_use) for mi in m_ins.all()]
|
||||||
|
@ -263,12 +274,13 @@ def mlog_revert(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
||||||
else:
|
else:
|
||||||
lookup['belong_dept'] = belong_dept
|
lookup['belong_dept'] = belong_dept
|
||||||
|
|
||||||
wmaterial, _ = WMaterial.objects.get_or_create(**lookup, defaults=lookup)
|
wm, _ = WMaterial.objects.get_or_create(**lookup, defaults=lookup)
|
||||||
wmaterial.count = wmaterial.count + mi_count
|
wm.count = wm.count + mi_count
|
||||||
wmaterial.save()
|
wm.update_by = user
|
||||||
|
wm.save()
|
||||||
if material_out: # 产物退回
|
if material_out: # 产物退回
|
||||||
# 有多个产物的情况
|
# 有多个产物的情况
|
||||||
into_wm_mgroup = material_out.process.into_wm_mgroup
|
into_wm_mgroup = material_out.process.into_wm_mgroup if material_out.process else False
|
||||||
m_outs = Mlogb.objects.filter(mlog=mlog, material_out__isnull=False)
|
m_outs = Mlogb.objects.filter(mlog=mlog, material_out__isnull=False)
|
||||||
if m_outs.exists():
|
if m_outs.exists():
|
||||||
m_outs_list = [(mo.material_out, mo.batch if mo.batch else mlog.batch, mo.count_ok, mlog.count_real_eweight) for mo in m_outs.all()]
|
m_outs_list = [(mo.material_out, mo.batch if mo.batch else mlog.batch, mo.count_ok, mlog.count_real_eweight) for mo in m_outs.all()]
|
||||||
|
@ -282,14 +294,24 @@ def mlog_revert(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
||||||
lookup['mgroup'] = mgroup
|
lookup['mgroup'] = mgroup
|
||||||
else:
|
else:
|
||||||
lookup['belong_dept'] = belong_dept
|
lookup['belong_dept'] = belong_dept
|
||||||
wmaterial, _ = WMaterial.objects.get_or_create(**lookup, defaults=lookup)
|
wm_qs = WMaterial.objects.filter(**lookup)
|
||||||
wmaterial.count = wmaterial.count - mo_count
|
count_x = wm_qs.count()
|
||||||
if wmaterial.count < 0:
|
if count_x == 1:
|
||||||
raise ParseError('车间库存不足, 产物无法回退')
|
wm = wm_qs.first()
|
||||||
elif wmaterial.count == 0:
|
elif count_x == 0:
|
||||||
wmaterial.delete()
|
raise ParseError(
|
||||||
|
f'{str(mo_ma)}-{mo_batch}-批次库存不存在!')
|
||||||
else:
|
else:
|
||||||
wmaterial.save()
|
raise ParseError(
|
||||||
|
f'{str(mo_ma)}-{mo_batch}-存在多个相同批次!')
|
||||||
|
wm.count = wm.count - mo_count
|
||||||
|
if wm.count < 0:
|
||||||
|
raise ParseError('车间库存不足, 产物无法回退')
|
||||||
|
elif wm.count == 0:
|
||||||
|
wm.delete()
|
||||||
|
else:
|
||||||
|
wm.update_by = user
|
||||||
|
wm.save()
|
||||||
mlog.submit_time = None
|
mlog.submit_time = None
|
||||||
mlog.submit_user = None
|
mlog.submit_user = None
|
||||||
mlog.save()
|
mlog.save()
|
||||||
|
|
Loading…
Reference in New Issue