part of sort
This commit is contained in:
parent
6dbac8bd4b
commit
664f081b9f
|
@ -39,6 +39,7 @@ ALLOWED_HOSTS = [
|
|||
CORS_ALLOWED_ORIGINS = [
|
||||
"http://localhost",
|
||||
"http://localhost:3000",
|
||||
"http://localhost:3001",
|
||||
"http://192.168.106.234:3000",
|
||||
"https://toinv.svs-tech.pro",
|
||||
]
|
||||
|
|
|
@ -29,13 +29,19 @@ class TgItemSerializer(serializers.ModelSerializer):
|
|||
|
||||
|
||||
class TgStatItemSerializer(serializers.Serializer):
|
||||
location = serializers.SerializerMethodField()
|
||||
location = serializers.SerializerMethodField(required=False)
|
||||
inv_count = serializers.IntegerField()
|
||||
tmc = serializers.SerializerMethodField()
|
||||
|
||||
def get_location(self, obj):
|
||||
queryset = Territory.objects.get(id=obj.get("location__parent"))
|
||||
serializer = TerritorySerializer(queryset)
|
||||
if not obj.get("location__parent"):
|
||||
return None
|
||||
if isinstance(obj.get("location__parent"), list):
|
||||
queryset = Territory.objects.filter(id__in=obj.get("location__parent"))
|
||||
serializer = TerritorySerializer(queryset, many=True)
|
||||
else:
|
||||
queryset = Territory.objects.get(id=obj.get("location__parent"))
|
||||
serializer = TerritorySerializer(queryset)
|
||||
|
||||
return serializer.data
|
||||
|
||||
|
@ -45,7 +51,6 @@ class TgStatItemSerializer(serializers.Serializer):
|
|||
.values("tmc__name")
|
||||
.annotate(count=Count("id"))
|
||||
)
|
||||
logger.info(queryset)
|
||||
serializer = TmcElementSerializer(queryset, many=True)
|
||||
|
||||
return serializer.data
|
||||
|
|
|
@ -129,17 +129,31 @@ class TmcStatViewset(viewsets.ViewSet):
|
|||
http_method_names = ["get"]
|
||||
|
||||
def list(self, request):
|
||||
queryset = (
|
||||
TgItem.objects.all()
|
||||
.values("location__parent")
|
||||
.annotate(
|
||||
inv_count=Count("location__parent"),
|
||||
tmc_count=Count("tmc__tmc_id", distinct=True)
|
||||
if 'type' in request.query_params and request.query_params['type'] == 'location':
|
||||
queryset = (
|
||||
TgItem.objects.all()
|
||||
.values("location__parent")
|
||||
.annotate(
|
||||
inv_count=Count("location__parent"),
|
||||
tmc_count=Count("tmc__tmc_id", distinct=True)
|
||||
)
|
||||
.annotate(
|
||||
tmc=ArrayAgg("tmc"),
|
||||
)
|
||||
)
|
||||
.annotate(
|
||||
tmc=ArrayAgg("tmc"),
|
||||
else:
|
||||
queryset = (
|
||||
TgItem.objects.all()
|
||||
.values("tmc__tmc_id")
|
||||
.annotate(
|
||||
inv_count=Count("location__parent"),
|
||||
tmc_count=Count("tmc__tmc_id", distinct=True)
|
||||
)
|
||||
.annotate(
|
||||
location__parent=ArrayAgg("location__parent"),
|
||||
tmc=ArrayAgg("tmc"),
|
||||
)
|
||||
)
|
||||
)
|
||||
logger.info(queryset)
|
||||
# logger.info(queryset)
|
||||
serializer = TgStatItemSerializer(queryset, many=True)
|
||||
return Response(serializer.data)
|
||||
|
|
|
@ -10,10 +10,12 @@
|
|||
"@nuxt/image": "^1.7.0",
|
||||
"@nuxt/ui": "^2.16.0",
|
||||
"@pinia/nuxt": "^0.5.1",
|
||||
"chart.js": "^3.9.1",
|
||||
"nuxt": "^3.11.2",
|
||||
"nuxt-svgo": "^4.0.1",
|
||||
"pinia": "^2.1.7",
|
||||
"vue": "^3.4.27",
|
||||
"vue-chart-3": "^3.1.8",
|
||||
"vue-router": "^4.3.2",
|
||||
"vue3-telegram-login": "^1.1.0",
|
||||
"yup": "^1.4.0"
|
||||
|
@ -5114,6 +5116,12 @@
|
|||
"node": ">=0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/chart.js": {
|
||||
"version": "3.9.1",
|
||||
"resolved": "https://registry.npmjs.org/chart.js/-/chart.js-3.9.1.tgz",
|
||||
"integrity": "sha512-Ro2JbLmvg83gXF5F4sniaQ+lTbSv18E+TIf2cOeiH1Iqd2PGFOtem+DUufMZsCJwFE7ywPOpfXFBwRTGq7dh6w==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/chokidar": {
|
||||
"version": "3.6.0",
|
||||
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz",
|
||||
|
@ -12545,6 +12553,22 @@
|
|||
"ufo": "^1.5.3"
|
||||
}
|
||||
},
|
||||
"node_modules/vue-chart-3": {
|
||||
"version": "3.1.8",
|
||||
"resolved": "https://registry.npmjs.org/vue-chart-3/-/vue-chart-3-3.1.8.tgz",
|
||||
"integrity": "sha512-zX5ajjQi/PocEqLETlej3vp92q/tnI/Fvu2RVb++Kap8qOrXu6PXCpodi73BFrWzEGZIAnqoUxC3OIkRWD657g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@vue/runtime-core": "latest",
|
||||
"@vue/runtime-dom": "latest",
|
||||
"csstype": "latest",
|
||||
"lodash-es": "latest"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"chart.js": "=> ^3.1.0",
|
||||
"vue": ">= 3"
|
||||
}
|
||||
},
|
||||
"node_modules/vue-devtools-stub": {
|
||||
"version": "0.1.0",
|
||||
"resolved": "https://registry.npmjs.org/vue-devtools-stub/-/vue-devtools-stub-0.1.0.tgz",
|
||||
|
|
|
@ -19,9 +19,11 @@
|
|||
"vue": "^3.4.27",
|
||||
"vue-router": "^4.3.2",
|
||||
"vue3-telegram-login": "^1.1.0",
|
||||
"yup": "^1.4.0"
|
||||
"yup": "^1.4.0",
|
||||
"chart.js": "^3.9.1",
|
||||
"vue-chart-3": "^3.1.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"sass": "^1.77.2"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,8 @@
|
|||
<script setup lang="ts">
|
||||
const data = await apiCall<RootObject[]>(`stat/`, 'get')
|
||||
const isOrg = ref(true)
|
||||
const data = ref([] as RootObject[])
|
||||
data.value = await apiCall<RootObject[]>(`stat/?type=location`, 'get')
|
||||
|
||||
interface RootObject {
|
||||
location: Location;
|
||||
inv_count: number;
|
||||
|
@ -13,17 +16,35 @@ interface Location {
|
|||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
const getData = async () => {
|
||||
isOrg.value = !isOrg.value
|
||||
data.value = []
|
||||
data.value = await apiCall<RootObject[]>(`stat/${isOrg.value == true ? '?type=location' : ''}`, 'get')
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<div class="grid grid-cols-12 gap-4">
|
||||
<div class="col-span-12 page-header">
|
||||
<h1>Результаты инвентаризации</h1>
|
||||
</div>
|
||||
<UCard v-for="item in data" class="col-span-4">
|
||||
<div class="col-span-12">
|
||||
<UButtonGroup>
|
||||
<UButton :disabled="isOrg" @click="getData">По организациям</UButton>
|
||||
<UButton :disabled="!isOrg" @click="getData">По продуктам</UButton>
|
||||
</UButtonGroup>
|
||||
</div>
|
||||
<UCard v-for="item in data" class="col-span-4" v-if="data && isOrg">
|
||||
<template #header>
|
||||
{{ item.location.name }} <UBadge>{{ item.inv_count }}</UBadge>
|
||||
</template>
|
||||
<UTable :rows="item.tmc" />
|
||||
</UCard>
|
||||
<UCard v-for="item in data" class="col-span-6" v-if="data && !isOrg">
|
||||
<template #header>
|
||||
{{ item.tmc[0].tmc__name }} <UBadge>{{ item.tmc[0].count }}</UBadge>
|
||||
</template>
|
||||
<UTable :rows="item.location" />
|
||||
</UCard>
|
||||
</div>
|
||||
</template>
|
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"name": "to_inventory",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {}
|
||||
}
|
Loading…
Reference in New Issue