Exemplo n.º 1
0
    def to_representation(self, instance):
        representation = super().to_representation(instance)

        to_represent = {
            'relatedPartyId':
            representation.get('RelatedPartyId', None),
            'relatedParty':
            return_value_or_none(representation.get('BaseParty2Id', None),
                                 'BasePartyName'),
            'relationType':
            return_value_or_none(representation.get('RelationType', {}),
                                 'Description'),
            'percentOwnership':
            representation.get('PercentOwnership', None),
            'controllingOwner':
            'Yes' if representation.get('IsControllingOwner', None) else 'No',
            'relationLegalId':
            return_value_or_none(representation.get('BaseParty1Id', None),
                                 'PrimaryLegalId'),
            'relationEmail':
            return_deep_value_or_none(representation.get('BaseParty1Id', None),
                                      'PrimaryEmailId', 'EmailFinal'),
            'RelationPhone':
            return_deep_value_or_none(representation.get('BaseParty1Id', None),
                                      'PrimaryTelephoneId',
                                      'TelFormattedFinal'),
            'BeginDate':
            representation.get('StartDate', None),
        }

        return to_represent
Exemplo n.º 2
0
    def to_representation(self, instance):
        representation = super().to_representation(instance)

        to_represent = {
            'documentFileId':
            representation.get('DocumentFileId', None),
            'documentType':
            return_value_or_none(representation.get('DocumentType', {}),
                                 'Description'),
            'fileName':
            representation.get('FileName', None),
            'fileType':
            representation.get('FileType', None),
            'status':
            return_value_or_none(representation.get('DocumentStatus', {}),
                                 'Description'),
            # 'uploadBy'
            # 'verifiedBy'
            'uploadDate':
            representation.get('UploadDate', None),
            'verifiedDate':
            representation.get('VerifiedDate', None),
            'documentDateNext':
            representation.get('DocumentDateNext', None)
        }

        return to_represent
Exemplo n.º 3
0
    def to_representation(self, instance):
        representation = super().to_representation(instance)

        to_represent = {
            'collateralId':
            representation.get('CollateralId'),
            'creditApplicationId':
            representation.get('CreditApplicationId').get(
                'CreditApplicationId', None)
            if representation.get('CreditApplicationId') is not None else None,
            'basePartyName':
            representation.get('BasePartyId').get('BasePartyName', None)
            if representation.get('BasePartyId') is not None else None,
            'model':
            self.model,
            'collateralParent':
            representation.get('CollateralIdParent').get('Description1')
            if representation.get('CollateralIdParent') is not None else None,
            'requestType':
            representation.get('RequestType').get('Description', None)
            if representation.get('RequestType') is not None else None,
            'collateral':
            return_value_or_none(representation.get('Description1', {}),
                                 'HostValue')
            if return_value_or_none(representation.get('Description1', {}),
                                    'ProposedValue') is None else
            return_value_or_none(representation.get('Description1', {}),
                                 'ProposedValue'),
            'hostCollateralId':
            representation.get('CollateralIdHost', None),
            'currency': {
                'id':
                representation.get('Currency', {}).get('HostValue', None)
                if representation.get('Currency') is not None else None,
                'title':
                Currency.objects.get(CurrencyId=representation['Currency']
                                     ['HostValue']).Description
                if representation['Currency'] is not None and
                Currency.objects.filter(CurrencyId=representation['Currency']
                                        ['HostValue']).exists() else None
            },
            'existingCharge':
            100000,
            'marketValue':
            100000,
            'forcedSaleValue':
            100000,
            'discountFactor':
            None,
            'discountedValue':
            100000,
            'proposedCharge':
            100000,
            'parameterSummary':
            None,
        }

        return to_represent
