Merge branch 'master' of http://gitea.xxhhcty.xyz:8080/zcdsj/factory
This commit is contained in:
commit
b52e90a11f
|
@ -37,7 +37,8 @@ class MioFilter(filters.FilterSet):
|
|||
"item_mio__test_user": ["isnull"],
|
||||
"item_mio__w_mioitem__number": ["exact"],
|
||||
"mgroup": ["exact"],
|
||||
"item_mio__batch": ["exact"]
|
||||
"item_mio__batch": ["exact"],
|
||||
"inout_date": ["gte", "lte", "exact"],
|
||||
}
|
||||
|
||||
def filter_materials__type(self, queryset, name, value):
|
||||
|
|
|
@ -10,7 +10,7 @@ from apps.wpmw.models import Wpr
|
|||
from apps.qm.models import Ftest, Defect
|
||||
from django.db.models import Count, Q
|
||||
|
||||
def do_out(item: MIOItem):
|
||||
def do_out(item: MIOItem, is_reverse: bool = False):
|
||||
"""
|
||||
生产领料到车间
|
||||
"""
|
||||
|
@ -23,8 +23,6 @@ def do_out(item: MIOItem):
|
|||
mgroup = mio.mgroup
|
||||
do_user = mio.do_user
|
||||
material:Material = item.material
|
||||
if material.into_wm is False: # 用于混料的原料不与车间库存交互, 这个是配置项目
|
||||
return
|
||||
|
||||
# 获取defect
|
||||
defect:Defect = None
|
||||
|
@ -98,22 +96,24 @@ def do_out(item: MIOItem):
|
|||
else:
|
||||
mb.save()
|
||||
|
||||
|
||||
# 领到车间库存(或工段)
|
||||
wm, new_create = WMaterial.objects.get_or_create(
|
||||
batch=xbatch, material=xmaterial,
|
||||
belong_dept=belong_dept, mgroup=mgroup,
|
||||
state=WMaterial.WM_OK, defect=defect)
|
||||
if new_create:
|
||||
wm.create_by = do_user
|
||||
wm.batch_ofrom = mb.batch if mb else None
|
||||
wm.material_ofrom = mb.material if mb else None
|
||||
wm.count = wm.count + item.count
|
||||
wm.update_by = do_user
|
||||
wm.save()
|
||||
if material.into_wm:
|
||||
# 领到车间库存(或工段)
|
||||
wm, new_create = WMaterial.objects.get_or_create(
|
||||
batch=xbatch, material=xmaterial,
|
||||
belong_dept=belong_dept, mgroup=mgroup,
|
||||
state=WMaterial.WM_OK, defect=defect)
|
||||
if new_create:
|
||||
wm.create_by = do_user
|
||||
wm.batch_ofrom = mb.batch if mb else None
|
||||
wm.material_ofrom = mb.material if mb else None
|
||||
wm.count = wm.count + item.count
|
||||
wm.update_by = do_user
|
||||
wm.save()
|
||||
|
||||
# 开始变动wpr
|
||||
if xmaterial.tracking == Material.MA_TRACKING_SINGLE:
|
||||
if material.into_wm is False:
|
||||
raise ParseError("追踪单个物料不支持不进行车间库存的操作")
|
||||
mioitemws = MIOItemw.objects.filter(mioitem=item)
|
||||
if mioitemws.count() != item.count:
|
||||
raise ParseError("出入库与明细数量不一致,操作失败")
|
||||
|
@ -141,8 +141,7 @@ def do_in(item: MIOItem):
|
|||
mgroup = mio.mgroup
|
||||
do_user = mio.do_user
|
||||
material = item.material
|
||||
if material.into_wm is False: # 根据配置不进行入车间库存的处理
|
||||
return
|
||||
|
||||
action_list = []
|
||||
mias = MIOItemA.objects.filter(mioitem=item)
|
||||
is_zhj = False # 是否组合件入仓库
|
||||
|
@ -177,38 +176,39 @@ def do_in(item: MIOItem):
|
|||
raise ParseError("存在非正数!")
|
||||
|
||||
xbatchs.append(xbatch)
|
||||
|
||||
wm_qs = WMaterial.objects.filter(
|
||||
batch=xbatch,
|
||||
material=xmaterial,
|
||||
belong_dept=belong_dept,
|
||||
mgroup=mgroup,
|
||||
defect=defect,
|
||||
state=WMaterial.WM_OK)
|
||||
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}-存在多个相同批次!')
|
||||
if material.into_wm:
|
||||
wm_qs = WMaterial.objects.filter(
|
||||
batch=xbatch,
|
||||
material=xmaterial,
|
||||
belong_dept=belong_dept,
|
||||
mgroup=mgroup,
|
||||
defect=defect,
|
||||
state=WMaterial.WM_OK)
|
||||
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
|
||||
wm.update_by = do_user
|
||||
wm.save()
|
||||
else:
|
||||
raise ParseError(f'{str(xmaterial)}-{xbatch}车间物料不足')
|
||||
|
||||
wm_production_dept = wm.mgroup.belong_dept if wm.mgroup else wm.belong_dept
|
||||
if production_dept is None:
|
||||
production_dept = wm_production_dept
|
||||
elif wm_production_dept and production_dept != wm_production_dept:
|
||||
raise ParseError(f'{str(xmaterial)}-{xbatch}车间物料不属于同一车间')
|
||||
|
||||
# 扣减车间库存
|
||||
new_count = wm.count - xcount
|
||||
if new_count >= 0:
|
||||
wm.count = new_count
|
||||
wm.update_by = do_user
|
||||
wm.save()
|
||||
else:
|
||||
raise ParseError(f'{str(xmaterial)}-{xbatch}车间物料不足')
|
||||
|
||||
wm_production_dept = wm.mgroup.belong_dept if wm.mgroup else wm.belong_dept
|
||||
if production_dept is None:
|
||||
production_dept = wm_production_dept
|
||||
elif wm_production_dept and production_dept != wm_production_dept:
|
||||
raise ParseError(f'{str(xmaterial)}-{xbatch}车间物料不属于同一车间')
|
||||
# 增加mb
|
||||
if not is_zhj:
|
||||
mb, _ = MaterialBatch.objects.get_or_create(
|
||||
|
@ -231,6 +231,8 @@ def do_in(item: MIOItem):
|
|||
|
||||
# 开始变动wpr
|
||||
if xmaterial.tracking == Material.MA_TRACKING_SINGLE:
|
||||
if material.into_wm is False:
|
||||
raise ParseError("追踪单个物料不支持不进行车间库存的操作")
|
||||
mioitemws = MIOItemw.objects.filter(mioitem=item)
|
||||
if mioitemws.count() != item.count:
|
||||
raise ParseError("出入库与明细数量不一致,操作失败")
|
||||
|
|
Loading…
Reference in New Issue