feat: 生产入库后变更车间物料

This commit is contained in:
caoqianming 2023-09-28 09:22:37 +08:00
parent f13de6b2c5
commit 9ebf15b04f
2 changed files with 35 additions and 6 deletions

View File

@ -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):

View File

@ -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('车间物料不足')