Exemplo n.º 4
0
    def to_representation(self, instance):
        representation = super().to_representation(instance)

        collateral = representation.get('CollateralId', {})
        facility = representation.get('FacilityId', {})

        to_represent = {
            'id': representation.get('CoverageId'),
            'facilityId': facility.get('FacilityId', None),
            'facilityParty': facility.get('FacilityId', None),
            'collateralDescription': return_value_or_none(collateral.get('Description1', {}), 'HostValue') if return_value_or_none(collateral.get('Description1', {}), 'ProposedValue') is None else return_value_or_none(collateral.get('Description1', {}), 'ProposedValue'),
            'hostFacilityId': facility.get('FacilityIdHost', None),
            'facilityOwner': return_value_or_none(facility.get('BasePartyId', {}), 'BasePartyName'),
            'facilityDescription': return_value_or_none(facility.get('Description1', {}), 'HostValue') if return_value_or_none(facility.get('Description1', {}), 'ProposedValue') is None else return_value_or_none(facility.get('Description1', {}), 'ProposedValue'),
            'currency': Currency.objects.get(CurrencyId=facility['Currency']['HostValue']).Description if 'Currency' in facility and facility['Currency'] is not None and Currency.objects.filter(CurrencyId=facility['Currency']['HostValue']).exists() else None,
            'tenor': return_value_or_none(facility.get('TenorOriginal', {}), 'HostValue') if return_value_or_none(facility.get('TenorOriginal', {}), 'ProposedValue') is None else return_value_or_none(facility.get('TenorOriginal', {}), 'ProposedValue'),
            'assignment': representation.get('Assignment', None),
            'lienOrder': representation.get('LienOrder', None),
            'frequency': return_value_or_none(facility.get('FrequencyTenor', {}), 'HostValue') if return_value_or_none(facility.get('FrequencyTenor', {}), 'ProposedValue') is None else return_value_or_none(facility.get('FrequencyTenor', {}), 'ProposedValue'),
            'facilityLimit': return_value_or_none(facility.get('CommitmentValue', {}), 'HostValue') if return_value_or_none(facility.get('CommitmentValue', {}), 'ProposedValue') is None else return_value_or_none(facility.get('CommitmentValue', {}), 'ProposedValue'),
            'outstandingBalance': return_value_or_none(facility.get('BalanceValue', {}), 'HostValue') if return_value_or_none(facility.get('BalanceValue', {}), 'ProposedValue') is None else return_value_or_none(facility.get('BalanceValue', {}), 'ProposedValue'),
            'proposedLimit': None,
            'totalExposure': return_value_or_none(facility.get('ExposureTotal', {}), 'HostValue') if return_value_or_none(facility.get('ExposureTotal', {}), 'ProposedValue') is None else return_value_or_none(facility.get('ExposureTotal', {}), 'ProposedValue'),
        }

        return to_represent
Exemplo n.º 5
0
    def to_representation(self, instance):
        representation = super().to_representation(instance)

        to_represent = {
            'id': representation.get('BasePartyTelephoneId', None),
            'value': representation.get('TelFormattedFinal', None),
            'telephoneType': return_value_or_none(representation.get('TelephoneType'), 'TelephoneTypeId'),
            'preferenceType': return_value_or_none(representation.get('PreferenceType'), 'PreferenceTypeId'),

            'telephoneTypeStringed': return_value_or_none(representation.get('TelephoneType'), 'Description'),
            'preferenceTypeStringed': return_value_or_none(representation.get('PreferenceType'), 'Description'),
        }

        return to_represent
Exemplo n.º 6
0
    def to_representation(self, instance):
        representation = super().to_representation(instance)
        base_party_id = representation.get('BasePartyId', None)
        base_party_type = return_value_or_none(
            representation.get('BasePartyType', {}), 'BasePartyTypeId')

        if base_party_type is not None:
            base_party_type = int(base_party_type)
            if base_party_type == 1:
                birth_date = BasePartyIndividual.objects.get(
                    BasePartyId=base_party_id).BirthDate
                sector = None

            elif base_party_type == 2:
                base_party_non_individual = BasePartyNonIndividual.objects.get(
                    BasePartyId=base_party_id)
                sector = base_party_non_individual.PrimarySector.Description if base_party_non_individual.PrimarySector is not None else None
                birth_date = None

            else:
                sector = None
                birth_date = None

        else:
            sector = None
            birth_date = None

        to_represent = {
            'basePartyId':
            base_party_id,
            'basePartyName':
            representation.get('BasePartyName', None),
            'basePartyHostId':
            representation.get('BasePartyHostId', None),
            'primaryLegalId':
            representation.get('PrimaryLegalId', None),
            'primaryEmail':
            return_value_or_none(representation.get('PrimaryEmailId', {}),
                                 'EmailFinal'),
            'primaryTelephone':
            return_value_or_none(representation.get('PrimaryTelephoneId', {}),
                                 'TelFormattedFinal'),
            'sector':
            sector,
            'birthDate':
            birth_date,
        }

        return to_represent
