fix(wpm): allow qualified and grade b batch merges
This commit is contained in:
parent
fd4de2bd4b
commit
d98b7fada2
|
|
@ -1419,7 +1419,6 @@ class HandoverSerializer(CustomModelSerializer):
|
||||||
next_mat = None
|
next_mat = None
|
||||||
next_state = None
|
next_state = None
|
||||||
next_defect = None
|
next_defect = None
|
||||||
next_defect_grade = None
|
|
||||||
if new_wm and attrs["type"] != Handover.H_CHANGE:
|
if new_wm and attrs["type"] != Handover.H_CHANGE:
|
||||||
next_mat = new_wm.material
|
next_mat = new_wm.material
|
||||||
next_state = new_wm.state
|
next_state = new_wm.state
|
||||||
|
|
@ -1440,15 +1439,10 @@ class HandoverSerializer(CustomModelSerializer):
|
||||||
if clear_defect and new_wm is not None and new_wm.defect is not None:
|
if clear_defect and new_wm is not None and new_wm.defect is not None:
|
||||||
raise ParseError('清除批次缺陷时目标批次不能带缺陷')
|
raise ParseError('清除批次缺陷时目标批次不能带缺陷')
|
||||||
if clear_defect and tracking == Material.MA_TRACKING_BATCH:
|
if clear_defect and tracking == Material.MA_TRACKING_BATCH:
|
||||||
if wm.defect is None:
|
defect_grade = effective_defect_grade(wm, "notok_sign")
|
||||||
|
if defect_grade not in [Defect.DEFECT_OK, Defect.DEFECT_OK_B]:
|
||||||
raise ParseError(
|
raise ParseError(
|
||||||
f'第{ind+1}行-批次追踪物料仅同缺陷等级可清除批次缺陷'
|
f'第{ind+1}行-批次追踪物料仅合格品和合格B类可清除批次缺陷'
|
||||||
)
|
|
||||||
if next_defect_grade is None:
|
|
||||||
next_defect_grade = wm.defect.okcate
|
|
||||||
elif next_defect_grade != wm.defect.okcate:
|
|
||||||
raise ParseError(
|
|
||||||
f'第{ind+1}行-批次追踪物料仅同缺陷等级可清除批次缺陷'
|
|
||||||
)
|
)
|
||||||
if next_mat is None:
|
if next_mat is None:
|
||||||
next_mat = wm.material
|
next_mat = wm.material
|
||||||
|
|
|
||||||
|
|
@ -507,7 +507,34 @@ class WMaterialScopeTests(SimpleTestCase):
|
||||||
self.assertTrue(validated["clear_defect"])
|
self.assertTrue(validated["clear_defect"])
|
||||||
self.assertEqual(validated["count"], 2)
|
self.assertEqual(validated["count"], 2)
|
||||||
|
|
||||||
def test_batch_tracking_merge_can_clear_same_grade_notok_defects(self):
|
def test_batch_tracking_merge_can_clear_ok_and_ok_b_defects(self):
|
||||||
|
material = Material(tracking=Material.MA_TRACKING_BATCH)
|
||||||
|
defect_b = Defect(id="1", okcate=Defect.DEFECT_OK_B)
|
||||||
|
wm_ok = WMaterial(
|
||||||
|
id="10", material=material, batch="OK-001", count=1,
|
||||||
|
state=WMaterial.WM_OK, defect=None,
|
||||||
|
)
|
||||||
|
wm_b = WMaterial(
|
||||||
|
id="20", material=material, batch="B-001", count=1,
|
||||||
|
state=WMaterial.WM_OK, defect=defect_b,
|
||||||
|
)
|
||||||
|
|
||||||
|
validated = HandoverSerializer().validate({
|
||||||
|
"wm": wm_ok,
|
||||||
|
"handoverb": [
|
||||||
|
{"wm": wm_ok, "count": 1},
|
||||||
|
{"wm": wm_b, "count": 1},
|
||||||
|
],
|
||||||
|
"new_batch": "OK-MERGED",
|
||||||
|
"clear_defect": True,
|
||||||
|
"type": Handover.H_NORMAL,
|
||||||
|
"mtype": Handover.H_MERGE,
|
||||||
|
})
|
||||||
|
|
||||||
|
self.assertTrue(validated["clear_defect"])
|
||||||
|
self.assertEqual(validated["count"], 2)
|
||||||
|
|
||||||
|
def test_batch_tracking_merge_cannot_clear_same_grade_notok_defects(self):
|
||||||
material = Material(tracking=Material.MA_TRACKING_BATCH)
|
material = Material(tracking=Material.MA_TRACKING_BATCH)
|
||||||
defect_a = Defect(id="1", okcate=Defect.DEFECT_NOTOK)
|
defect_a = Defect(id="1", okcate=Defect.DEFECT_NOTOK)
|
||||||
defect_b = Defect(id="2", okcate=Defect.DEFECT_NOTOK)
|
defect_b = Defect(id="2", okcate=Defect.DEFECT_NOTOK)
|
||||||
|
|
@ -520,7 +547,11 @@ class WMaterialScopeTests(SimpleTestCase):
|
||||||
state=WMaterial.WM_NOTOK, defect=defect_b,
|
state=WMaterial.WM_NOTOK, defect=defect_b,
|
||||||
)
|
)
|
||||||
|
|
||||||
validated = HandoverSerializer().validate({
|
with self.assertRaisesMessage(
|
||||||
|
ParseError,
|
||||||
|
"批次追踪物料仅合格品和合格B类可清除批次缺陷",
|
||||||
|
):
|
||||||
|
HandoverSerializer().validate({
|
||||||
"wm": wm_a,
|
"wm": wm_a,
|
||||||
"handoverb": [
|
"handoverb": [
|
||||||
{"wm": wm_a, "count": 1},
|
{"wm": wm_a, "count": 1},
|
||||||
|
|
@ -532,9 +563,6 @@ class WMaterialScopeTests(SimpleTestCase):
|
||||||
"mtype": Handover.H_MERGE,
|
"mtype": Handover.H_MERGE,
|
||||||
})
|
})
|
||||||
|
|
||||||
self.assertTrue(validated["clear_defect"])
|
|
||||||
self.assertEqual(validated["count"], 2)
|
|
||||||
|
|
||||||
def test_batch_tracking_merge_cannot_clear_mixed_defect_grades(self):
|
def test_batch_tracking_merge_cannot_clear_mixed_defect_grades(self):
|
||||||
material = Material(tracking=Material.MA_TRACKING_BATCH)
|
material = Material(tracking=Material.MA_TRACKING_BATCH)
|
||||||
defect_b = Defect(id="1", okcate=Defect.DEFECT_OK_B)
|
defect_b = Defect(id="1", okcate=Defect.DEFECT_OK_B)
|
||||||
|
|
@ -550,7 +578,7 @@ class WMaterialScopeTests(SimpleTestCase):
|
||||||
|
|
||||||
with self.assertRaisesMessage(
|
with self.assertRaisesMessage(
|
||||||
ParseError,
|
ParseError,
|
||||||
"批次追踪物料仅同缺陷等级可清除批次缺陷",
|
"批次追踪物料仅合格品和合格B类可清除批次缺陷",
|
||||||
):
|
):
|
||||||
HandoverSerializer().validate({
|
HandoverSerializer().validate({
|
||||||
"wm": wm_a,
|
"wm": wm_a,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue