feat: 混料支持车间库存
This commit is contained in:
parent
f6db92f815
commit
4c3610ac25
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.2.12 on 2024-03-06 08:43
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('wpm', '0040_mlog_count_n_xzp'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='wmaterial',
|
||||
name='count_eweight',
|
||||
field=models.FloatField(default=0, verbose_name='单数重量'),
|
||||
),
|
||||
]
|
|
@ -83,6 +83,7 @@ class WMaterial(CommonBDModel):
|
|||
Material, verbose_name='物料', on_delete=models.CASCADE)
|
||||
batch = models.CharField('批次号', max_length=50)
|
||||
count = models.PositiveIntegerField('当前数量', default=0)
|
||||
count_eweight = models.FloatField('单数重量', default=0)
|
||||
|
||||
class Meta:
|
||||
unique_together = ('material', 'batch', 'belong_dept')
|
||||
|
|
|
@ -191,12 +191,15 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
|||
'batch': mlog.batch, 'material': item.material_out, 'belong_dept': belong_dept
|
||||
})
|
||||
wmaterial.count = wmaterial.count + item.count_ok
|
||||
if hasattr(item, 'count_real_eweight'):
|
||||
wmaterial.count_eweight = item.count_real_eweight
|
||||
wmaterial.save()
|
||||
else:
|
||||
wmaterial, _ = WMaterial.objects.get_or_create(batch=mlog.batch, material=material_out, belong_dept=belong_dept, defaults={
|
||||
'batch': mlog.batch, 'material': material_out, 'belong_dept': belong_dept
|
||||
})
|
||||
wmaterial.count = wmaterial.count + mlog.count_ok
|
||||
wmaterial.count_eweight = mlog.count_real_eweight
|
||||
wmaterial.save()
|
||||
mlog.submit_time = now
|
||||
mlog.submit_user = user
|
||||
|
@ -279,7 +282,10 @@ def handover_submit(handover: Handover, user: User, now: Union[datetime.datetime
|
|||
return
|
||||
now = timezone.now()
|
||||
if handover.wm:
|
||||
wm = handover.wm
|
||||
wm: WMaterial = handover.wm
|
||||
need_add = True
|
||||
if '混料' in wm.material.name:
|
||||
need_add = False
|
||||
count_x = wm.count - handover.count
|
||||
if count_x < 0:
|
||||
raise ParseError('车间库存不足!')
|
||||
|
@ -288,11 +294,12 @@ def handover_submit(handover: Handover, user: User, now: Union[datetime.datetime
|
|||
else:
|
||||
wm.count = count_x
|
||||
wm.save()
|
||||
wm_to, _ = WMaterial.objects.get_or_create(batch=handover.batch, material=handover.material, belong_dept=handover.send_dept, defaults={
|
||||
'batch': handover.batch, 'material': handover.material, 'belong_dept': handover.send_dept
|
||||
})
|
||||
wm_to.count = wm_to.count + handover.count
|
||||
wm_to.save()
|
||||
if need_add:
|
||||
wm_to, _ = WMaterial.objects.get_or_create(batch=handover.batch, material=handover.material, belong_dept=handover.send_dept, defaults={
|
||||
'batch': handover.batch, 'material': handover.material, 'belong_dept': handover.send_dept
|
||||
})
|
||||
wm_to.count = wm_to.count + handover.count
|
||||
wm_to.save()
|
||||
handover.submit_user = user
|
||||
handover.submit_time = now
|
||||
handover.save()
|
||||
|
|
Loading…
Reference in New Issue