Exemplo n.º 7
0
    def to_representation(self, instance):
        representation = super().to_representation(instance)

        to_represent = {
            'facilityId': representation.get('FacilityId'),
            'creditApplicationId': representation.get('CreditApplicationId').get('CreditApplicationId', None) if representation.get('CreditApplicationId') is not None else None,
            'basePartyName': representation.get('BasePartyId').get('BasePartyName', None) if representation.get('BasePartyId') is not None else None,
            'model': self.model,
            'parentFacility': representation.get('FacilityIdParent').get('Description1') if representation.get('FacilityIdParent') is not None else None,
            'requestType': representation.get('RequestType').get('Description', None) if representation.get('RequestType') is not None else None,
            # 'facility': representation.get('Description1', None),
            # 'facility': 'I don\'t know how to fill this',
            'facility': return_value_or_none(representation.get('Description1', {}), 'HostValue') if return_value_or_none(representation.get('Description1', {}), 'ProposedValue') is None else return_value_or_none(representation.get('Description1', {}), 'ProposedValue'),
            'hostFacilityId': representation.get('FacilityIdHost', None),
            'currency': {
                'id': representation.get('Currency', {}).get('HostValue', None) if representation.get('Currency') is not None else None,
                'title': Currency.objects.get(CurrencyId=representation['Currency']['HostValue']).Description if representation['Currency'] is not None and Currency.objects.filter(CurrencyId=representation['Currency']['HostValue']).exists() else None
            },
            # 'currentBalance': representation['BalanceValue'],
            # 'existingLimit': representation['CommitmentValue'],
            # 'proposedLimit': representation['ProposedValue'],
            # 'parameterSummary': representation['ParameterSummary1'],
            # 'currency': None,
            'currentBalance': 1000000,
            'existingLimit': 1000000,
            'proposedLimit': 1000000,
            'parameterSummary': None
        }

        return to_represent
Exemplo n.º 8
0
    def to_representation(self, instance):
        representation = super().to_representation(instance)

        document_file = DocumentFile.objects.filter(DocumentId=representation['DocumentId']).order_by('-DocumentFileId').first()

        to_represent = {
            'documentId': representation.get('DocumentId', None),
            'documentName': representation.get('FileName', None),
            'documentType': return_value_or_none(representation.get('DocumentType', {}), 'Description'),
            'documentStatus': return_value_or_none(representation.get('DocumentStatus', {}), 'Description'),
            'applicationNumber': return_value_or_none(representation.get('CreditApplicationId', {}), 'CreditApplicationId'),
            'fileType': representation.get('FileType', None),
            'fileURL': 'http://' + self.context.get('host') + '/ViewFile/' + str(document_file.DocumentFileId) if document_file is not None and document_file.DocumentFileId is not None and self.context.get('host') is not None else None,
            'uploadedBy': '{} {}'.format(return_value_or_none(representation.get('LastUpdatedBy', {}), 'first_name'), return_value_or_none(representation.get('LastUpdatedBy', {}), 'last_name')),
            'dateUploaded': representation.get('LastUpdatedDate', None)
        }

        return to_represent
Exemplo n.º 9
0
    def to_representation(self, instance):
        representation = super().to_representation(instance)

        to_represent = {
            'id':
            representation.get('DocumentRelatedItemId', None),
            'relatedItemType':
            return_value_or_none(representation.get('RelatedItemType', {}),
                                 'RelatedItemTypeId'),
            'relatedItemTypeStringed':
            return_value_or_none(representation.get('RelatedItemType', {}),
                                 'Description'),
            'relatedItemId':
            representation.get('RelatedItemId', None),
            'description':
            representation.get('Description', None)
        }

        return to_represent
Exemplo n.º 10
0
    def to_representation(self, instance):
        representation = super().to_representation(instance)

        to_represent = {
            'id':
            representation.get('BasePartyAddressId', None),
            'street1':
            representation.get('Street1', None),
            'street2':
            representation.get('Street2', None),
            'countryAndPostCode': {
                'postCode':
                representation.get('PostCode', None),
                'country':
                return_value_or_none(representation.get('Country', None),
                                     'CountryId')
            },
            'cityAndState': {
                'location1': representation.get('Level1Location', None),
                'location2': representation.get('Level2Location', None),
                'location3': representation.get('Level3Location', None)
            },
            'value':
            representation.get('AddressFinal', None),
            'addressType':
            return_value_or_none(representation.get('AddressType'),
                                 'AddressTypeId'),
            'preferenceType':
            return_value_or_none(representation.get('PreferenceType'),
                                 'PreferenceTypeId'),
            'addressTypeStringed':
            return_value_or_none(representation.get('AddressType'),
                                 'Description'),
            'preferenceTypeStringed':
            return_value_or_none(representation.get('PreferenceType'),
                                 'Description'),
        }

        return to_represent
Exemplo n.º 11
0
    def to_representation(self, instance):
        representation = super().to_representation(instance)

        to_represent = {
            'id':
            representation.get('BasePartyIdentifierId', None),
            'identifier':
            representation.get('Identifier', None),
            'identifierCategory':
            return_value_or_none(representation.get('IdentifierCategory', {}),
                                 'IdentifierCategoryId'),
            'identifierType':
            return_value_or_none(representation.get('IdentifierType', {}),
                                 'IdentifierTypeId'),
            'identifierCategoryStringed':
            return_value_or_none(representation.get('IdentifierCategory', {}),
                                 'Description'),
            'identifierTypeStringed':
            return_value_or_none(representation.get('IdentifierType', {}),
                                 'Description'),
        }

        return to_represent
