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__name": ["exact", "in"],
|
||||
"batch": ["exact", "contains"],
|
||||
"mgroup": ["exact", "in"],
|
||||
"mgroup": ["exact", "in", "isnull"],
|
||||
"mgroup__name": ["exact", "in"],
|
||||
"count": ["gte", "lte", "exact"]
|
||||
}
|
||||
|
|
|
@ -347,7 +347,7 @@ class HandoverSerializer(CustomModelSerializer):
|
|||
attrs['send_mgroup'] = attrs['wm'].mgroup
|
||||
if material.process and material.process.into_wm_mgroup and 'recive_mgroup' not in attrs:
|
||||
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
|
||||
if 'recive_dept' not in attrs and 'recive_mgroup' not in attrs:
|
||||
raise ValidationError('交送车间和交送工段必须有一个')
|
||||
|
|
|
@ -104,13 +104,15 @@ def do_out(mio: MIO):
|
|||
action_list = [[item.material, item.batch, item.count]]
|
||||
for al in action_list:
|
||||
xmaterial, xbatch, xcount = al
|
||||
# 领到车间库存(非工段)
|
||||
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,
|
||||
"material": xmaterial,
|
||||
"count": xcount,
|
||||
"create_by": do_user,
|
||||
"belong_dept": belong_dept
|
||||
"belong_dept": belong_dept,
|
||||
"mgroup": None,
|
||||
})
|
||||
if not new_create:
|
||||
wm.count = wm.count + item.count
|
||||
|
@ -142,13 +144,21 @@ def do_in(mio: MIO):
|
|||
action_list = [[item.material, item.batch, item.count]]
|
||||
for al in action_list:
|
||||
xmaterial, xbatch, xcount = al
|
||||
try:
|
||||
wm = WMaterial.objects.get(
|
||||
batch=xbatch, material=xmaterial, belong_dept=belong_dept)
|
||||
except ObjectDoesNotExist:
|
||||
raise ParseError(f'{str(xmaterial)}-{xbatch}车间物料不存在!')
|
||||
except MultipleObjectsReturned:
|
||||
raise ParseError(f'{str(xmaterial)}-{xbatch}存在多行车间物料!')
|
||||
# 优先从车间库存里拿
|
||||
wm_qs = WMaterial.objects.filter(batch=xbatch, material=xmaterial, belong_dept=belong_dept, mgroup=None)
|
||||
if not wm_qs.exists():
|
||||
wm_qs = WMaterial.objects.filter(batch=xbatch, material=xmaterial, belong_dept=belong_dept, mgroup__isnull=False)
|
||||
|
||||
count_x = wm_qs.count()
|
||||
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
|
||||
if new_count > 0:
|
||||
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
|
||||
|
||||
if material_in: # 需要进行车间库存管理
|
||||
into_wm_mgroup = material_in.process.into_wm_mgroup
|
||||
m_ins = Mlogb.objects.filter(mlog=mlog, material_in__isnull=False)
|
||||
if m_ins.exists():
|
||||
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:
|
||||
mi_ma, mi_batch, mi_count = mi
|
||||
# 需要判断领用数是否合理
|
||||
lookup = {'batch': mi_batch, 'material': mi_ma, 'mgroup': None}
|
||||
if into_wm_mgroup:
|
||||
lookup['mgroup'] = mgroup
|
||||
else:
|
||||
lookup['belong_dept'] = belong_dept
|
||||
material_has_qs = WMaterial.objects.filter(**lookup)
|
||||
count_x = material_has_qs.count()
|
||||
# 优先使用工段库存
|
||||
wm_qs = WMaterial.objects.filter(batch=mi_batch, material=mi_ma, mgroup=mgroup)
|
||||
if not wm_qs.exists():
|
||||
wm_qs = WMaterial.objects.filter(batch=mi_batch, material=mi_ma, belong_dept=belong_dept, mgroup=None)
|
||||
|
||||
count_x = wm_qs.count()
|
||||
if count_x == 1:
|
||||
material_has = material_has_qs.first()
|
||||
wm = wm_qs.first()
|
||||
elif count_x == 0:
|
||||
raise ParseError(
|
||||
f'{str(mi_ma)}-{mi_batch}-批次库存不存在!')
|
||||
else:
|
||||
raise ParseError(
|
||||
f'{str(mi_ma)}-{mi_batch}-存在多个相同批次!')
|
||||
if mi_count > material_has.count:
|
||||
|
||||
if mi_count > wm.count:
|
||||
raise ParseError(
|
||||
f'{str(mi_ma)}-{mi_batch}-该批次车间库存不足!')
|
||||
else:
|
||||
material_has.count = material_has.count - mi_count
|
||||
if material_has.count == 0:
|
||||
material_has.delete()
|
||||
wm.count = wm.count - mi_count
|
||||
if wm.count == 0:
|
||||
wm.delete()
|
||||
else:
|
||||
material_has.save()
|
||||
wm.update_by = user
|
||||
wm.save()
|
||||
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)
|
||||
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()]
|
||||
|
@ -226,10 +236,11 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
|||
else:
|
||||
lookup['belong_dept'] = belong_dept
|
||||
if mo_count > 0:
|
||||
wmaterial, _ = WMaterial.objects.get_or_create(**lookup, defaults=lookup)
|
||||
wmaterial.count = wmaterial.count + mo_count
|
||||
wmaterial.count_eweight = mo_count_eweight
|
||||
wmaterial.save()
|
||||
wm, _ = WMaterial.objects.get_or_create(**lookup, defaults=lookup)
|
||||
wm.count = wm.count + mo_count
|
||||
wm.count_eweight = mo_count_eweight
|
||||
wm.update_by = user
|
||||
wm.save()
|
||||
mlog.submit_time = now
|
||||
mlog.submit_user = user
|
||||
mlog.save()
|
||||
|
@ -249,7 +260,7 @@ def mlog_revert(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
|||
material_in = mlog.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)
|
||||
if m_ins.exists():
|
||||
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:
|
||||
lookup['belong_dept'] = belong_dept
|
||||
|
||||
wmaterial, _ = WMaterial.objects.get_or_create(**lookup, defaults=lookup)
|
||||
wmaterial.count = wmaterial.count + mi_count
|
||||
wmaterial.save()
|
||||
wm, _ = WMaterial.objects.get_or_create(**lookup, defaults=lookup)
|
||||
wm.count = wm.count + mi_count
|
||||
wm.update_by = user
|
||||
wm.save()
|
||||
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)
|
||||
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()]
|
||||
|
@ -282,14 +294,24 @@ def mlog_revert(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
|||
lookup['mgroup'] = mgroup
|
||||
else:
|
||||
lookup['belong_dept'] = belong_dept
|
||||
wmaterial, _ = WMaterial.objects.get_or_create(**lookup, defaults=lookup)
|
||||
wmaterial.count = wmaterial.count - mo_count
|
||||
if wmaterial.count < 0:
|
||||
raise ParseError('车间库存不足, 产物无法回退')
|
||||
elif wmaterial.count == 0:
|
||||
wmaterial.delete()
|
||||
wm_qs = WMaterial.objects.filter(**lookup)
|
||||
count_x = wm_qs.count()
|
||||
if count_x == 1:
|
||||
wm = wm_qs.first()
|
||||
elif count_x == 0:
|
||||
raise ParseError(
|
||||
f'{str(mo_ma)}-{mo_batch}-批次库存不存在!')
|
||||
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_user = None
|
||||
mlog.save()
|
||||
|
|
Loading…
Reference in New Issue