fix - pos sharing on agc bug fixed influently
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import typing
|
||||
|
||||
from apps.authentication.services.service import get_bank_info
|
||||
from apps.pos_device.models import Device, StakeHolders
|
||||
from apps.product.models import (
|
||||
Quota,
|
||||
@@ -19,65 +20,51 @@ def pos_organizations_sharing_information(
|
||||
pos sharing organizations' information,
|
||||
device have multiple organizations (sub_accounts) for sharing money
|
||||
"""
|
||||
stake_holders = device.stake_holders.select_related('broker', 'organization').filter()
|
||||
stake_holders_qs = (
|
||||
device.stake_holders
|
||||
.select_related('broker', 'organization')
|
||||
.prefetch_related('organization__bank_information')
|
||||
)
|
||||
|
||||
broker_values_qs = quota.broker_values.all()
|
||||
|
||||
if quota_stat and quota_stat.broker_values.exists():
|
||||
broker_values_qs = broker_values_qs.filter(org_quota_stat=quota_stat)
|
||||
|
||||
broker_value_map = {
|
||||
bv.broker_id: bv.value
|
||||
for bv in broker_values_qs
|
||||
}
|
||||
|
||||
if owner_org.type.key == 'AGC':
|
||||
agc_stake_holder = (
|
||||
owner_org.pos_stake_holders
|
||||
.filter(holders_share_amount__org_quota_stat=quota_stat)
|
||||
.select_related('device')
|
||||
.first()
|
||||
)
|
||||
|
||||
if agc_stake_holder:
|
||||
stake_holders_qs = (
|
||||
agc_stake_holder.device.stake_holders
|
||||
.select_related('broker', 'organization')
|
||||
.prefetch_related('organization__bank_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
|
||||
sharing_information_list.append({
|
||||
"organization_name": item.organization.name,
|
||||
"bank_account": {
|
||||
"credit_card": item.organization.bank_information.first().card,
|
||||
"sheba": "IR" + item.organization.bank_information.first().sheba,
|
||||
"account": item.organization.bank_information.first().account,
|
||||
} if item.organization.bank_information.exists() else {},
|
||||
"broker": item.broker.name if item.broker else None,
|
||||
"amount": quota.broker_values.filter(
|
||||
broker=item.broker,
|
||||
# if quota price features was edited for this organization
|
||||
org_quota_stat=quota_stat if quota_stat and 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
|
||||
#
|
||||
# # item.holders_share_amount.filter(quota_distribution=distribution).first().share_amount
|
||||
# # if item.holders_share_amount.filter(quota_distribution=distribution).exists() else None
|
||||
# """
|
||||
"agency": False,
|
||||
"default_account": item.default
|
||||
})
|
||||
elif owner_org.type.key == 'AGC':
|
||||
agc_stake_holder = owner_org.pos_stake_holders.filter(
|
||||
holders_share_amount__org_quota_stat=quota_stat,
|
||||
).first()
|
||||
print(quota_stat.id)
|
||||
stake_holders = agc_stake_holder.device.stake_holders.select_related(
|
||||
'broker', 'organization'
|
||||
).filter()
|
||||
for item in stake_holders:
|
||||
if item.broker: # if stakeholder is not an agency, it is a broker
|
||||
sharing_information_list.append({
|
||||
"organization_name": item.organization.name,
|
||||
"bank_account": {
|
||||
"credit_card": item.organization.bank_information.first().card,
|
||||
"sheba": "IR" + item.organization.bank_information.first().sheba,
|
||||
"account": item.organization.bank_information.first().account,
|
||||
} if item.organization.bank_information.exists() else {},
|
||||
"broker": item.broker.name if item.broker else None,
|
||||
"amount": quota.broker_values.filter(
|
||||
broker=item.broker,
|
||||
# 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
|
||||
#
|
||||
# # item.holders_share_amount.filter(quota_distribution=distribution).first().share_amount
|
||||
# # if item.holders_share_amount.filter(quota_distribution=distribution).exists() else None
|
||||
# """
|
||||
"agency": False,
|
||||
"default_account": item.default
|
||||
})
|
||||
|
||||
for item in stake_holders_qs:
|
||||
if not item.broker:
|
||||
continue
|
||||
|
||||
sharing_information_list.append({
|
||||
"organization_name": item.organization.name,
|
||||
"bank_account": get_bank_info(item.organization),
|
||||
"broker": item.broker.name,
|
||||
"amount": broker_value_map.get(item.broker_id),
|
||||
"agency": False,
|
||||
"default_account": item.default,
|
||||
})
|
||||
|
||||
# if device owner is an agency organization
|
||||
if owner_org.type.key == 'AGC':
|
||||
@@ -108,13 +95,15 @@ def agency_organization_pos_info(
|
||||
"""
|
||||
|
||||
# get agency share amount
|
||||
agc_share_amount = agency.pos_stake_holders.filter(
|
||||
holders_share_amount__org_quota_stat=quota_stat
|
||||
agc_stake_holder = (
|
||||
agency.pos_stake_holders
|
||||
.filter(holders_share_amount__org_quota_stat=quota_stat)
|
||||
.select_related('device')
|
||||
)
|
||||
|
||||
agc_share_amount = agc_share_amount.first().holders_share_amount.filter(
|
||||
agc_share_amount = agc_stake_holder.first().holders_share_amount.filter(
|
||||
org_quota_stat=quota_stat
|
||||
) if agc_share_amount.exists() else None
|
||||
) if agc_stake_holder.exists() else None
|
||||
|
||||
agc_share_amount = agc_share_amount.first().share_amount if agc_share_amount else None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user