Exemplo n.º 12
0
    def to_representation(self, instance):
        representation = super().to_representation(instance)

        communication_id = representation.get('CommunicationId', None)

        to_represent = {
            "communicationId":
            communication_id,
            'from':
            representation.get('AddressFrom', None),
            'subject':
            representation.get('Subject', None),
            'regarding':
            return_value_or_none(representation.get('BasePartyId', None),
                                 'BasePartyName'),
            'dateReceive':
            representation.get('InsertDate', None)
        }

        return to_represent
Exemplo n.º 13
0
    def to_representation(self, instance):
        representation = super().to_representation(instance)

        to_represent = {
            'industryAnalysisId':
            representation.get('IndustryAnalysisId', None),
            'industry':
            return_value_or_none(representation.get('Industry', {}),
                                 'Description'),
            'productServiceSold':
            representation.get('ProductServiceSold', None),
            'percentTotalRevenue':
            representation.get('PercentTotalRevenue', None),
            'revenueContribution':
            representation.get('RevenueContribution', None),
            'percentMarketShare':
            representation.get('PercentMarketShare', None),
            'growthRate':
            representation.get('GrowthRate', None),
            'buyerPower':
            return_value_or_none(representation.get('BuyerPower', {}),
                                 'Description'),
            'supplierPower':
            return_value_or_none(representation.get('SupplierPower', {}),
                                 'Description'),
            'newEntrantThreat':
            return_value_or_none(representation.get('NewEntrantThreat', {}),
                                 'Description'),
            'substitutionThreat':
            return_value_or_none(representation.get('SubstitutionThreat', {}),
                                 'Description'),
            'competitiveRivalry':
            return_value_or_none(representation.get('CompetitiveRivalry', {}),
                                 'Description'),
            'startDate':
            representation.get('StartDate', None)
        }

        return to_represent
Exemplo n.º 14
0
    def to_representation(self, instance):
        representation = super().to_representation(instance)

        to_represent = {
            'collateralOwner':
            return_value_or_none(representation.get('BasePartyId', {}),
                                 'BasePartyName'),
            'collateralDescription':
            return_value_or_none(representation.get('Description1', {}),
                                 'HostValue')
            if return_value_or_none(representation.get('Description1', {}),
                                    'ProposedValue') is None else
            return_value_or_none(representation.get('Description1', {}),
                                 'ProposedValue'),
            'currency':
            Currency.objects.get(
                CurrencyId=representation['Currency']['HostValue']).Description
            if representation['Currency'] is not None
            and Currency.objects.filter(
                CurrencyId=representation['Currency']['HostValue']).exists()
            else None,
            'openMarketValue':
            representation.get('ProposedValue'),
            'discountFactor':
            return_value_or_none(representation.get('DiscountFactor', {}),
                                 'HostValue')
            if return_value_or_none(representation.get('DiscountFactor', {}),
                                    'ProposedValue') is None else
            return_value_or_none(representation.get('DiscountFactor', {}),
                                 'ProposedValue'),
            'discountedValue':
            return_value_or_none(representation.get('DiscountedValue', {}),
                                 'HostValue')
            if return_value_or_none(representation.get('DiscountedValue', {}),
                                    'ProposedValue') is None
            else return_value_or_none(
                representation.get('DiscountedValue', {}), 'ProposedValue'),
            'forcedSaleValue':
            return_value_or_none(representation.get('ForcedSaleValue', {}),
                                 'HostValue')
            if return_value_or_none(representation.get('ForcedSaleValue', {}),
                                    'ProposedValue') is None
            else return_value_or_none(
                representation.get('ForcedSaleValue', {}), 'ProposedValue'),
            'priorLiens':
            return_value_or_none(representation.get('PriorLiens', {}),
                                 'HostValue')
            if return_value_or_none(representation.get('PriorLiens', {}),
                                    'ProposedValue') is None else
            return_value_or_none(representation.get('PriorLiens', {}),
                                 'ProposedValue')
        }

        return to_represent
