fix - showing my devices

This commit is contained in:
2025-12-17 16:08:45 +03:30
parent 34aac97eaa
commit 6e0c7d14c9
7 changed files with 58 additions and 5 deletions

View File

@@ -14,7 +14,7 @@
</component>
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.9 (dam_env)" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Python 3.10 (env)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">

2
.idea/misc.xml generated
View File

@@ -3,5 +3,5 @@
<component name="Black">
<option name="sdkName" value="Python 3.10 (env)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (dam_env)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (env)" project-jdk-type="Python SDK" />
</project>

View File

@@ -0,0 +1,25 @@
from django.core.management.base import BaseCommand
from apps.warehouse.models import InventoryQuotaSaleTransaction
class Command(BaseCommand):
help = "Fix Ranchers FullName on Transactions"
def handle(self, *args, **kwargs):
self.stdout.write("🔄 Bulk updating ranchers...")
trans_list = []
transactions = InventoryQuotaSaleTransaction.objects.all()
for trans in transactions:
if trans.rancher:
trans.rancher_fullname = trans.rancher.first_name + " " + trans.rancher.last_name if trans.rancher.last_name else ""
print(trans.rancher_fullname)
trans_list.append(trans)
self.stdout.write(" Bulk updating ranchers started...")
InventoryQuotaSaleTransaction.objects.bulk_update(trans_list, fields=['rancher_fullname'])
self.stdout.write(self.style.SUCCESS(
f"✅ Done! {0} set to True, {0} set to False"
))

View File

@@ -0,0 +1,28 @@
from django.core.management.base import BaseCommand
from apps.herd.models import Rancher
class Command(BaseCommand):
help = "Fix Ranchers FirstName & LastName On Ranching Farm"
def handle(self, *args, **kwargs):
self.stdout.write("🔄 Bulk updating ranchers...")
ranchers_list = []
ranchers = Rancher.objects.all()
for rancher in ranchers:
if rancher.ranching_farm:
if not rancher.first_name or not rancher.last_name:
split_ranching_farm = rancher.ranching_farm.split(" ")
rancher.first_name = split_ranching_farm[0]
rancher.last_name = " ".join(split_ranching_farm[1:]) if len(split_ranching_farm) >= 2 else None
ranchers_list.append(rancher)
print(rancher.first_name, "--->", rancher.last_name)
self.stdout.write(" Bulk updating ranchers started...")
Rancher.objects.bulk_update(ranchers_list, fields=['first_name', 'last_name'])
self.stdout.write(self.style.SUCCESS(
f"✅ Done! {0} set to True, {0} set to False"
))

View File

@@ -133,7 +133,6 @@ def agency_organization_pos_info(
"agency": True,
"default_account": True
})
return pos_sharing_list
return None
return None

View File

@@ -113,12 +113,12 @@ class DeviceViewSet(BaseViewSet, SoftDeleteMixin, viewsets.ModelViewSet, AdminFi
organization = get_organization_by_user(request.user)
devices = self.get_queryset(
visibility_by_org_scope=True
) if organization.free_visibility_by_scope else self.get_queryset()
)
# filter by Jihad & admin of system
if organization.type.key == 'J':
queryset = devices.filter(assignment__client__organization__province=organization.province)
elif not organization.type.key == 'ADM':
elif organization.type.key == 'PSP':
queryset = apply_visibility_filter_by_org_type(devices, organization)
else:
queryset = devices

View File

@@ -27,6 +27,7 @@ def quota_live_stock_allocation_info(quota: Quota) -> typing.Any:
""" information of quota live stock allocations """
allocations = quota.livestock_allocations.select_related('livestock_type')
print(allocations)
if allocations:
allocations_list = [{