Exemplo n.º 1
0
def sync_budget_lines(test_run):
    budget_lines = BudgetLine.objects.all()
    logger.info("Syncing {0} BudgetLine objects.".format(budget_lines.count()))

    for budget_line in budget_lines:
        logger.info("Syncing BudgetLine: {0}".format(budget_line))

        # Find the corresponding SF budget lines.
        try:
            sfbudget_line = SalesforceProjectBudget.objects.filter(external_id=budget_line.id).get()
        except SalesforceProjectBudget.DoesNotExist:
            sfbudget_line = SalesforceProjectBudget()

        # SF Layout: Information section
        #Unknown: Materialen, Tools, Transport, Training, etc.
        # sfbudget_line.category =
        sfbudget_line.costs = budget_line.money_amount
        sfbudget_line.description = budget_line.description
        sfbudget_line.external_id = budget_line.id
        sfbudget_line.project = SalesforceProject.objects.filter(external_id=budget_line.project.id).get()

        # Save the SF budget lines.
        if not test_run:
            sfbudget_line.save()

    # Delete budget_lines if the correspondig budget_lines doesn't exist.
    sfbudget_lines = SalesforceProjectBudget.objects.all()
    for sfbudget_line in sfbudget_lines:
        try:
            BudgetLine.objects.filter(id=sfbudget_line.external_id).get()
        except BudgetLine.DoesNotExist:
            sfbudget_line.delete()
def sync_budget_lines(test_run):
    global error_count
    global success_count
    budget_lines = ProjectBudgetLine.objects.all()
    logger.info("Syncing {0} BudgetLine objects.".format(budget_lines.count()))

    for budget_line in budget_lines:
        logger.info("Syncing BudgetLine: {0}".format(budget_line.id))

        # Find the corresponding SF budget lines.
        try:
            sfbudget_line = SalesforceProjectBudget.objects.get(external_id=budget_line.id)
        except SalesforceProjectBudget.DoesNotExist:
            sfbudget_line = SalesforceProjectBudget()

        # SF Layout: Information section
        # Unknown: Materialen, Tools, Transport, Training, etc.
        # sfbudget_line.category =

        sfbudget_line.costs = "%01.2f" % (budget_line.amount / 100)
        sfbudget_line.description = budget_line.description
        sfbudget_line.external_id = budget_line.id
        sfbudget_line.project = SalesforceProject.objects.get(external_id=budget_line.project_plan.id)

        # Save the object to Salesforce
        if not test_run:
            try:
                sfbudget_line.save()
                success_count += 1
            except Exception as e:
                error_count += 1
                logger.error("Error while saving budget line id {0}: ".format(budget_line.id) + str(e))
Exemplo n.º 3
0
def sync_projectbudgetlines(dry_run, sync_from_datetime, loglevel):
    logger.setLevel(loglevel)
    error_count = 0
    success_count = 0

    budget_lines = ProjectBudgetLine.objects.all()

    if sync_from_datetime:
        budget_lines = budget_lines.filter(updated__gte=sync_from_datetime)

    logger.info("Syncing {0} BudgetLine objects.".format(budget_lines.count()))

    for budget_line in budget_lines:
        logger.debug("Syncing BudgetLine: {0}".format(budget_line.id))

        # Find the corresponding SF budget lines.
        try:
            sfbudget_line = SalesforceProjectBudget.objects.get(external_id=budget_line.id)
        except SalesforceProjectBudget.DoesNotExist:
            sfbudget_line = SalesforceProjectBudget()

        # SF Layout: Information section
        sfbudget_line.costs = "%01.2f" % (budget_line.amount / 100)
        sfbudget_line.description = budget_line.description
        sfbudget_line.external_id = budget_line.id

        try:
            sfbudget_line.project = SalesforceProject.objects.get(external_id=budget_line.project_plan.id)
        except SalesforceProject.DoesNotExist:
            logger.error(
                "Unable to find project id {0} in Salesforce for budget line id {1}".format(
                    budget_line.project_plan.id, budget_line.id
                )
            )

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

    return success_count, error_count