def get_collateral_coverage_summary(collateral_id):
    if collateral_id is None:
        return

    collateral = Collateral.objects.filter(CollateralId=collateral_id).first()

    open_market_value = {
        'host_value': return_value_or_none(collateral.MarketValue,
                                           'HostValue'),
        'proposed_value': return_value_or_none(collateral.MarketValue,
                                               'HostValue')
    }

    discounted_value = {
        'host_value': return_value_or_none(collateral.MarketValue,
                                           'HostValue'),
        'proposed_value': return_value_or_none(collateral.MarketValue,
                                               'HostValue')
    }

    forced_sale_value = {
        'host_value': return_value_or_none(collateral.MarketValue,
                                           'HostValue'),
        'proposed_value': return_value_or_none(collateral.MarketValue,
                                               'HostValue')
    }

    facility_limit = {'host_value': 0, 'proposed_value': 0}

    outstanding_balance = {'host_value': 0, 'proposed_value': 0}

    total_exposure = {'host_value': 0, 'proposed_value': 0}

    coverages = Coverage.objects.filter(CollateralId=collateral_id)

    for coverage in coverages:
        if coverage.FacilityId is not None:
            facility = coverage.FacilityId

            lien_order = coverage.LienOrder
            assignment = coverage.Assignment
            if assignment is not None and lien_order is not None:
                facility_limit['host_value'] = (
                    facility_limit.get('host_value') + (return_value_or_none(
                        facility.CommitmentValue, 'HostValue') * assignment) if
                    return_value_or_none(facility.CommitmentValue, 'HostValue')
                    is not None and isinstance(
                        return_value_or_none(facility.CommitmentValue,
                                             'HostValue'), float or int) else
                    0)
                facility_limit['proposed_value'] = (
                    facility_limit.get('proposed_value') +
                    (return_value_or_none(facility.CommitmentValue,
                                          'ProposedValue') * assignment)
                    if return_value_or_none(facility.CommitmentValue,
                                            'ProposedValue') is not None
                    and isinstance(
                        return_value_or_none(facility.CommitmentValue,
                                             'ProposedValue'), float or int)
                    else 0)

                outstanding_balance['host_value'] = (
                    outstanding_balance.get('host_value') +
                    (return_value_or_none(facility.BalanceValue, 'HostValue') *
                     assignment) if return_value_or_none(
                         facility.BalanceValue, 'HostValue') is not None
                    and isinstance(
                        return_value_or_none(facility.BalanceValue,
                                             'HostValue'), float or int) else
                    0)
                outstanding_balance['proposed_value'] = (
                    outstanding_balance.get('proposed_value') +
                    (return_value_or_none(facility.BalanceValue,
                                          'ProposedValue') * assignment)
                    if return_value_or_none(facility.BalanceValue,
                                            'ProposedValue') is not None
                    and isinstance(
                        return_value_or_none(facility.BalanceValue,
                                             'ProposedValue'), float or int)
                    else 0)

                total_exposure['host_value'] = (
                    total_exposure.get('host_value') + (return_value_or_none(
                        facility.ExposureTotal, 'HostValue') * assignment) if
                    return_value_or_none(facility.ExposureTotal, 'HostValue')
                    is not None and isinstance(
                        return_value_or_none(facility.ExposureTotal,
                                             'HostValue'), float or int) else
                    0)
                total_exposure['proposed_value'] = (
                    total_exposure.get('proposed_value') +
                    (return_value_or_none(facility.ExposureTotal,
                                          'ProposedValue') * assignment)
                    if return_value_or_none(facility.ExposureTotal,
                                            'ProposedValue') is not None
                    and isinstance(
                        return_value_or_none(facility.ExposureTotal,
                                             'ProposedValue'), float or int)
                    else 0)

    utilization_by_omv = {
        'host_value': (total_exposure.get('host_value') /
                       open_market_value.get('host_value'))
        if open_market_value.get('host_value') is not None
        and total_exposure.get('host_value') != 0 else None,
        'proposed_value': (total_exposure.get('proposed_value') /
                           open_market_value.get('proposed_value'))
        if open_market_value.get('proposed_value') is not None
        and total_exposure.get('proposed_value') != 0 else None
    }
    utilization_by_dv = {
        'host_value':
        (total_exposure.get('host_value') / discounted_value.get('host_value'))
        if discounted_value.get('host_value') is not None
        and total_exposure.get('host_value') != 0 else None,
        'proposed_value': (total_exposure.get('proposed_value') /
                           discounted_value.get('proposed_value'))
        if discounted_value.get('proposed_value') is not None
        and total_exposure.get('proposed_value') != 0 else None
    }
    utilization_by_fsv = {
        'host_value': (total_exposure.get('host_value') /
                       forced_sale_value.get('host_value'))
        if forced_sale_value.get('host_value') is not None
        and total_exposure.get('host_value') != 0 else None,
        'proposed_value': (total_exposure.get('proposed_value') /
                           forced_sale_value.get('proposed_value'))
        if forced_sale_value.get('proposed_value') is not None
        and total_exposure.get('proposed_value') != 0 else None
    }

    return [{
        'parameterGroup': 'Exposure Info',
        'parameter': 'Facility Limit',
        'facility': True,
        'hostValue': facility_limit.get('host_value', None),
        'proposedValue': facility_limit.get('proposed_value', None)
    }, {
        'parameterGroup': 'Exposure Info',
        'parameter': 'Outstanding Balance',
        'facility': True,
        'hostValue': outstanding_balance.get('host_value', None),
        'proposedValue': outstanding_balance.get('proposed_value', None)
    }, {
        'parameterGroup': 'Exposure Info',
        'parameter': 'Total Exposure',
        'facility': True,
        'hostValue': total_exposure.get('host_value', None),
        'proposedValue': total_exposure.get('proposed_value', None)
    }, {
        'parameterGroup': 'Collateral Info',
        'parameter': 'Open Market Value (OMV)',
        'collateral': True,
        'hostValue': open_market_value.get('host_value', None),
        'proposedValue': open_market_value.get('proposed_value', None)
    }, {
        'parameterGroup': 'Collateral Info',
        'parameter': 'Discounted Value (DV)',
        'collateral': True,
        'hostValue': discounted_value.get('host_value', None),
        'proposedValue': discounted_value.get('proposed_value', None)
    }, {
        'parameterGroup': 'Collateral Info',
        'parameter': 'Forced Sale Value (FSV)',
        'collateral': True,
        'hostValue': forced_sale_value.get('host_value', None),
        'proposedValue': forced_sale_value.get('proposed_value', None)
    }, {
        'parameterGroup': 'Coverage Ratios',
        'parameter': 'Coverage By OMV',
        'collateral': True,
        'hostValue': utilization_by_omv.get('host_value', None),
        'proposedValue': utilization_by_omv.get('proposed_value', None)
    }, {
        'parameterGroup': 'Coverage Ratios',
        'parameter': 'Coverage By DV',
        'collateral': True,
        'hostValue': utilization_by_dv.get('host_value', None),
        'proposedValue': utilization_by_dv.get('proposed_value', None)
    }, {
        'parameterGroup': 'Coverage Ratios',
        'parameter': 'Coverage By FSV',
        'collateral': True,
        'hostValue': utilization_by_fsv.get('host_value', None),
        'proposedValue': utilization_by_fsv.get('proposed_value', None)
    }]
    def to_representation(self, instance):
        representation = super().to_representation(instance)

        collateral = representation.get('CollateralId', {})
        facility = representation.get('FacilityId', {})

        to_represent = {
            'model':
            self.model,
            'bindWith':
            representation.get('BindWith', None),
            'facilityId':
            facility.get('FacilityId'),
            'facilityDescription':
            return_value_or_none(facility.get(
                'Description1', {}), 'HostValue') if return_value_or_none(
                    facility.get('Description1', {}), 'ProposedValue') is None
            else return_value_or_none(facility.get('Description1', {}),
                                      'ProposedValue'),
            'collateralId':
            collateral.get('CollateralId'),
            'collateralOwner':
            return_value_or_none(collateral.get('BasePartyId', {}),
                                 'BasePartyName'),
            'collateralDescription':
            return_value_or_none(collateral.get('Description1', {}),
                                 'HostValue')
            if return_value_or_none(collateral.get('Description1', {}),
                                    'ProposedValue') is None else
            return_value_or_none(collateral.get('Description1', {}),
                                 'ProposedValue'),
            'currency':
            Currency.objects.get(
                CurrencyId=collateral['Currency']['HostValue']).Description
            if collateral['Currency'] is not None and Currency.objects.filter(
                CurrencyId=collateral['Currency']['HostValue']).exists() else
            None,
            'openMarketValue':
            collateral.get('ProposedValue'),
            'discountedValue':
            return_value_or_none(collateral.get('DiscountedValue', {}),
                                 'HostValue')
            if return_value_or_none(collateral.get('DiscountedValue', {}),
                                    'ProposedValue') is None else
            return_value_or_none(collateral.get('DiscountedValue', {}),
                                 'ProposedValue'),
            'forcedSaleValue':
            return_value_or_none(collateral.get('ForcedSaleValue', {}),
                                 'HostValue')
            if return_value_or_none(collateral.get('ForcedSaleValue', {}),
                                    'ProposedValue') is None else
            return_value_or_none(collateral.get('ForcedSaleValue', {}),
                                 'ProposedValue'),
            'assignment':
            representation.get('Assignment', None),
            'lienOrder':
            representation.get('LienOrder', None),
        }

        return to_represent
