set to get rancher_inventory - change serializer to check context
This commit is contained in:
18
apps/authentication/migrations/0036_organization_phone.py
Normal file
18
apps/authentication/migrations/0036_organization_phone.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.0 on 2025-08-30 06:40
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('authentication', '0035_bankaccountinformation_account_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='organization',
|
||||||
|
name='phone',
|
||||||
|
field=models.CharField(max_length=25, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -49,7 +49,6 @@ class POSDeviceViewSet(viewsets.ModelViewSet, POSDeviceMixin):
|
|||||||
|
|
||||||
serial = headers_data['device-serial']
|
serial = headers_data['device-serial']
|
||||||
mac = headers_data['device-mac']
|
mac = headers_data['device-mac']
|
||||||
sdk = headers_data['device-sdk']
|
|
||||||
psp_name = headers_data['device-provider']
|
psp_name = headers_data['device-provider']
|
||||||
|
|
||||||
# provider organization
|
# provider organization
|
||||||
@@ -72,7 +71,7 @@ class POSDeviceViewSet(viewsets.ModelViewSet, POSDeviceMixin):
|
|||||||
|
|
||||||
session = self.session_queryset.filter(serial=serial).first()
|
session = self.session_queryset.filter(serial=serial).first()
|
||||||
if not session:
|
if not session:
|
||||||
session = pos_models.Sessions.objects.create(
|
pos_models.Sessions.objects.create(
|
||||||
device=device,
|
device=device,
|
||||||
name=headers_data['device-name'],
|
name=headers_data['device-name'],
|
||||||
version=headers_data['device-version'],
|
version=headers_data['device-version'],
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class InventoryEntryViewSet(viewsets.ModelViewSet, DynamicSearchMixin, POSDevice
|
|||||||
return self.get_paginated_response(serializer.data)
|
return self.get_paginated_response(serializer.data)
|
||||||
|
|
||||||
@action(
|
@action(
|
||||||
methods=['post'],
|
methods=['get'],
|
||||||
detail=False,
|
detail=False,
|
||||||
url_path='rancher_inventory_entries',
|
url_path='rancher_inventory_entries',
|
||||||
url_name='rancher_inventory_entries',
|
url_name='rancher_inventory_entries',
|
||||||
@@ -60,7 +60,7 @@ class InventoryEntryViewSet(viewsets.ModelViewSet, DynamicSearchMixin, POSDevice
|
|||||||
def rancher_inventory_entries(self, request):
|
def rancher_inventory_entries(self, request):
|
||||||
""" """
|
""" """
|
||||||
organization = self.get_device_organization()
|
organization = self.get_device_organization()
|
||||||
rancher = Rancher.objects.filter(national_code=request.data['national_code']).first()
|
rancher = Rancher.objects.filter(national_code=request.GET['national_code']).first()
|
||||||
entries = self.queryset.filter(organization=organization)
|
entries = self.queryset.filter(organization=organization)
|
||||||
|
|
||||||
available_entries = [entry for entry in entries if can_buy_from_inventory(rancher, entry)]
|
available_entries = [entry for entry in entries if can_buy_from_inventory(rancher, entry)]
|
||||||
|
|||||||
@@ -57,8 +57,9 @@ class InventoryEntrySerializer(serializers.ModelSerializer):
|
|||||||
'id': instance.distribution.quota.product.id,
|
'id': instance.distribution.quota.product.id,
|
||||||
}
|
}
|
||||||
|
|
||||||
# rancher herd & live stock statistics
|
if self.context['rancher']:
|
||||||
representation['rancher_statistics'] = get_rancher_statistics(self.context['rancher'])
|
# rancher herd & live stock statistics
|
||||||
|
representation['rancher_statistics'] = get_rancher_statistics(self.context['rancher'])
|
||||||
|
|
||||||
# rancher live stock statistics by inventory entry
|
# rancher live stock statistics by inventory entry
|
||||||
representation['rancher_quota_weight_statistics'] = rancher_quota_weight(
|
representation['rancher_quota_weight_statistics'] = rancher_quota_weight(
|
||||||
|
|||||||
Reference in New Issue
Block a user