Fix bulk-created individual defect IDs
This commit is contained in:
parent
074e759c29
commit
1f98b81ce3
|
|
@ -21,6 +21,7 @@ from apps.wpmw.models import Wpr, WprDefect
|
|||
from ..qm.models import Defect, Ftest
|
||||
from django.db.models import Count, Q
|
||||
from apps.utils.tasks import ctask_run
|
||||
from apps.utils.snowflake import idWorker
|
||||
from apps.mtm.models import Process, WmScope
|
||||
from django.db.models import F
|
||||
|
||||
|
|
@ -214,6 +215,7 @@ def restore_mlog_wpr_defects(mlog: Mlog):
|
|||
continue
|
||||
restored.extend(
|
||||
WprDefect(
|
||||
id=idWorker.get_id(),
|
||||
wpr=wpr,
|
||||
defect_id=item["defect_id"],
|
||||
is_main=item.get("is_main", False),
|
||||
|
|
|
|||
|
|
@ -548,6 +548,30 @@ class WMaterialScopeTests(SimpleTestCase):
|
|||
|
||||
|
||||
class WprDefectLifecycleTests(SimpleTestCase):
|
||||
@patch("apps.wpmw.models.WprDefect.objects.bulk_create")
|
||||
@patch("apps.wpmw.models.WprDefect.objects.filter")
|
||||
@patch(
|
||||
"apps.wpmw.models.idWorker.get_id",
|
||||
side_effect=["100", "101"],
|
||||
)
|
||||
def test_replace_defects_assigns_unique_ids_before_bulk_create(
|
||||
self,
|
||||
get_id,
|
||||
defect_filter,
|
||||
bulk_create,
|
||||
):
|
||||
wpr = Wpr(id="1")
|
||||
|
||||
wpr.replace_defects([
|
||||
{"defect_id": "10", "is_main": True},
|
||||
{"defect_id": "11", "is_main": False},
|
||||
])
|
||||
|
||||
defect_filter.return_value.delete.assert_called_once_with()
|
||||
created = bulk_create.call_args.args[0]
|
||||
self.assertEqual([str(item.id) for item in created], ["100", "101"])
|
||||
self.assertEqual(get_id.call_count, 2)
|
||||
|
||||
@patch("apps.wpmw.models.WprDefect.objects.filter")
|
||||
def test_change_inventory_never_changes_individual_defects(self, defect_filter):
|
||||
material = Material(id="1", tracking=Material.MA_TRACKING_SINGLE)
|
||||
|
|
@ -671,8 +695,13 @@ class MlogWprDefectSnapshotTests(SimpleTestCase):
|
|||
@patch("apps.wpm.services.WprDefect.objects.bulk_create")
|
||||
@patch("apps.wpm.services.WprDefect.objects.filter")
|
||||
@patch("apps.wpm.services.Wpr.objects.select_for_update")
|
||||
@patch(
|
||||
"apps.wpm.services.idWorker.get_id",
|
||||
side_effect=["100", "101"],
|
||||
)
|
||||
def test_restore_replaces_current_defects_exactly(
|
||||
self,
|
||||
get_id,
|
||||
select_for_update,
|
||||
defect_filter,
|
||||
bulk_create,
|
||||
|
|
@ -698,6 +727,8 @@ class MlogWprDefectSnapshotTests(SimpleTestCase):
|
|||
[(str(item.defect_id), item.is_main) for item in created],
|
||||
[("10", True), ("11", False)],
|
||||
)
|
||||
self.assertEqual([str(item.id) for item in created], ["100", "101"])
|
||||
self.assertEqual(get_id.call_count, 2)
|
||||
|
||||
|
||||
@skipUnless(
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ from apps.utils.models import BaseModel
|
|||
from apps.mtm.models import Material
|
||||
from rest_framework.exceptions import ParseError
|
||||
from apps.wpm.models import WmStateOption, Mlogbw, Handoverbw
|
||||
from apps.utils.snowflake import idWorker
|
||||
from apps.utils.tools import update_dict
|
||||
from apps.inm.models import MIOItemw
|
||||
from django.db.models import F, Value
|
||||
|
|
@ -130,6 +131,7 @@ class Wpr(BaseModel):
|
|||
WprDefect.objects.filter(wpr=self).delete()
|
||||
WprDefect.objects.bulk_create([
|
||||
WprDefect(
|
||||
id=idWorker.get_id(),
|
||||
wpr=self,
|
||||
defect_id=item["defect_id"],
|
||||
is_main=item.get("is_main", False),
|
||||
|
|
|
|||
Loading…
Reference in New Issue