Exemplo n.º 17
0
    def to_representation(self, instance):
        representation = super().to_representation(instance)

        to_represent = {
            'hostFacilityId':
            representation.get('FacilityIdHost', None),
            'facilityOwner':
            return_value_or_none(representation.get('BasePartyId', {}),
                                 'BasePartyName'),
            'facilityDescription':
            return_value_or_none(representation.get('Description1', {}),
                                 'HostValue')
            if return_value_or_none(representation.get('Description1', {}),
                                    'ProposedValue') is None else
            return_value_or_none(representation.get('Description1', {}),
                                 'ProposedValue'),
            'currency':
            Currency.objects.get(
                CurrencyId=representation['Currency']['HostValue']).Description
            if representation['Currency'] is not None
            and Currency.objects.filter(
                CurrencyId=representation['Currency']['HostValue']).exists()
            else None,
            'tenor':
            return_value_or_none(representation.get('TenorOriginal', {}),
                                 'HostValue')
            if return_value_or_none(representation.get('TenorOriginal', {}),
                                    'ProposedValue') is None else
            return_value_or_none(representation.get('TenorOriginal', {}),
                                 'ProposedValue'),
            'frequency':
            return_value_or_none(representation.get('FrequencyTenor', {}),
                                 'HostValue')
            if return_value_or_none(representation.get('FrequencyTenor', {}),
                                    'ProposedValue') is None else
            return_value_or_none(representation.get('FrequencyTenor', {}),
                                 'ProposedValue'),
            'facilityLimit':
            return_value_or_none(representation.get('CommitmentValue', {}),
                                 'HostValue')
            if return_value_or_none(representation.get('CommitmentValue', {}),
                                    'ProposedValue') is None
            else return_value_or_none(
                representation.get('CommitmentValue', {}), 'ProposedValue'),
            'outstandingBalance':
            return_value_or_none(representation.get('BalanceValue', {}),
                                 'HostValue')
            if return_value_or_none(representation.get('BalanceValue', {}),
                                    'ProposedValue') is None else
            return_value_or_none(representation.get('BalanceValue', {}),
                                 'ProposedValue'),
            'proposedLimit':
            None,
            'totalExposure':
            return_value_or_none(representation.get('ExposureTotal', {}),
                                 'HostValue')
            if return_value_or_none(representation.get('ExposureTotal', {}),
                                    'ProposedValue') is None else
            return_value_or_none(representation.get('ExposureTotal', {}),
                                 'ProposedValue'),
        }

        return to_represent
