Example #1
0
def sync_organizations(test_run):
    organizations = Organization.objects.all()
    logger.info("Syncing {0} Organization objects.".format(organizations.count()))

    for organization in organizations:
        logger.info("Syncing Organization: {0}".format(organization))

        # Find the corresponding SF organization.
        try:
            sforganization = SalesforceOrganization.objects.filter(external_id=organization.id).get()
        except SalesforceOrganization.DoesNotExist:
            sforganization = SalesforceOrganization()

        # SF Layout: Account details section.
        sforganization.name = organization.name
        sforganization.legal_status = organization.legal_status
        # Unknown (Business/Funds/1%IDEA): - sforganization.organization_type =

        # # SF Layout: Address Information section.
        sforganization.external_id = organization.id
        # if organization.organizationaddress:
        #     sforganization.billing_city = str(organization.organizationaddress.country.name)
        #     sforganization.billing_street = str(organization.organizationaddress.line1) + " " + str(organization.organizationaddress.line2)
        #     sforganization.billing_postal_code = str(organization.organizationaddress.postal_code)
        # else:
        #     sforganization.billing_city = ''
        #     sforganization.billing_street = ''
        #     sforganization.billing_postal_code = ''
        #
        # sforganization.email_address =
        sforganization.phone = organization.phone_number
        sforganization.website = organization.website

        # # SF Layout: Bank Account section.
        sforganization.address_bank = organization.account_bank_address
        sforganization.bank_account_name = organization.account_bank_name
        sforganization.bank_account_number = organization.account_number
        sforganization.bank_name = organization.name
        sforganization.bic_swift = organization.account_bic
        sforganization.country_bank = str(organization.account_bank_country)
        sforganization.iban_number = organization.account_iban

        # # SF Layout: Description section.
        sforganization.description = organization.description

        # # SF Layout: System Information.
        sforganization.created_date = organization.created

        # Save the SF project.
        if not test_run:
            sforganization.save()
Example #2
0
def sync_organizations(dry_run, sync_from_datetime, loglevel):
    logger.setLevel(loglevel)
    error_count = 0
    success_count = 0

    organizations = Organization.objects.all()
    if sync_from_datetime:
        organizations = organizations.filter(updated__gte=sync_from_datetime)

    logger.info("Syncing {0} Organization objects.".format(organizations.count()))

    for organization in organizations:
        logger.debug("Syncing Organization: {0}".format(organization.id))

        # Find the corresponding SF organization.
        try:
            sforganization = SalesforceOrganization.objects.get(external_id=organization.id)
        except SalesforceOrganization.DoesNotExist:
            sforganization = SalesforceOrganization()

        # SF Layout: Account details section.
        sforganization.name = organization.name
        sforganization.legal_status = organization.legal_status
        sforganization.description = organization.description

        # SF Layout: Contact Information section. Ignore address type and only use first address.
        # When multiple address types are supported in the website, extend this function
        sforganization.billing_city = organization.city[:40]
        sforganization.billing_street = organization.address_line1 + " " + organization.address_line2
        sforganization.billing_postal_code = organization.postal_code
        if organization.country:
            sforganization.billing_country = organization.country.name
        else:
            sforganization.billing_country = ''

        # E-mail addresses for organizations are currently left out because source data is not validated
        # sforganization.email_address = organization.email
        sforganization.phone = organization.phone_number
        sforganization.website = organization.website

        # SF Layout: Bank Account section.
        sforganization.address_bank = organization.account_bank_address
        sforganization.bank_account_name = organization.name
        sforganization.bank_account_number = organization.account_number
        sforganization.bank_name = organization.account_bank_name
        sforganization.bic_swift = organization.account_bic
        sforganization.country_bank = str(organization.account_bank_country)
        sforganization.iban_number = organization.account_iban

        # SF Layout: System Information.
        sforganization.external_id = organization.id
        sforganization.created_date = organization.created

        # Save the object to Salesforce
        if not dry_run:
            try:
                sforganization.save()
                success_count += 1
            except Exception as e:
                error_count += 1
                logger.error("Error while saving organization id {0}: ".format(organization.id) + str(e))

    return success_count, error_count
def sync_organizations(test_run):
    global error_count
    global success_count
    organizations = Organization.objects.all()
    logger.info("Syncing {0} Organization objects.".format(organizations.count()))

    for organization in organizations:
        logger.info("Syncing Organization: {0}".format(organization.id))

        # Find the corresponding SF organization.
        try:
            sforganization = SalesforceOrganization.objects.get(external_id=organization.id)
        except SalesforceOrganization.DoesNotExist:
            sforganization = SalesforceOrganization()

        # SF Layout: Account details section.
        sforganization.name = organization.name
        sforganization.legal_status = organization.legal_status
        sforganization.description = organization.description

        # TODO: Determine if and how organization type should be entered
        # sforganization.organization_type =

        # SF Layout: Contact Information section. Intentionally ignore the address type as it is not used.
        try:
            organizationaddress = OrganizationAddress.objects.get(organization=organization)
        except OrganizationAddress.DoesNotExist:
            sforganization.billing_city = ''
            sforganization.billing_street = ''
            sforganization.billing_postal_code = ''
            sforganization.billing_country = ''
        except OrganizationAddress.MultipleObjectsReturned:
            logger.warn("Organization id {0} has multiple addresses, this is not supported by the integration.".format(organization.id))
        else:
            sforganization.billing_city = organizationaddress.city
            sforganization.billing_street = organizationaddress.line1 + " " + organizationaddress.line2
            sforganization.billing_postal_code = organizationaddress.postal_code
            if organizationaddress.country:
                sforganization.billing_country = organizationaddress.country.name
            else:
                sforganization.billing_country = ''

        sforganization.email_address = organization.email
        sforganization.phone = organization.phone_number
        sforganization.website = organization.website

        # SF Layout: Bank Account section.
        sforganization.address_bank = organization.account_bank_address
        sforganization.bank_account_name = organization.account_bank_name
        sforganization.bank_account_number = organization.account_number
        sforganization.bank_name = organization.name
        sforganization.bic_swift = organization.account_bic
        sforganization.country_bank = str(organization.account_bank_country)
        sforganization.iban_number = organization.account_iban

        # SF Layout: System Information.
        sforganization.external_id = organization.id
        sforganization.created_date = organization.created

        # Save the object to Salesforce
        if not test_run:
            try:
                sforganization.save()
                success_count += 1
            except Exception as e:
                error_count += 1
                logger.error("Error while saving organization id {0}: ".format(organization.id) + str(e))