From 9ebf15b04fbb3775dff83690ba09f4444f0ded38 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 28 Sep 2023 09:22:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=94=9F=E4=BA=A7=E5=85=A5=E5=BA=93?= =?UTF-8?q?=E5=90=8E=E5=8F=98=E6=9B=B4=E8=BD=A6=E9=97=B4=E7=89=A9=E6=96=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/inm/services.py | 6 ++++-- apps/wpm/services.py | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/apps/inm/services.py b/apps/inm/services.py index fd71a460..609eddc4 100644 --- a/apps/inm/services.py +++ b/apps/inm/services.py @@ -1,6 +1,7 @@ from apps.inm.models import MIO, MIOItem, MaterialBatch from rest_framework.exceptions import ValidationError from django.db.models.aggregates import Sum +from apps.wpm.services import do_out, do_in class InmService: @@ -15,14 +16,15 @@ class InmService: if instance.type == MIO.MIO_TYPE_PUR_IN: # 需要更新订单 from apps.pum.services import PumService PumService.mio_purin(instance) + elif instance.type == MIO.MIO_TYPE_DO_IN: + do_in(instance) elif instance.type in [MIO.MIO_TYPE_DO_OUT, MIO.MIO_TYPE_SALE_OUT, MIO.MIO_TYPE_OTHER_OUT]: # 生产领料 销售出库 cls.update_mb(instance, -1) if instance.type == MIO.MIO_TYPE_SALE_OUT: from apps.sam.services import SamService SamService.mio_saleout(instance) elif instance.type == MIO.MIO_TYPE_DO_OUT: - from apps.wpm.services import pick - pick(instance) + do_out(instance) @classmethod def update_mb(cls, instance: MIO, in_or_out: int = 1): diff --git a/apps/wpm/services.py b/apps/wpm/services.py index 604a9caa..7db7bd48 100644 --- a/apps/wpm/services.py +++ b/apps/wpm/services.py @@ -3,6 +3,9 @@ import datetime from django.core.cache import cache from django.db.models import Sum from django.utils.timezone import localtime +from django.core.exceptions import ObjectDoesNotExist + +from rest_framework.exceptions import ParseError from apps.inm.models import MIO, MIOItem from apps.mtm.models import Mgroup, Shift @@ -52,12 +55,12 @@ def get_pcoal_heat(year_s: int, month_s: int, day_s: int): return 0 -def pick(mio: MIO): +def do_out(mio: MIO): """ 生产领料到车间 """ belong_dept = mio.belong_dept - pick_user = mio.pick_user + do_user = mio.do_user mioitems = MIOItem.objects.filter(mio=mio) for item in mioitems: wm, new_create = WMaterial.objects.get_or_create(batch=item.batch, material=item.material, @@ -65,10 +68,34 @@ def pick(mio: MIO): "batch": item.batch, "material": item.material, "count": item.count, - "create_by": pick_user, + "create_by": do_user, "belong_dept": belong_dept }) if not new_create: wm.count = wm.count + item.count - wm.update_by = pick_user + wm.update_by = do_user wm.save() + + +def do_in(mio: MIO): + """ + 生产入库 + """ + belong_dept = mio.belong_dept + do_user = mio.do_user + mioitems = MIOItem.objects.filter(mio=mio) + for item in mioitems: + try: + wm = WMaterial.objects.get( + batch=item.batch, material=item.material, belong_dept=belong_dept) + except ObjectDoesNotExist: + raise ParseError('车间物料不存在') + new_count = wm.count - item.count + if new_count > 0: + wm.count = new_count + wm.update_by = do_user + wm.save() + elif new_count == 0: + wm.delete() + else: + raise ParseError('车间物料不足')