Exemplo n.º 18
0
    def post(self, request, *args, **kwargs):
        global base_party_type
        global base_party_non_individual

        global primary_email_id
        global primary_telephone_id
        global primary_contact_id

        if request.data is None:
            return Response('Data is missing', status=400)

        base_party = BaseParty.objects.create()
        base_party_banking_summary = BasePartyBankingSummary.objects.create(BasePartyId=base_party)
        base_party_financial_summary = BasePartyFinancialsSummary.objects.create(BasePartyId=base_party)

        if 'details' in request.data:
            details = request.data.get('details', {})

            if 'basicDetails' in details:
                basic_details = details.get('basicDetails', {})

                primary_email_id = basic_details.get('primaryEmailId', None)
                primary_telephone_id = basic_details.get('primaryTelephoneId', None)
                primary_contact_id = basic_details.get('primaryContactId', None)

                base_party_type = basic_details.get('basePartyType') if basic_details.get('basePartyType') is not None else None
                if int(base_party_type) == 1:
                    base_party_individual = BasePartyIndividual.objects.create(BasePartyId=base_party)
                elif int(base_party_type) == 2:
                    base_party_non_individual = BasePartyNonIndividual.objects.create(BasePartyId=base_party)

                    for field in base_party_details_basic_details_non_individual_fields:
                        setattr(base_party_non_individual, field['db_field'], basic_details.get(field['field_label'], None))

                for field in base_party_details_basic_details_base_party_fields:
                    setattr(base_party, field['db_field'], basic_details.get(field['field_label'], None))

                base_party.save()

            if 'bankingHighlights' in details:
                banking_highlights = details.get('bankingHighlights', {})

                for field in base_party_details_banking_summary_fields:
                    setattr(base_party_banking_summary, field['db_field'], banking_highlights.get(field['field_label'], None))

                base_party_banking_summary.save()

            if 'financialHighlights' in details:
                financial_highlights = details.get('financialHighlights', {})

                for field in base_party_details_financial_summary_fields:
                    setattr(base_party_financial_summary, field['db_field'], financial_highlights.get(field['field_label'], None))

                base_party_financial_summary.save()

            if 'otherInformation' in details and base_party_type is not None and base_party_non_individual is not None:
                other_information = details.get('otherInformation', {})

                for field in base_party_details_other_information_fields:
                    setattr(base_party_non_individual, field['db_field'], other_information.get(field['field_label'], None))

                base_party_non_individual.save()

        if 'identifiers' in request.data:
            _identifiers = request.data.get('identifiers', {})

            if 'identifiers' in _identifiers:
                identifiers = _identifiers.get('identifiers', [])

                if len(identifiers) > 0:
                    for identifier in identifiers:
                        if 'temp' in str(identifier.get('id', '')):
                            base_party_identifier = BasePartyIdentifier()
                            base_party_identifier.BasePartyId = base_party
                            base_party_identifier.Identifier = identifier.get('identifier', None)
                            base_party_identifier.IdentifierCategory_id = identifier.get('identifierCategory', None)
                            base_party_identifier.IdentifierType_id = identifier.get('identifierType', None)
                            base_party_identifier.save()

        if 'contactsAndAddresses' in request.data:
            contacts_and_addresses = request.data.get('contactsAndAddresses', {})

            if 'telephones' in contacts_and_addresses:
                telephones = contacts_and_addresses.get('telephones', [])

                if len(telephones) > 0:
                    for telephone in telephones:
                        if 'temp' in str(telephone.get('id', '')):
                            base_party_telephone = BasePartyTelephone()
                            base_party_telephone.BasePartyId = base_party
                            base_party_telephone.TelFormattedFinal = telephone.get('value', None)
                            base_party_telephone.PreferenceType_id = telephone.get('preferenceType', None)
                            base_party_telephone.TelephoneType_id = telephone.get('telephoneType', None)
                            base_party_telephone.save()

                            if primary_telephone_id == telephone.get('id', None):
                                base_party.PrimaryTelephoneId = base_party_telephone
                                base_party.save()

            if 'addresses' in contacts_and_addresses:
                addresses = contacts_and_addresses.get('addresses', [])

                if len(addresses) > 0:
                    for address in addresses:
                        if address.get('addressType', None) is not None and address.get('addressType', None).isdigit() and int(address.get('addressType', None)) == 1:
                            if 'temp' in str(address.get('id', '')):
                                base_party_address = BasePartyAddress()
                                base_party_address.BasePartyId = base_party
                                base_party_address.AddressType_id = address.get('addressType', None)
                                base_party_address.PreferenceType_id = address.get('preferenceType', None)
                                base_party_address.Street1 = address.get('street1', None)
                                base_party_address.Street2 = address.get('street2', None)
                                base_party_address.Level1Location = return_value_or_none(address.get('cityAndState', {}), 'location1')
                                base_party_address.Level2Location = return_value_or_none(address.get('cityAndState', {}), 'location2')
                                base_party_address.Level3Location = return_value_or_none(address.get('cityAndState', {}), 'location3')
                                base_party_address.Country_id = return_value_or_none(address.get('countryAndPostCode', {}), 'country')
                                base_party_address.PostCode = return_value_or_none(address.get('countryAndPostCode', {}), 'postCode')

                                country_query_set = Country.objects.filter(CountryId=return_value_or_none(address.get('countryAndPostCode', {}), 'country'))

                                address_final = '{} {} {} {} {} {}'.format(country_query_set.first().Description if country_query_set.exists() else '',
                                                                           return_value_or_none(address.get('cityAndState', {}), 'location1'),
                                                                           return_value_or_none(address.get('cityAndState', {}), 'location2'),
                                                                           return_value_or_none(address.get('cityAndState', {}), 'location3'),
                                                                           address.get('street1', None),
                                                                           address.get('street2', None))

                                base_party_address.AddressFinal = address_final
                                base_party_address.save()

                                if primary_contact_id == address.get('id', None):
                                    base_party.PrimaryContactId = base_party_address
                                    base_party.save()

                        elif address.get('addressType', None) is not None and address.get('addressType', None).isdigit() and int(address.get('addressType', None)) == 2:
                            if 'temp' in str(address.get('id', '')):
                                base_party_email = BasePartyEmail()
                                base_party_email.BasePartyId = base_party
                                base_party_email.EmailFinal = address.get('value', None)
                                base_party_email.EmailType_id = address.get('emailType', None)
                                base_party_email.AddressType_id = address.get('addressType', None)
                                base_party_email.PreferenceType_id = address.get('preferenceType', None)
                                base_party_email.save()

                                if primary_email_id == address.get('id', None):
                                    base_party.PrimaryEmailId = base_party_email
                                    base_party.save()

        response = BasePartiesSerializer(base_party).data

        return JsonResponse(response)