fix: FmlogViewSet test

This commit is contained in:
caoqianming 2025-03-03 19:09:17 +08:00
parent eca0f26623
commit 46d586430e
1 changed files with 5 additions and 2 deletions

View File

@ -182,6 +182,9 @@ class MlogViewSet(CustomModelViewSet):
'material_out__name', 'material_out__number', 'material_out__specification', 'material_out__model',]
def add_info_for_list(self, data):
czx_dict = {}
for item in data:
czx_dict.update(item.get("oinfo_json", {}))
if self.request.query_params.get('with_mlogb', False):
data_dict = {item['id']: {**item, "mlogb_full": [], "mlogb": []} for item in data}
mlogb_qs = Mlogb.objects.filter(mlog__id__in=data_dict.keys()).select_related("material_in", "material_out").order_by("create_time")
@ -192,7 +195,7 @@ class MlogViewSet(CustomModelViewSet):
data_dict[item_dict["mlog"]]["mlogb_full"].append(item_dict)
if item.get("material_out", None):
data_dict[item_dict["mlog"]]["mlogb"].append(item_dict)
return list(data_dict.values())
data = list(data_dict.values())
return data
@transaction.atomic
@ -628,7 +631,7 @@ class MlogbOutViewSet(UpdateModelMixin, CustomGenericViewSet):
serializer_class = MlogbOutUpdateSerializer
class FmlogViewSet(CustomListModelMixin, BulkCreateModelMixin, BulkDestroyModelMixin, CustomGenericViewSet):
class FmlogViewSet(CustomModelViewSet):
perms_map = {'get': '*', 'post': 'mlog.create', 'put': 'mlog.update', 'delete': 'mlog.delete'}
queryset = Fmlog.objects.all()
serializer_class = FmlogSerializer