feat: ftestwork增加是否更新库存字段
This commit is contained in:
parent
40b012b962
commit
fc2195eba1
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.2.12 on 2024-09-02 07:27
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('qm', '0022_ftestwork_count_sampling_ok'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='ftestwork',
|
||||
name='need_update_wm',
|
||||
field=models.BooleanField(default=True, verbose_name='是否更新车间库存'),
|
||||
),
|
||||
]
|
|
@ -122,6 +122,7 @@ class FtestWork(CommonBDModel):
|
|||
count_sampling_ok = models.IntegerField('抽检合格数量', default=0)
|
||||
count_ok = models.IntegerField('合格数量', default=0)
|
||||
count_notok = models.IntegerField('不合格数量', default=0)
|
||||
need_update_wm = models.BooleanField('是否更新车间库存', default=True)
|
||||
count_notok_json = models.JSONField('不合格项数量统计', default=dict, null=False, blank=True)
|
||||
test_user = models.ForeignKey(
|
||||
User, verbose_name='操作人', on_delete=models.CASCADE, related_name='ftestwork_test_user', null=True, blank=True)
|
||||
|
|
|
@ -63,7 +63,7 @@ class QuaStatUpdateSerializer(CustomModelSerializer):
|
|||
class FtestWorkCreateUpdateSerializer(CustomModelSerializer):
|
||||
class Meta:
|
||||
model = FtestWork
|
||||
fields = ['id', 'wm', 'mb', 'type', 'type2', 'test_date', 'count', 'count_sampling', 'count_ok', 'count_notok', 'count_notok_json', 'test_user']
|
||||
fields = ['id', 'wm', 'mb', 'type', 'type2', 'test_date', 'count', 'count_sampling', 'count_ok', 'count_notok', 'count_notok_json', 'test_user', 'need_update_wm']
|
||||
extra_kwargs = {'test_user': {'required': True}, 'type': {'required': True}}
|
||||
|
||||
def validate(self, attrs):
|
||||
|
|
|
@ -7,67 +7,68 @@ from django.utils import timezone
|
|||
|
||||
def ftestwork_submit(ins:FtestWork, user: User):
|
||||
wm:WMaterial = ins.wm
|
||||
if wm.state == WMaterial.WM_TEST:
|
||||
# 更新对应的车间库存
|
||||
wm.count = wm.count - ins.count
|
||||
if wm.count >= 0:
|
||||
# 已检测的数量
|
||||
wm.count_xtest = wm.count_xtest + ins.count
|
||||
wm.save()
|
||||
else:
|
||||
raise ParseError("超过待检数量")
|
||||
# 生成合格的
|
||||
count_ok = ins.count_ok
|
||||
if count_ok > 0:
|
||||
wm, new_create = WMaterial.objects.get_or_create(
|
||||
material=wm.material,
|
||||
batch=wm.batch,
|
||||
mgroup=wm.mgroup,
|
||||
belong_dept=wm.belong_dept,
|
||||
state=WMaterial.WM_OK,
|
||||
defaults={
|
||||
'count': count_ok,
|
||||
'material': wm.material,
|
||||
'batch': wm.batch,
|
||||
'mgroup': wm.mgroup,
|
||||
'belong_dept': wm.belong_dept,
|
||||
}
|
||||
)
|
||||
if not new_create:
|
||||
wm.count = wm.count + count_ok
|
||||
if ins.need_update_wm:
|
||||
if wm.state == WMaterial.WM_TEST:
|
||||
# 更新对应的车间库存
|
||||
wm.count = wm.count - ins.count
|
||||
if wm.count >= 0:
|
||||
# 已检测的数量
|
||||
wm.count_xtest = wm.count_xtest + ins.count
|
||||
wm.save()
|
||||
else:
|
||||
wm.count = wm.count - ins.count_notok
|
||||
if wm.count >= 0:
|
||||
wm.save()
|
||||
else:
|
||||
raise ParseError("超过待检数量")
|
||||
# 生成合格的
|
||||
count_ok = ins.count_ok
|
||||
if count_ok > 0:
|
||||
wm, new_create = WMaterial.objects.get_or_create(
|
||||
material=wm.material,
|
||||
batch=wm.batch,
|
||||
mgroup=wm.mgroup,
|
||||
belong_dept=wm.belong_dept,
|
||||
state=WMaterial.WM_OK,
|
||||
defaults={
|
||||
'count': count_ok,
|
||||
'material': wm.material,
|
||||
'batch': wm.batch,
|
||||
'mgroup': wm.mgroup,
|
||||
'belong_dept': wm.belong_dept,
|
||||
}
|
||||
)
|
||||
if not new_create:
|
||||
wm.count = wm.count + count_ok
|
||||
wm.save()
|
||||
else:
|
||||
raise ParseError("不合格数不可大于批次数量")
|
||||
|
||||
# 生成不合格的
|
||||
count_notok_json = ins.count_notok_json
|
||||
for k, v in count_notok_json.items():
|
||||
if v > 0:
|
||||
notok_sign = k.replace('count_n_', '')
|
||||
wm_n, new_create = WMaterial.objects.get_or_create(
|
||||
material=wm.material,
|
||||
batch=wm.batch,
|
||||
mgroup=wm.mgroup,
|
||||
belong_dept=wm.belong_dept,
|
||||
notok_sign=notok_sign,
|
||||
state=WMaterial.WM_NOTOK,
|
||||
defaults={
|
||||
'count': v,
|
||||
'material': wm.material,
|
||||
'batch': wm.batch,
|
||||
'mgroup': wm.mgroup,
|
||||
'belong_dept': wm.belong_dept,
|
||||
'notok_sign': notok_sign,
|
||||
'state': WMaterial.WM_NOTOK,
|
||||
}
|
||||
)
|
||||
if not new_create:
|
||||
wm_n.count = wm_n.count + v
|
||||
wm_n.save()
|
||||
wm.count = wm.count - ins.count_notok
|
||||
if wm.count >= 0:
|
||||
wm.save()
|
||||
else:
|
||||
raise ParseError("不合格数不可大于批次数量")
|
||||
|
||||
# 生成不合格的
|
||||
count_notok_json = ins.count_notok_json
|
||||
for k, v in count_notok_json.items():
|
||||
if v > 0:
|
||||
notok_sign = k.replace('count_n_', '')
|
||||
wm_n, new_create = WMaterial.objects.get_or_create(
|
||||
material=wm.material,
|
||||
batch=wm.batch,
|
||||
mgroup=wm.mgroup,
|
||||
belong_dept=wm.belong_dept,
|
||||
notok_sign=notok_sign,
|
||||
state=WMaterial.WM_NOTOK,
|
||||
defaults={
|
||||
'count': v,
|
||||
'material': wm.material,
|
||||
'batch': wm.batch,
|
||||
'mgroup': wm.mgroup,
|
||||
'belong_dept': wm.belong_dept,
|
||||
'notok_sign': notok_sign,
|
||||
'state': WMaterial.WM_NOTOK,
|
||||
}
|
||||
)
|
||||
if not new_create:
|
||||
wm_n.count = wm_n.count + v
|
||||
wm_n.save()
|
||||
ins.submit_user = user
|
||||
ins.submit_time = timezone.now()
|
||||
ins.save()
|
Loading…
Reference in New Issue