fix - pos device agencies on new system with quota stat
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
# Generated by Django 5.0 on 2025-12-03 11:13
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('pos_device', '0078_deviceversion_checksum_deviceversion_url'),
|
||||||
|
('product', '0101_quota_edited_pricing_features'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='stakeholdershareamount',
|
||||||
|
name='org_quota_stat',
|
||||||
|
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='holders_share_amount', to='product.organizationquotastats'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -7,7 +7,7 @@ from django.db import models
|
|||||||
from apps.authentication.models import Organization, City, Province
|
from apps.authentication.models import Organization, City, Province
|
||||||
from apps.authorization.models import UserRelations
|
from apps.authorization.models import UserRelations
|
||||||
from apps.core.models import BaseModel
|
from apps.core.models import BaseModel
|
||||||
from apps.product.models import Product, Broker, QuotaBrokerValue, QuotaDistribution
|
from apps.product.models import Product, Broker, QuotaBrokerValue, QuotaDistribution, OrganizationQuotaStats
|
||||||
|
|
||||||
|
|
||||||
class ProviderCompany(BaseModel):
|
class ProviderCompany(BaseModel):
|
||||||
@@ -292,6 +292,12 @@ class StakeHolderShareAmount(BaseModel):
|
|||||||
related_name='holders_share_amount',
|
related_name='holders_share_amount',
|
||||||
null=True
|
null=True
|
||||||
)
|
)
|
||||||
|
org_quota_stat = models.ForeignKey(
|
||||||
|
OrganizationQuotaStats,
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
related_name='holders_share_amount',
|
||||||
|
null=True
|
||||||
|
)
|
||||||
stakeholders = models.ForeignKey(
|
stakeholders = models.ForeignKey(
|
||||||
StakeHolders,
|
StakeHolders,
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ from apps.pos_device.models import Device, StakeHolders
|
|||||||
from apps.product.models import (
|
from apps.product.models import (
|
||||||
Quota,
|
Quota,
|
||||||
QuotaDistribution,
|
QuotaDistribution,
|
||||||
Organization
|
Organization, OrganizationQuotaStats
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def pos_organizations_sharing_information(
|
def pos_organizations_sharing_information(
|
||||||
device: Device,
|
device: Device,
|
||||||
quota: Quota = None,
|
quota: Quota = None,
|
||||||
quota_stat=None,
|
quota_stat: OrganizationQuotaStats = None,
|
||||||
distribution: QuotaDistribution = None,
|
distribution: QuotaDistribution = None,
|
||||||
owner_org: Organization = None
|
owner_org: Organization = None
|
||||||
) -> typing.Any:
|
) -> typing.Any:
|
||||||
@@ -23,7 +23,7 @@ def pos_organizations_sharing_information(
|
|||||||
|
|
||||||
sharing_information_list = []
|
sharing_information_list = []
|
||||||
for item in stake_holders:
|
for item in stake_holders:
|
||||||
if item.broker and not owner_org.type.key == 'AGC': # if stakeholder is not an agency, it is a broker
|
if item.broker: # if stakeholder is not an agency, it is a broker
|
||||||
sharing_information_list.append({
|
sharing_information_list.append({
|
||||||
"organization_name": item.organization.name,
|
"organization_name": item.organization.name,
|
||||||
"bank_account": {
|
"bank_account": {
|
||||||
@@ -34,8 +34,9 @@ def pos_organizations_sharing_information(
|
|||||||
"broker": item.broker.name if item.broker else None,
|
"broker": item.broker.name if item.broker else None,
|
||||||
"amount": quota.broker_values.filter(
|
"amount": quota.broker_values.filter(
|
||||||
broker=item.broker,
|
broker=item.broker,
|
||||||
).first().value if quota and item.broker else None,
|
# if quota price features was edited for this organization
|
||||||
|
org_quota_stat=quota_stat if quota_stat.broker_values.exists() else None
|
||||||
|
).first().value if quota.broker_values.filter(broker=item.broker).exists() else None,
|
||||||
# """
|
# """
|
||||||
# if we will need to get agencies share amount, we can use this bellow code
|
# if we will need to get agencies share amount, we can use this bellow code
|
||||||
#
|
#
|
||||||
@@ -47,7 +48,7 @@ def pos_organizations_sharing_information(
|
|||||||
})
|
})
|
||||||
elif owner_org.type.key == 'AGC':
|
elif owner_org.type.key == 'AGC':
|
||||||
agc_stake_holder = owner_org.pos_stake_holders.filter(
|
agc_stake_holder = owner_org.pos_stake_holders.filter(
|
||||||
holders_share_amount__quota_distribution=distribution
|
holders_share_amount__org_quota_stat=quota_stat,
|
||||||
).first()
|
).first()
|
||||||
stake_holders = agc_stake_holder.device.stake_holders.select_related(
|
stake_holders = agc_stake_holder.device.stake_holders.select_related(
|
||||||
'broker', 'organization'
|
'broker', 'organization'
|
||||||
@@ -64,9 +65,9 @@ def pos_organizations_sharing_information(
|
|||||||
"broker": item.broker.name if item.broker else None,
|
"broker": item.broker.name if item.broker else None,
|
||||||
"amount": quota.broker_values.filter(
|
"amount": quota.broker_values.filter(
|
||||||
broker=item.broker,
|
broker=item.broker,
|
||||||
org_quota_stat=quota_stat
|
# if quota price features was edited for this organization
|
||||||
).first().value if quota and item.broker else None,
|
org_quota_stat=quota_stat if quota_stat.broker_values.exists() else None
|
||||||
|
).first().value if quota.broker_values.filter(broker=item.broker).exists() else None,
|
||||||
# """
|
# """
|
||||||
# if we will need to get agencies share amount, we can use this bellow code
|
# if we will need to get agencies share amount, we can use this bellow code
|
||||||
#
|
#
|
||||||
@@ -83,7 +84,8 @@ def pos_organizations_sharing_information(
|
|||||||
agency=owner_org,
|
agency=owner_org,
|
||||||
pos_sharing_list=sharing_information_list,
|
pos_sharing_list=sharing_information_list,
|
||||||
device=device,
|
device=device,
|
||||||
distribution=distribution
|
distribution=distribution,
|
||||||
|
quota_stat=quota_stat
|
||||||
)
|
)
|
||||||
|
|
||||||
return sharing_information_list
|
return sharing_information_list
|
||||||
@@ -93,7 +95,8 @@ def agency_organization_pos_info(
|
|||||||
agency: Organization = None,
|
agency: Organization = None,
|
||||||
pos_sharing_list: list = None,
|
pos_sharing_list: list = None,
|
||||||
device: Device = None,
|
device: Device = None,
|
||||||
distribution: QuotaDistribution = None
|
distribution: QuotaDistribution = None,
|
||||||
|
quota_stat: OrganizationQuotaStats = None
|
||||||
) -> typing.Any:
|
) -> typing.Any:
|
||||||
"""
|
"""
|
||||||
if pos org owner is an agency, calculate share amount of agency
|
if pos org owner is an agency, calculate share amount of agency
|
||||||
@@ -102,11 +105,11 @@ def agency_organization_pos_info(
|
|||||||
|
|
||||||
# get agency share amount
|
# get agency share amount
|
||||||
agc_share_amount = agency.pos_stake_holders.filter(
|
agc_share_amount = agency.pos_stake_holders.filter(
|
||||||
holders_share_amount__quota_distribution=distribution
|
holders_share_amount__org_quota_stat=quota_stat
|
||||||
)
|
)
|
||||||
|
|
||||||
agc_share_amount = agc_share_amount.first().holders_share_amount.filter(
|
agc_share_amount = agc_share_amount.first().holders_share_amount.filter(
|
||||||
quota_distribution=distribution
|
org_quota_stat=quota_stat
|
||||||
) if agc_share_amount.exists() else None
|
) if agc_share_amount.exists() else None
|
||||||
|
|
||||||
agc_share_amount = agc_share_amount.first().share_amount if agc_share_amount.exists() else None
|
agc_share_amount = agc_share_amount.first().share_amount if agc_share_amount.exists() else None
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ from apps.core.services.visibility_service import apply_visibility_filter_by_org
|
|||||||
from apps.pos_device import models as pos_models
|
from apps.pos_device import models as pos_models
|
||||||
from apps.pos_device.web.api.v1.serilaizers import device as device_serializer
|
from apps.pos_device.web.api.v1.serilaizers import device as device_serializer
|
||||||
from apps.pos_device.web.api.v1.viewsets.client import POSClientViewSet
|
from apps.pos_device.web.api.v1.viewsets.client import POSClientViewSet
|
||||||
from apps.product.models import Broker
|
from apps.product.models import Broker, OrganizationQuotaStats
|
||||||
from apps.product.web.api.v1.viewsets.quota_distribution_api import QuotaDistributionViewSet
|
from apps.product.web.api.v1.viewsets.quota_distribution_api import QuotaDistributionViewSet
|
||||||
from common.helpers import generate_code
|
from common.helpers import generate_code
|
||||||
from common.helpers import get_organization_by_user
|
from common.helpers import get_organization_by_user
|
||||||
@@ -389,7 +389,11 @@ class StakeHoldersViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSearchM
|
|||||||
|
|
||||||
|
|
||||||
class StakeHolderShareAmountViewSet(viewsets.ModelViewSet, DynamicSearchMixin, SoftDeleteMixin):
|
class StakeHolderShareAmountViewSet(viewsets.ModelViewSet, DynamicSearchMixin, SoftDeleteMixin):
|
||||||
queryset = pos_models.StakeHolderShareAmount.objects.select_related('quota_distribution', 'stakeholders')
|
queryset = pos_models.StakeHolderShareAmount.objects.select_related(
|
||||||
|
'quota_distribution',
|
||||||
|
'org_quota_stat',
|
||||||
|
'stakeholders'
|
||||||
|
)
|
||||||
serializer_class = device_serializer.StakeHolderShareAmountSerializer
|
serializer_class = device_serializer.StakeHolderShareAmountSerializer
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
@@ -413,7 +417,14 @@ class StakeHolderShareAmountViewSet(viewsets.ModelViewSet, DynamicSearchMixin, S
|
|||||||
view=QuotaDistributionViewSet(),
|
view=QuotaDistributionViewSet(),
|
||||||
data=data['distribution']
|
data=data['distribution']
|
||||||
)
|
)
|
||||||
data.update({'quota_distribution': distribution['id']})
|
|
||||||
|
# quota stat will create after distribution , we get that obj here
|
||||||
|
quota_stat = OrganizationQuotaStats.objects.get(
|
||||||
|
quota_id=data['distribution']['quota'],
|
||||||
|
organization_id=data['distribution']['assigned_organization']
|
||||||
|
)
|
||||||
|
|
||||||
|
data.update({'quota_distribution': distribution['id'], 'org_quota_stat': quota_stat.id})
|
||||||
|
|
||||||
serializer = self.serializer_class(data=data)
|
serializer = self.serializer_class(data=data)
|
||||||
if serializer.is_valid(raise_exception=True):
|
if serializer.is_valid(raise_exception=True):
|
||||||
|
|||||||
Reference in New Issue
Block a user