Merge branch 'master' of https://e.coding.net/ctcdevteam/ehs/ehs_server
This commit is contained in:
commit
82587b1736
|
@ -63,6 +63,8 @@ def do_out(item: MIOItem):
|
||||||
xbatch:str = al[1]
|
xbatch:str = al[1]
|
||||||
xcount:str = al[2]
|
xcount:str = al[2]
|
||||||
xbatches.append(xbatch)
|
xbatches.append(xbatch)
|
||||||
|
if xcount <= 0:
|
||||||
|
raise ParseError("存在非正数!")
|
||||||
mb = None
|
mb = None
|
||||||
if not is_zhj:
|
if not is_zhj:
|
||||||
try:
|
try:
|
||||||
|
@ -140,6 +142,8 @@ def do_in(item: MIOItem):
|
||||||
xbatchs = []
|
xbatchs = []
|
||||||
for al in action_list:
|
for al in action_list:
|
||||||
xmaterial, xbatch, xcount = al
|
xmaterial, xbatch, xcount = al
|
||||||
|
if xcount <= 0:
|
||||||
|
raise ParseError("存在非正数!")
|
||||||
xbatchs.append(xbatch)
|
xbatchs.append(xbatch)
|
||||||
# 扣减车间库存
|
# 扣减车间库存
|
||||||
wm_qs = WMaterial.objects.filter(
|
wm_qs = WMaterial.objects.filter(
|
||||||
|
@ -228,8 +232,9 @@ class InmService:
|
||||||
更新物料数量
|
更新物料数量
|
||||||
"""
|
"""
|
||||||
# 统计物料数量
|
# 统计物料数量
|
||||||
m_ids = MIOItem.objects.filter(mio=instance).values_list('material_id', flat=True)
|
m_ids = list(MIOItem.objects.filter(mio=instance).values_list('material_id', flat=True))
|
||||||
cal_material_count(m_ids)
|
m_ids2 = list(MIOItemA.objects.filter(mioitem__mio=instance).values_list('material_id', flat=True))
|
||||||
|
cal_material_count(m_ids+m_ids2)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def update_inm(cls, instance: MIO, is_reverse: bool = False):
|
def update_inm(cls, instance: MIO, is_reverse: bool = False):
|
||||||
|
@ -242,7 +247,10 @@ class InmService:
|
||||||
BatchLog.clear(mio=instance)
|
BatchLog.clear(mio=instance)
|
||||||
else:
|
else:
|
||||||
for item in MIOItem.objects.filter(mio=instance):
|
for item in MIOItem.objects.filter(mio=instance):
|
||||||
BatchSt.g_create(batch=item.batch, mio=instance, material_start=item.material)
|
if item.mb: # 说明录入到已有批次
|
||||||
|
BatchSt.g_create(batch=item.batch)
|
||||||
|
else:
|
||||||
|
BatchSt.g_create(batch=item.batch, mio=instance, material_start=item.material)
|
||||||
from apps.pum.services import PumService
|
from apps.pum.services import PumService
|
||||||
if is_reverse:
|
if is_reverse:
|
||||||
cls.update_mb(instance, -1)
|
cls.update_mb(instance, -1)
|
||||||
|
@ -254,7 +262,10 @@ class InmService:
|
||||||
BatchLog.clear(mio=instance)
|
BatchLog.clear(mio=instance)
|
||||||
else:
|
else:
|
||||||
for item in MIOItem.objects.filter(mio=instance):
|
for item in MIOItem.objects.filter(mio=instance):
|
||||||
BatchSt.g_create(batch=item, mio=instance, material_start=item.material)
|
if item.mb:
|
||||||
|
BatchSt.g_create(batch=item.batch)
|
||||||
|
else:
|
||||||
|
BatchSt.g_create(batch=item.batch, mio=instance, material_start=item.material)
|
||||||
if is_reverse:
|
if is_reverse:
|
||||||
cls.update_mb(instance, -1)
|
cls.update_mb(instance, -1)
|
||||||
else:
|
else:
|
||||||
|
@ -346,7 +357,7 @@ class InmService:
|
||||||
|
|
||||||
for material, warehouse, batch, change_count, defect, mioitem in m_list:
|
for material, warehouse, batch, change_count, defect, mioitem in m_list:
|
||||||
if change_count <= 0:
|
if change_count <= 0:
|
||||||
continue
|
raise ParseError("存在非正数!")
|
||||||
state = WMaterial.WM_OK
|
state = WMaterial.WM_OK
|
||||||
if defect:
|
if defect:
|
||||||
state = WMaterial.WM_NOTOK
|
state = WMaterial.WM_NOTOK
|
||||||
|
|
|
@ -286,6 +286,7 @@ class MIOItemViewSet(CustomListModelMixin, BulkCreateModelMixin, BulkDestroyMode
|
||||||
sr.save()
|
sr.save()
|
||||||
# 开始变动库存
|
# 开始变动库存
|
||||||
InmService.update_mb_item(ins, -1, 'count_notok')
|
InmService.update_mb_item(ins, -1, 'count_notok')
|
||||||
|
InmService.update_material_count(ins.mio)
|
||||||
return Response()
|
return Response()
|
||||||
|
|
||||||
@action(methods=['post'], detail=True, perms_map={'post': 'mioitem.test'}, serializer_class=serializers.Serializer)
|
@action(methods=['post'], detail=True, perms_map={'post': 'mioitem.test'}, serializer_class=serializers.Serializer)
|
||||||
|
@ -303,6 +304,7 @@ class MIOItemViewSet(CustomListModelMixin, BulkCreateModelMixin, BulkDestroyMode
|
||||||
pass
|
pass
|
||||||
ins.test_date = None
|
ins.test_date = None
|
||||||
ins.save()
|
ins.save()
|
||||||
|
InmService.update_material_count(ins.mio)
|
||||||
return Response()
|
return Response()
|
||||||
|
|
||||||
@action(methods=['post'], detail=True, perms_map={'post': 'mioitem.test'}, serializer_class=MIOItemPurInTestSerializer)
|
@action(methods=['post'], detail=True, perms_map={'post': 'mioitem.test'}, serializer_class=MIOItemPurInTestSerializer)
|
||||||
|
@ -320,6 +322,7 @@ class MIOItemViewSet(CustomListModelMixin, BulkCreateModelMixin, BulkDestroyMode
|
||||||
sr = MIOItemPurInTestSerializer(instance=ins, data=request.data)
|
sr = MIOItemPurInTestSerializer(instance=ins, data=request.data)
|
||||||
sr.is_valid(raise_exception=True)
|
sr.is_valid(raise_exception=True)
|
||||||
sr.save()
|
sr.save()
|
||||||
|
InmService.update_material_count(ins.mio)
|
||||||
return Response()
|
return Response()
|
||||||
|
|
||||||
@action(methods=['post'], detail=False, perms_map={'post': '*'}, serializer_class=MioItemAnaSerializer)
|
@action(methods=['post'], detail=False, perms_map={'post': '*'}, serializer_class=MioItemAnaSerializer)
|
||||||
|
|
|
@ -59,6 +59,18 @@ class MaterialViewSet(CustomModelViewSet):
|
||||||
daoru_material(settings.BASE_DIR + request.data.get('path', ''))
|
daoru_material(settings.BASE_DIR + request.data.get('path', ''))
|
||||||
return Response()
|
return Response()
|
||||||
|
|
||||||
|
@action(methods=['post'], detail=True, serializer_class=Serializer, perms_map={'post': 'material.create'})
|
||||||
|
@transaction.atomic
|
||||||
|
def cal_count(self, request, *args, **kwargs):
|
||||||
|
"""统计数量
|
||||||
|
|
||||||
|
统计数量
|
||||||
|
"""
|
||||||
|
ins = self.get_object()
|
||||||
|
from apps.mtm.services_2 import cal_material_count
|
||||||
|
cal_material_count([ins.id])
|
||||||
|
return Response()
|
||||||
|
|
||||||
@action(methods=['put'], detail=True, serializer_class=Serializer, perms_map={'put': '*'})
|
@action(methods=['put'], detail=True, serializer_class=Serializer, perms_map={'put': '*'})
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def set_week_esitimate_consume(self, request, *args, **kwargs):
|
def set_week_esitimate_consume(self, request, *args, **kwargs):
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
from django.db.models import DecimalField
|
||||||
|
from django.core.validators import MinValueValidator
|
||||||
|
from django.utils.functional import cached_property
|
||||||
|
from decimal import Decimal
|
||||||
|
|
||||||
|
|
||||||
class MyFilePathField(serializers.CharField):
|
class MyFilePathField(serializers.CharField):
|
||||||
|
@ -8,3 +12,9 @@ class MyFilePathField(serializers.CharField):
|
||||||
if 'http' in value:
|
if 'http' in value:
|
||||||
return str(value)
|
return str(value)
|
||||||
return settings.BASE_URL + str(value)
|
return settings.BASE_URL + str(value)
|
||||||
|
|
||||||
|
class PositiveDecimalField(DecimalField):
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def validators(self):
|
||||||
|
return [MinValueValidator(Decimal('0.0'))] + super().validators
|
|
@ -23,6 +23,7 @@ from ..qm.models import Defect, Ftest
|
||||||
from django.db.models import Count, Q
|
from django.db.models import Count, Q
|
||||||
from apps.utils.tasks import ctask_run
|
from apps.utils.tasks import ctask_run
|
||||||
from apps.mtm.models import Process
|
from apps.mtm.models import Process
|
||||||
|
from apps.mtm.services_2 import cal_material_count
|
||||||
|
|
||||||
myLogger = logging.getLogger('log')
|
myLogger = logging.getLogger('log')
|
||||||
|
|
||||||
|
@ -199,6 +200,8 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
||||||
m_ins_list = [(material_in, mlog.batch, mlog.count_use, None, mlog)]
|
m_ins_list = [(material_in, mlog.batch, mlog.count_use, None, mlog)]
|
||||||
for mi in m_ins_list:
|
for mi in m_ins_list:
|
||||||
mi_ma, mi_batch, mi_count, defect, mlog_or_b = mi
|
mi_ma, mi_batch, mi_count, defect, mlog_or_b = mi
|
||||||
|
if mi_count <= 0:
|
||||||
|
raise ParseError('存在非正数!')
|
||||||
# 需要判断领用数是否合理
|
# 需要判断领用数是否合理
|
||||||
# 优先使用工段库存
|
# 优先使用工段库存
|
||||||
if isinstance(mlog_or_b, Mlogb) and mlog_or_b.wm_in:
|
if isinstance(mlog_or_b, Mlogb) and mlog_or_b.wm_in:
|
||||||
|
@ -238,18 +241,19 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
||||||
if need_store_notok:
|
if need_store_notok:
|
||||||
for item in m_ins_bl_list:
|
for item in m_ins_bl_list:
|
||||||
material, batch, count, defect, mi_ = item
|
material, batch, count, defect, mi_ = item
|
||||||
if count> 0:
|
if count <= 0:
|
||||||
lookup = {'batch': batch, 'material': material, 'mgroup': mgroup, 'defect': defect, 'state': WMaterial.WM_NOTOK}
|
raise ParseError('存在非正数!')
|
||||||
wm, is_create = WMaterial.objects.get_or_create(**lookup, defaults={"belong_dept": belong_dept})
|
lookup = {'batch': batch, 'material': material, 'mgroup': mgroup, 'defect': defect, 'state': WMaterial.WM_NOTOK}
|
||||||
wm.count = wm.count + count
|
wm, is_create = WMaterial.objects.get_or_create(**lookup, defaults={"belong_dept": belong_dept})
|
||||||
if is_create:
|
wm.count = wm.count + count
|
||||||
wm.create_by = user
|
if is_create:
|
||||||
wm.batch_ofrom = mi_.batch_ofrom
|
wm.create_by = user
|
||||||
wm.material_ofrom = mi_.material_ofrom
|
wm.batch_ofrom = mi_.batch_ofrom
|
||||||
wm.update_by = user
|
wm.material_ofrom = mi_.material_ofrom
|
||||||
wm.save()
|
wm.update_by = user
|
||||||
if material.tracking == Material.MA_TRACKING_SINGLE:
|
wm.save()
|
||||||
raise ParseError("加工前不良的物料暂不支持单件追踪")
|
if material.tracking == Material.MA_TRACKING_SINGLE:
|
||||||
|
raise ParseError("加工前不良的物料暂不支持单件追踪")
|
||||||
|
|
||||||
|
|
||||||
if material_out or is_fix: # 需要入车间库存
|
if material_out or is_fix: # 需要入车间库存
|
||||||
|
@ -294,7 +298,9 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
||||||
# 一次填写的暂时不处理不合格品
|
# 一次填写的暂时不处理不合格品
|
||||||
for mo in m_outs_list:
|
for mo in m_outs_list:
|
||||||
mo_ma, mo_batch, mo_count, mo_count_eweight, notok_sign_or_defect, mlog_or_b = mo
|
mo_ma, mo_batch, mo_count, mo_count_eweight, notok_sign_or_defect, mlog_or_b = mo
|
||||||
if mo_count <= 0:
|
if mo_count < 0:
|
||||||
|
raise ParseError('存在负数!')
|
||||||
|
elif mo_count == 0:
|
||||||
continue
|
continue
|
||||||
if is_fix:
|
if is_fix:
|
||||||
wm_state = WMaterial.WM_REPAIRED
|
wm_state = WMaterial.WM_REPAIRED
|
||||||
|
@ -435,7 +441,9 @@ def mlog_revert(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
||||||
|
|
||||||
for mo in m_outs_list:
|
for mo in m_outs_list:
|
||||||
mo_ma, mo_batch, mo_count, _, notok_sign_or_defect, mlog_or_b = mo
|
mo_ma, mo_batch, mo_count, _, notok_sign_or_defect, mlog_or_b = mo
|
||||||
if mo_count == 0:
|
if mo_count < 0:
|
||||||
|
raise ParseError('存在负数!')
|
||||||
|
elif mo_count == 0:
|
||||||
continue
|
continue
|
||||||
if is_fix:
|
if is_fix:
|
||||||
wm_state = WMaterial.WM_REPAIRED
|
wm_state = WMaterial.WM_REPAIRED
|
||||||
|
@ -500,6 +508,8 @@ def mlog_revert(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
||||||
m_ins_list = [(material_in, mlog.batch, mlog.count_use, mlog.wm_in, mlog)]
|
m_ins_list = [(material_in, mlog.batch, mlog.count_use, mlog.wm_in, mlog)]
|
||||||
for mi in m_ins_list:
|
for mi in m_ins_list:
|
||||||
mi_ma, mi_batch, mi_count, defect_or, mlog_or_b = mi
|
mi_ma, mi_batch, mi_count, defect_or, mlog_or_b = mi
|
||||||
|
if mi_count <= 0:
|
||||||
|
raise ParseError('存在非正数!')
|
||||||
if isinstance(mlog_or_b, Mlogb) and mlog_or_b.wm_in:
|
if isinstance(mlog_or_b, Mlogb) and mlog_or_b.wm_in:
|
||||||
wm = WMaterial.objects.get(id=mlog_or_b.wm_in.id)
|
wm = WMaterial.objects.get(id=mlog_or_b.wm_in.id)
|
||||||
else:
|
else:
|
||||||
|
@ -531,19 +541,20 @@ def mlog_revert(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
||||||
if stored_notok:
|
if stored_notok:
|
||||||
for item in m_ins_bl_list:
|
for item in m_ins_bl_list:
|
||||||
material, batch, count, defect, mi_ = item
|
material, batch, count, defect, mi_ = item
|
||||||
if count> 0:
|
if count <= 0:
|
||||||
lookup = {'batch': batch, 'material': material, 'mgroup': mgroup, 'defect': defect, 'state': WMaterial.WM_NOTOK}
|
raise ParseError('存在非正数!')
|
||||||
wm, is_create = WMaterial.objects.get_or_create(**lookup, defaults={**lookup, "belong_dept": belong_dept})
|
lookup = {'batch': batch, 'material': material, 'mgroup': mgroup, 'defect': defect, 'state': WMaterial.WM_NOTOK}
|
||||||
wm.count = wm.count - count
|
wm, is_create = WMaterial.objects.get_or_create(**lookup, defaults={**lookup, "belong_dept": belong_dept})
|
||||||
if wm.count < 0:
|
wm.count = wm.count - count
|
||||||
raise ParseError('加工前不良数量大于库存量')
|
if wm.count < 0:
|
||||||
if is_create:
|
raise ParseError('加工前不良数量大于库存量')
|
||||||
wm.create_by = user
|
if is_create:
|
||||||
else:
|
wm.create_by = user
|
||||||
wm.update_by = user
|
else:
|
||||||
wm.save()
|
wm.update_by = user
|
||||||
if material.tracking == Material.MA_TRACKING_SINGLE:
|
wm.save()
|
||||||
raise ParseError("加工前不良的物料暂不支持单件回退")
|
if material.tracking == Material.MA_TRACKING_SINGLE:
|
||||||
|
raise ParseError("加工前不良的物料暂不支持单件回退")
|
||||||
|
|
||||||
mlog.submit_time = None
|
mlog.submit_time = None
|
||||||
mlog.submit_user = None
|
mlog.submit_user = None
|
||||||
|
@ -723,9 +734,13 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime,
|
||||||
raise ParseError("合并批次时请提供新批次号")
|
raise ParseError("合并批次时请提供新批次号")
|
||||||
|
|
||||||
new_target = None
|
new_target = None
|
||||||
|
mids = []
|
||||||
for item in handoverb_list:
|
for item in handoverb_list:
|
||||||
wmId, xcount, handover_or_b = item
|
wmId, xcount, handover_or_b = item
|
||||||
|
if xcount <= 0:
|
||||||
|
raise ParseError("存在非正数!")
|
||||||
wm_from = WMaterial.objects.get(id=wmId)
|
wm_from = WMaterial.objects.get(id=wmId)
|
||||||
|
mids.append(wm_from.material.id)
|
||||||
|
|
||||||
# 合并为新批
|
# 合并为新批
|
||||||
if mtype == Handover.H_MERGE:
|
if mtype == Handover.H_MERGE:
|
||||||
|
@ -897,6 +912,12 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime,
|
||||||
if batches:
|
if batches:
|
||||||
for batch in batches:
|
for batch in batches:
|
||||||
MyThread(target=get_alldata_with_batch_and_store, args=(batch,)).start()
|
MyThread(target=get_alldata_with_batch_and_store, args=(batch,)).start()
|
||||||
|
|
||||||
|
# 如果是改版交接需要触发统计数量
|
||||||
|
if handover.type == Handover.H_CHANGE:
|
||||||
|
mids.append(handover.material_changed.id)
|
||||||
|
cal_material_count(mids)
|
||||||
|
|
||||||
|
|
||||||
def handover_revert(handover:Handover):
|
def handover_revert(handover:Handover):
|
||||||
BatchLog.clear(handover=handover)
|
BatchLog.clear(handover=handover)
|
||||||
|
|
Loading…
Reference in New Issue