Example #1
0
def create_monthly_billing_entry(service,
                                 start_date,
                                 end_date,
                                 notification_type,
                                 monthly_totals=[]):
    entry = MonthlyBilling(service_id=service.id,
                           notification_type=notification_type,
                           monthly_totals=monthly_totals,
                           start_date=start_date,
                           end_date=end_date)

    db.session.add(entry)
    db.session.commit()

    return entry
Example #2
0
def _update_monthly_billing(service_id, start_date, end_date,
                            notification_type):
    billing_data = get_billing_data_for_month(
        service_id=service_id,
        start_date=start_date,
        end_date=end_date,
        notification_type=notification_type)
    monthly_totals = _monthly_billing_data_to_json(billing_data)
    row = get_monthly_billing_entry(service_id, start_date, notification_type)
    if row:
        row.monthly_totals = monthly_totals
        row.updated_at = datetime.utcnow()
    else:
        row = MonthlyBilling(service_id=service_id,
                             notification_type=notification_type,
                             monthly_totals=monthly_totals,
                             start_date=start_date,
                             end_date=end_date)

    db.session.add(row)