remove bank account when remove org
This commit is contained in:
@@ -231,7 +231,7 @@ class OrganizationTypeViewSet(BaseViewSet, SoftDeleteMixin, ModelViewSet):
|
||||
return self.get_paginated_response(serializer.data)
|
||||
|
||||
|
||||
class OrganizationViewSet(BaseViewSet, SoftDeleteMixin, ModelViewSet, DynamicSearchMixin):
|
||||
class OrganizationViewSet(BaseViewSet, ModelViewSet, DynamicSearchMixin):
|
||||
""" Crud operations for organization model """ #
|
||||
queryset = Organization.objects.all()
|
||||
serializer_class = OrganizationSerializer
|
||||
@@ -384,6 +384,19 @@ class OrganizationViewSet(BaseViewSet, SoftDeleteMixin, ModelViewSet, DynamicSea
|
||||
serializer = self.serializer_class(page, many=True)
|
||||
return self.get_paginated_response(serializer.data)
|
||||
|
||||
@transaction.atomic
|
||||
def destroy(self, request, pk=None, *args, **kwargs):
|
||||
""" remove organization with bank accounts """
|
||||
org = self.get_object()
|
||||
|
||||
org.bank_information.all().update(trash=True)
|
||||
org.soft_delete()
|
||||
|
||||
return Response(
|
||||
{"detail": "رکورد با موفقیت حذف شد (Soft Delete)."}, # noqa
|
||||
status=status.HTTP_204_NO_CONTENT
|
||||
)
|
||||
|
||||
|
||||
class BankAccountViewSet(SoftDeleteMixin, ModelViewSet):
|
||||
""" Crud operations for bank account model """ #
|
||||
|
||||
@@ -22,48 +22,48 @@ def pos_organizations_sharing_information(
|
||||
|
||||
sharing_information_list = []
|
||||
for item in stake_holders:
|
||||
if item.broker and not owner_org.type.name == '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": 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
|
||||
).first().value if quota and item.broker else None,
|
||||
# if item.broker and not owner_org.type.name == '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": 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
|
||||
).first().value if quota and item.broker 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
|
||||
})
|
||||
else:
|
||||
sharing_information_list.append({
|
||||
"organization_name": "تعاونی دامداران فامنین",
|
||||
"bank_account": {
|
||||
"credit_card": "2222222222222222",
|
||||
"sheba": "666666666666666666",
|
||||
"account": "4444444444444444444444",
|
||||
},
|
||||
"broker": "تعاونی",
|
||||
"amount": 1600,
|
||||
|
||||
# """
|
||||
# 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": True
|
||||
})
|
||||
# """
|
||||
# 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
|
||||
})
|
||||
# else:
|
||||
# sharing_information_list.append({
|
||||
# "organization_name": "تعاونی دامداران فامنین",
|
||||
# "bank_account": {
|
||||
# "credit_card": "2222222222222222",
|
||||
# "sheba": "666666666666666666",
|
||||
# "account": "4444444444444444444444",
|
||||
# },
|
||||
# "broker": "تعاونی",
|
||||
# "amount": 1600,
|
||||
#
|
||||
# # """
|
||||
# # 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": True
|
||||
# })
|
||||
|
||||
# if device owner is an agency organization
|
||||
print(sharing_information_list)
|
||||
@@ -90,12 +90,13 @@ def agency_organization_pos_info(
|
||||
"""
|
||||
|
||||
# get agency share amount
|
||||
agc_share_amount = agency.pos_stake_holders.filter(
|
||||
agc_share_amount = (agency.pos_stake_holders.filter(
|
||||
device=device,
|
||||
).first().holders_share_amount.filter(
|
||||
quota_distribution=distribution
|
||||
)
|
||||
|
||||
))
|
||||
# .holders_share_amount.filter(
|
||||
# quota_distribution=distribution
|
||||
# ))
|
||||
print(agc_share_amount, device)
|
||||
agc_share_amount = agc_share_amount.first().share_amount if agc_share_amount else None
|
||||
|
||||
# calculate agency parent share amount
|
||||
|
||||
@@ -101,7 +101,6 @@ class QuotaDistributionViewSet(viewsets.ModelViewSet, DynamicSearchMixin, POSDev
|
||||
can_buy_from_inventory(rancher.first(), distribution=distribution) & rancher.exists()
|
||||
)
|
||||
]
|
||||
print(device)
|
||||
|
||||
# paginate & response
|
||||
page = self.paginate_queryset(available_distributions) # noqa
|
||||
|
||||
Reference in New Issue
Block a user