Compare commits
No commits in common. "5709bc3a474611aacf835fb590e5b220a2c9f475" and "e7ea16ece6c138c64343cd358dc79715a7e681ec" have entirely different histories.
5709bc3a47
...
e7ea16ece6
|
|
@ -1107,9 +1107,6 @@ class MlogbOutUpdateSerializer(CustomModelSerializer):
|
|||
return ins
|
||||
|
||||
def validate(self, attrs):
|
||||
mlog: Mlog = attrs.get("mlog")
|
||||
if mlog.submit_time is not None:
|
||||
raise ParseError('生产日志已提交不可编辑')
|
||||
mlogbdefect = attrs.get("mlogbdefect", [])
|
||||
if mlogbdefect:
|
||||
attrs.pop("count_notok_json", None)
|
||||
|
|
|
|||
|
|
@ -206,13 +206,6 @@ class MlogViewSet(CustomModelViewSet):
|
|||
data["oinfo_json_"] = {czx_dict.get(k, k): v for k, v in data.get("oinfo_json", {}).items()}
|
||||
return data
|
||||
|
||||
@classmethod
|
||||
def lock_and_check_can_update(cls, mlog:Mlog):
|
||||
mlog_lock:Mlog = Mlog.objects.select_for_update(id=mlog.id)
|
||||
if mlog_lock.submit_time is not None:
|
||||
raise ParseError("该记录已提交无法更改")
|
||||
|
||||
|
||||
def get_serializer_class(self):
|
||||
if self.request.query_params.get('with_mlogb', False):
|
||||
return MlogSerializer
|
||||
|
|
@ -696,13 +689,12 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust
|
|||
|
||||
def perform_destroy(self, instance):
|
||||
ins: Mlogb = instance
|
||||
MlogViewSet.lock_and_check_can_update(ins.mlog)
|
||||
if ins.mlog.submit_time is not None:
|
||||
raise ParseError('生产日志已提交不可编辑')
|
||||
ins.delete()
|
||||
ins.mlog.cal_mlog_count_from_mlogb()
|
||||
|
||||
def perform_update(self, serializer):
|
||||
ins:Mlogb = serializer.instance
|
||||
MlogViewSet.lock_and_check_can_update(ins.mlog)
|
||||
ins:Mlogb = serializer.save()
|
||||
ins.mlog.cal_mlog_count_from_mlogb()
|
||||
|
||||
|
|
@ -871,7 +863,6 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust
|
|||
|
||||
def perform_create(self, serializer):
|
||||
mlogbin: Mlogb = serializer.save()
|
||||
MlogViewSet.lock_and_check_can_update(mlogbin.mlog)
|
||||
MlogbInViewSet.p_create_after(mlogbin)
|
||||
|
||||
@classmethod
|
||||
|
|
@ -912,8 +903,6 @@ class MlogbOutViewSet(UpdateModelMixin, CustomGenericViewSet):
|
|||
serializer_class = MlogbOutUpdateSerializer
|
||||
|
||||
def perform_update(self, serializer):
|
||||
ins:Mlogb = serializer.instance
|
||||
MlogViewSet.lock_and_check_can_update(ins.mlog)
|
||||
material_out = serializer.validated_data.get('material_out')
|
||||
if material_out and material_out.tracking == Material.MA_TRACKING_SINGLE:
|
||||
raise ParseError("单件产品不支持直接修改")
|
||||
|
|
@ -979,16 +968,12 @@ class MlogbwViewSet(CustomModelViewSet):
|
|||
insx = ins
|
||||
else:
|
||||
insx = [ins]
|
||||
checked = False
|
||||
for ins in insx:
|
||||
if mlog is None:
|
||||
mlog = ins.mlogb.mlog
|
||||
else:
|
||||
if mlog != ins.mlogb.mlog:
|
||||
raise ParseError("所有记录必须属于同一张日志")
|
||||
if not checked:
|
||||
MlogViewSet.lock_and_check_can_update(mlog)
|
||||
checked = True
|
||||
wpr:Wpr = ins.wpr
|
||||
mlogb:Mlogb = ins.mlogb
|
||||
if wpr.wm != mlogb.wm_in:
|
||||
|
|
@ -1056,25 +1041,20 @@ class MlogbwViewSet(CustomModelViewSet):
|
|||
if isinstance(mlogbw, list):
|
||||
pass
|
||||
else:
|
||||
mlog = mlogbw.mlogb.mlog
|
||||
MlogViewSet.lock_and_check_can_update(mlog)
|
||||
Mlogbw.cal_count_notok(mlogbw.mlogb)
|
||||
|
||||
mlog = mlogbw.mlogb.mlog
|
||||
mlog.cal_mlog_count_from_mlogb()
|
||||
|
||||
def after_bulk_update(self, objs):
|
||||
mlogbIds = list(set([obj["mlogb"] for obj in objs]))
|
||||
for mlogbId in mlogbIds:
|
||||
mlogb = Mlogb.objects.get(id=mlogbId)
|
||||
mlog = mlogb.mlog
|
||||
MlogViewSet.lock_and_check_can_update(mlog)
|
||||
Mlogbw.cal_count_notok(mlogb)
|
||||
|
||||
mlog = mlogb.mlog
|
||||
mlog.cal_mlog_count_from_mlogb()
|
||||
|
||||
def perform_destroy(self, instance:Mlogbw):
|
||||
mlogb:Mlogb = instance.mlogb
|
||||
MlogViewSet.lock_and_check_can_update(mlogb.mlog)
|
||||
if mlogb.material_out is not None and instance.wpr is not None:
|
||||
raise ParseError("不能删除该产出明细")
|
||||
|
||||
|
|
@ -1125,7 +1105,8 @@ class MlogUserViewSet(BulkCreateModelMixin, ListModelMixin, DestroyModelMixin, C
|
|||
|
||||
def perform_destroy(self, instance):
|
||||
mlog:Mlog = instance.mlog
|
||||
MlogViewSet.lock_and_check_can_update(mlog)
|
||||
if mlog.submit_time is not None:
|
||||
raise ParseError("不能删除该记录")
|
||||
return super().perform_destroy(instance)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue