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_sampling_ok = models.IntegerField('抽检合格数量', default=0)
|
||||||
count_ok = models.IntegerField('合格数量', default=0)
|
count_ok = models.IntegerField('合格数量', default=0)
|
||||||
count_notok = 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)
|
count_notok_json = models.JSONField('不合格项数量统计', default=dict, null=False, blank=True)
|
||||||
test_user = models.ForeignKey(
|
test_user = models.ForeignKey(
|
||||||
User, verbose_name='操作人', on_delete=models.CASCADE, related_name='ftestwork_test_user', null=True, blank=True)
|
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 FtestWorkCreateUpdateSerializer(CustomModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = FtestWork
|
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}}
|
extra_kwargs = {'test_user': {'required': True}, 'type': {'required': True}}
|
||||||
|
|
||||||
def validate(self, attrs):
|
def validate(self, attrs):
|
||||||
|
|
|
@ -7,67 +7,68 @@ from django.utils import timezone
|
||||||
|
|
||||||
def ftestwork_submit(ins:FtestWork, user: User):
|
def ftestwork_submit(ins:FtestWork, user: User):
|
||||||
wm:WMaterial = ins.wm
|
wm:WMaterial = ins.wm
|
||||||
if wm.state == WMaterial.WM_TEST:
|
if ins.need_update_wm:
|
||||||
# 更新对应的车间库存
|
if wm.state == WMaterial.WM_TEST:
|
||||||
wm.count = wm.count - ins.count
|
# 更新对应的车间库存
|
||||||
if wm.count >= 0:
|
wm.count = wm.count - ins.count
|
||||||
# 已检测的数量
|
if wm.count >= 0:
|
||||||
wm.count_xtest = wm.count_xtest + ins.count
|
# 已检测的数量
|
||||||
wm.save()
|
wm.count_xtest = wm.count_xtest + ins.count
|
||||||
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()
|
wm.save()
|
||||||
else:
|
else:
|
||||||
wm.count = wm.count - ins.count_notok
|
raise ParseError("超过待检数量")
|
||||||
if wm.count >= 0:
|
# 生成合格的
|
||||||
wm.save()
|
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:
|
else:
|
||||||
raise ParseError("不合格数不可大于批次数量")
|
wm.count = wm.count - ins.count_notok
|
||||||
|
if wm.count >= 0:
|
||||||
# 生成不合格的
|
wm.save()
|
||||||
count_notok_json = ins.count_notok_json
|
else:
|
||||||
for k, v in count_notok_json.items():
|
raise ParseError("不合格数不可大于批次数量")
|
||||||
if v > 0:
|
|
||||||
notok_sign = k.replace('count_n_', '')
|
# 生成不合格的
|
||||||
wm_n, new_create = WMaterial.objects.get_or_create(
|
count_notok_json = ins.count_notok_json
|
||||||
material=wm.material,
|
for k, v in count_notok_json.items():
|
||||||
batch=wm.batch,
|
if v > 0:
|
||||||
mgroup=wm.mgroup,
|
notok_sign = k.replace('count_n_', '')
|
||||||
belong_dept=wm.belong_dept,
|
wm_n, new_create = WMaterial.objects.get_or_create(
|
||||||
notok_sign=notok_sign,
|
material=wm.material,
|
||||||
state=WMaterial.WM_NOTOK,
|
batch=wm.batch,
|
||||||
defaults={
|
mgroup=wm.mgroup,
|
||||||
'count': v,
|
belong_dept=wm.belong_dept,
|
||||||
'material': wm.material,
|
notok_sign=notok_sign,
|
||||||
'batch': wm.batch,
|
state=WMaterial.WM_NOTOK,
|
||||||
'mgroup': wm.mgroup,
|
defaults={
|
||||||
'belong_dept': wm.belong_dept,
|
'count': v,
|
||||||
'notok_sign': notok_sign,
|
'material': wm.material,
|
||||||
'state': WMaterial.WM_NOTOK,
|
'batch': wm.batch,
|
||||||
}
|
'mgroup': wm.mgroup,
|
||||||
)
|
'belong_dept': wm.belong_dept,
|
||||||
if not new_create:
|
'notok_sign': notok_sign,
|
||||||
wm_n.count = wm_n.count + v
|
'state': WMaterial.WM_NOTOK,
|
||||||
wm_n.save()
|
}
|
||||||
|
)
|
||||||
|
if not new_create:
|
||||||
|
wm_n.count = wm_n.count + v
|
||||||
|
wm_n.save()
|
||||||
ins.submit_user = user
|
ins.submit_user = user
|
||||||
ins.submit_time = timezone.now()
|
ins.submit_time = timezone.now()
|
||||||
ins.save()
|
ins.save()
|
Loading…
Reference in New Issue