Esempio n. 1
0
def edited_bsls(billing_schedule, changes):
    """
    Edit already saved BSLs to the way to reflect new changes
    """
    old_bsls = billing_schedule['schedule_lines']
    number_of_period_changed = int(changes['number_of_periods'])
    rate_applied = float(changes['rate'])
    no_of_terms_added = additional_no_of_terms(old_bsls, changes)
    # Fetch the newly created billing schedules from platform
    new_bsls = client.get(f"/billing_schedules/{billing_schedule['id']}")['data']['schedule_lines']
    # Filter out invoiced BSLs and sort by charge ready date
    filtered_bsls = unpaid_bs_lines(new_bsls)
    unpaid_old_bsls = unpaid_bs_lines(old_bsls)
    # Find the old line
    old_bsl = single_schedule_line(old_bsls)
    previous_rate = float(old_bsl['amount'])
    delta = edit_selected_periods(unpaid_old_bsls, number_of_period_changed, rate_applied, changes)
    if no_of_terms_added <= 0:
        for _x in range(abs(no_of_terms_added)):
            if len(unpaid_old_bsls) > number_of_period_changed:
                bsl = unpaid_old_bsls.pop()
                delta += float(bsl['amount'])
        last_line = unpaid_old_bsls[-1]
        line_amount = float(last_line['amount'])
        # Accommodate remaining delta in last line
        last_line['unit_price'] = unit_price(line_amount + delta, last_line)
        return unpaid_old_bsls
    # Add the delta to last BSLs previous line if the previous line was not fully even to other lines
    previous_last_line = unpaid_old_bsls[-1]
    line_amount = float(previous_last_line['amount'])
    if previous_rate > line_amount:
        if line_amount + delta < previous_rate:
            previous_last_line['unit_price'] = unit_price(line_amount + delta, previous_last_line)
            delta = 0
        else:
            previous_last_line['unit_price'] = unit_price(previous_rate, previous_last_line)
            delta -= float(previous_rate) - line_amount
    if no_of_terms_added > 0:
        # Add the deferred/changed rate to end of lines that were added
        for bsl in filtered_bsls[-no_of_terms_added:]:
            if delta > previous_rate:
                bsl['unit_price'] = unit_price(previous_rate, bsl)
                delta -= previous_rate
            else:
                bsl['unit_price'] = unit_price(delta, bsl)
                delta = 0
            # Append newly created lines
            unpaid_old_bsls.append(bsl)
    return unpaid_old_bsls
Esempio n. 2
0
def customer_show(customer_id):
    return client.get(f'/customers/{customer_id}')
Esempio n. 3
0
def billing_schedule(billing_schedule_id):
    response = client.get(f'/billing_schedules/{billing_schedule_id}')
    if response['status']:
        return format_bs_response(response)
    else:
        return response
Esempio n. 4
0
def subscription_show(subscription_id):
    return client.get(f'/subscriptions/{subscription_id}')
Esempio n. 5
0
def subscriptions():
    subscription_id = request.args.get('id')
    params = {}
    if subscription_id:
        params['id'] = subscription_id
    return client.get('/subscriptions', params)