feat: mlog返回子级详情
This commit is contained in:
parent
8a61ca9eb1
commit
9c69711f38
|
@ -188,6 +188,11 @@ class MlogViewSet(CustomModelViewSet):
|
|||
data["oinfo_json_"] = {czx_dict.get(k, k): v for k, v in data.get("oinfo_json", {}).items()}
|
||||
return data
|
||||
|
||||
def get_serializer_class(self):
|
||||
if self.request.query_params.get('with_mlogb', False):
|
||||
return MlogSerializer
|
||||
return super().get_serializer_class()
|
||||
|
||||
def add_info_for_list(self, data):
|
||||
czx_dict = {}
|
||||
for item in data:
|
||||
|
@ -196,17 +201,17 @@ class MlogViewSet(CustomModelViewSet):
|
|||
for item in data:
|
||||
if item.get("oinfo_json", None):
|
||||
item["oinfo_json_"] = {czx_dict.get(k, k): v for k, v in item.get("oinfo_json", {}).items()}
|
||||
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")
|
||||
mlogb_data = MlogbSerializer(instance=mlogb_qs, many=True).data
|
||||
for item in mlogb_data:
|
||||
item_dict = convert_ordereddict(item)
|
||||
if item_dict["mlog"] in data_dict:
|
||||
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)
|
||||
data = list(data_dict.values())
|
||||
# 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")
|
||||
# mlogb_data = MlogbDetailSerializer(instance=mlogb_qs, many=True).data
|
||||
# for item in mlogb_data:
|
||||
# item_dict = convert_ordereddict(item)
|
||||
# if item_dict["mlog"] in data_dict:
|
||||
# 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)
|
||||
# data = list(data_dict.values())
|
||||
return data
|
||||
|
||||
@transaction.atomic
|
||||
|
|
Loading…
Reference in New Issue