fix - pos device agencies on new system with quota stat

This commit is contained in:
2025-12-03 15:03:24 +03:30
parent 82683d4d71
commit c2bb50d9f8
4 changed files with 57 additions and 17 deletions

View File

@@ -4,14 +4,14 @@ from apps.pos_device.models import Device, StakeHolders
from apps.product.models import (
Quota,
QuotaDistribution,
Organization
Organization, OrganizationQuotaStats
)
def pos_organizations_sharing_information(
device: Device,
quota: Quota = None,
quota_stat=None,
quota_stat: OrganizationQuotaStats = None,
distribution: QuotaDistribution = None,
owner_org: Organization = None
) -> typing.Any:
@@ -23,7 +23,7 @@ def pos_organizations_sharing_information(
sharing_information_list = []
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({
"organization_name": item.organization.name,
"bank_account": {
@@ -34,8 +34,9 @@ def pos_organizations_sharing_information(
"broker": item.broker.name if item.broker else None,
"amount": quota.broker_values.filter(
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
#
@@ -47,7 +48,7 @@ def pos_organizations_sharing_information(
})
elif owner_org.type.key == 'AGC':
agc_stake_holder = owner_org.pos_stake_holders.filter(
holders_share_amount__quota_distribution=distribution
holders_share_amount__org_quota_stat=quota_stat,
).first()
stake_holders = agc_stake_holder.device.stake_holders.select_related(
'broker', 'organization'
@@ -64,9 +65,9 @@ def pos_organizations_sharing_information(
"broker": item.broker.name if item.broker else None,
"amount": quota.broker_values.filter(
broker=item.broker,
org_quota_stat=quota_stat
).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
#
@@ -83,7 +84,8 @@ def pos_organizations_sharing_information(
agency=owner_org,
pos_sharing_list=sharing_information_list,
device=device,
distribution=distribution
distribution=distribution,
quota_stat=quota_stat
)
return sharing_information_list
@@ -93,7 +95,8 @@ def agency_organization_pos_info(
agency: Organization = None,
pos_sharing_list: list = None,
device: Device = None,
distribution: QuotaDistribution = None
distribution: QuotaDistribution = None,
quota_stat: OrganizationQuotaStats = None
) -> typing.Any:
"""
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
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(
quota_distribution=distribution
org_quota_stat=quota_stat
) if agc_share_amount.exists() else None
agc_share_amount = agc_share_amount.first().share_amount if agc_share_amount.exists() else None