Merge branch 'master' of https://e.coding.net/ctcdevteam/ehs/ehs_server
This commit is contained in:
commit
717fe20821
|
@ -276,7 +276,7 @@ def insert_mplogx_from_king_mqtt_chunk(objs: list, otime_obj: datetime, is_offse
|
|||
code = f"K_{n}"
|
||||
cache_key = Mpoint.cache_key(code)
|
||||
mpoint_data = get_mpoint_cache(code)
|
||||
if mpoint_data is None:
|
||||
if mpoint_data is None or not mpoint_data['enabled']:
|
||||
continue
|
||||
val_type = mpoint_data["val_type"]
|
||||
# if is_offset:
|
||||
|
@ -287,7 +287,7 @@ def insert_mplogx_from_king_mqtt_chunk(objs: list, otime_obj: datetime, is_offse
|
|||
# else:
|
||||
# timex = timezone.make_aware(datetime.strptime(timex, '%Y-%m-%d %H:%M:%S.%f'))
|
||||
mpoint_interval = mpoint_data["interval"]
|
||||
mpoint_last_timex = mpoint_data.get("last_timex", None)
|
||||
mpoint_last_timex = mpoint_data.get('last_data', {}).get('last_timex', None)
|
||||
mpoint_is_rep_ep_running_state = mpoint_data.get("is_rep_ep_running_state", False)
|
||||
mpoint_ep_base_val1 = mpoint_data.get("ep_base_val1", None)
|
||||
# 控制采集间隔
|
||||
|
|
|
@ -5,6 +5,7 @@ from django.db.models import F
|
|||
from apps.wpm.services import do_out, do_in
|
||||
from apps.mtm.models import Material, Process
|
||||
from apps.utils.tools import ranstr
|
||||
from apps.system.models import Dept
|
||||
|
||||
|
||||
class InmService:
|
||||
|
@ -61,63 +62,57 @@ class InmService:
|
|||
in = 1
|
||||
out = -1
|
||||
"""
|
||||
belong_dept = instance.belong_dept
|
||||
mioitems = MIOItem.objects.filter(mio=instance)
|
||||
if not mioitems.exists():
|
||||
raise ParseError("未填写物料明细")
|
||||
type = instance.type
|
||||
prodction_dept = instance.belong_dept
|
||||
for i in MIOItem.objects.filter(mio=instance):
|
||||
material = i.material
|
||||
warehouse = i.warehouse
|
||||
mb, is_created = MaterialBatch.objects.get_or_create(
|
||||
material=material, warehouse=warehouse, batch=i.batch, defaults={"material": material, "warehouse": warehouse, "count": 0, "batch": i.batch}
|
||||
)
|
||||
if in_or_out == 1:
|
||||
mb.count = mb.count + i.count
|
||||
# if mb.expiration_date is None:
|
||||
# mb.expiration_date = i.expiration_date
|
||||
if instance.type == MIO.MIO_TYPE_DO_IN: # 生产入库需要记录production_dept字段
|
||||
if mb.production_dept is None or mb.production_dept == belong_dept:
|
||||
mb.production_dept = belong_dept
|
||||
else:
|
||||
raise ParseError("同种物料不同生产车间应该有不同批次号!")
|
||||
mb.save()
|
||||
mias = MIOItemA.objects.filter(mioitem=i)
|
||||
if mias.exists(): # 组合件入库
|
||||
if not is_created:
|
||||
raise ParseError("该批次组合件已存在")
|
||||
for mia in mias:
|
||||
MaterialBatchA.objects.create(mb=mb, material=mia.material, batch=mia.batch)
|
||||
elif in_or_out == -1:
|
||||
mb.count = mb.count - i.count
|
||||
if mb.count < 0:
|
||||
raise ParseError("批次库存不足,操作失败")
|
||||
elif mb.count == 0:
|
||||
mb.delete()
|
||||
else:
|
||||
mb.save()
|
||||
else:
|
||||
raise ParseError("不支持的操作")
|
||||
cls.cal_mat_count(material)
|
||||
cls.update_mb_item(i, in_or_out, type, prodction_dept)
|
||||
|
||||
@classmethod
|
||||
def update_mb_after_test(cls, ins: MIOItem):
|
||||
count_notok = ins.count_notok
|
||||
batch = ins.batch
|
||||
material = ins.material
|
||||
warehouse = ins.warehouse
|
||||
try:
|
||||
mb = MaterialBatch.objects.get(material=material, batch=batch, warehouse=warehouse)
|
||||
count_new = mb.count - count_notok
|
||||
if count_new < 0:
|
||||
raise ParseError("库存扣减失败,请确认!")
|
||||
mb.count = count_new
|
||||
def update_mb_item(cls, i: MIOItem, in_or_out: int = 1, field:str='count', type: str =None, production_dept: Dept=None):
|
||||
"""
|
||||
更新物料批次(根据明细)
|
||||
in = 1
|
||||
out = -1
|
||||
默认使用count字段做加减
|
||||
"""
|
||||
if type is None or production_dept is None:
|
||||
mio = i.mio
|
||||
type = mio.type
|
||||
production_dept = mio.belong_dept
|
||||
material = i.material
|
||||
warehouse = i.warehouse
|
||||
mb, is_created = MaterialBatch.objects.get_or_create(
|
||||
material=material, warehouse=warehouse, batch=i.batch, defaults={"material": material, "warehouse": warehouse, "count": 0, "batch": i.batch}
|
||||
)
|
||||
if in_or_out == 1:
|
||||
mb.count = mb.count + getattr(i, field)
|
||||
if type == MIO.MIO_TYPE_DO_IN: # 生产入库需要记录production_dept字段
|
||||
if mb.production_dept is None or mb.production_dept == production_dept:
|
||||
mb.production_dept = production_dept
|
||||
else:
|
||||
raise ParseError("同种物料不同生产车间应该有不同批次号!")
|
||||
mb.save()
|
||||
except MaterialBatch.DoesNotExist:
|
||||
# 库存不存在已被消耗了
|
||||
if count_notok != 0:
|
||||
raise ParseError("库存已全消耗!")
|
||||
mias = MIOItemA.objects.filter(mioitem=i)
|
||||
if mias.exists(): # 组合件入库
|
||||
if not is_created:
|
||||
raise ParseError("该批次组合件已存在")
|
||||
for mia in mias:
|
||||
MaterialBatchA.objects.create(mb=mb, material=mia.material, batch=mia.batch)
|
||||
elif in_or_out == -1:
|
||||
mb.count = mb.count - getattr(i, field)
|
||||
if mb.count < 0:
|
||||
raise ParseError("批次库存不足,操作失败")
|
||||
elif mb.count == 0:
|
||||
mb.delete()
|
||||
else:
|
||||
mb.save()
|
||||
else:
|
||||
raise ParseError("不支持的操作")
|
||||
cls.cal_mat_count(material)
|
||||
|
||||
|
||||
|
||||
def daoru_mb(path: str):
|
||||
"""
|
||||
|
|
|
@ -253,7 +253,22 @@ class MIOItemViewSet(ListModelMixin, BulkCreateModelMixin, BulkDestroyModelMixin
|
|||
sr.is_valid(raise_exception=True)
|
||||
sr.save()
|
||||
# 开始变动库存
|
||||
InmService.update_mb_after_test(ins)
|
||||
InmService.update_mb_item(ins, -1, 'count_notok', mio.type, mio.belong_dept)
|
||||
return Response()
|
||||
|
||||
@action(methods=['post'], detail=True, perms_map={'post': 'mioitem.test'}, serializer_class=serializers.Serializer)
|
||||
@transaction.atomic
|
||||
def test_revert(self, request, *args, **kwargs):
|
||||
"""
|
||||
检验撤回
|
||||
"""
|
||||
ins: MIOItem = self.get_object()
|
||||
mio: MIO = ins.mio
|
||||
if ins.test_date is None:
|
||||
raise ParseError('该明细还未检验')
|
||||
InmService.update_mb_item(ins, 1, 'count_notok', mio.type, mio.belong_dept)
|
||||
ins.test_date = None
|
||||
ins.save()
|
||||
return Response()
|
||||
|
||||
@action(methods=['post'], detail=True, perms_map={'post': 'mioitem.test'}, serializer_class=MIOItemPurInTestSerializer)
|
||||
|
|
Loading…
Reference in New Issue