Skip to content

Instantly share code, notes, and snippets.

@cieplak
Created January 15, 2014 00:11
Show Gist options
  • Save cieplak/8428473 to your computer and use it in GitHub Desktop.
Save cieplak/8428473 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from __future__ import unicode_literals
import argparse
import csv
from datetime import datetime
from decimal import Decimal
from balanced_service import models
from balanced_service.db import Session
class Record(object):
def __init__(self, dikt):
self.marketplace_guid = dikt.get('marketplace_guid')
self.dispute_count = dikt.get('dispute_count')
self.dispute_amount = int(Decimal(dikt.get('dispute_amount')) * 100)
self.total_fee = (15 * int(self.dispute_count)) + self.dispute_amount
self.settle_at = datetime(2014, 1, 16)
def create_invoice(record):
mp = models.Marketplace.query.get(record.marketplace_guid)
spec = models.InvoiceSpec(mp)
cls = models.Invoice
invoice = cls(
guid=cls._generate_guid(),
marketplace=mp,
hold_fee=0,
variable_fee_percentage=0,
bank_account_credit_fee=0,
failed_credit_fee=0,
refund_fee=False,
prepaid_discount_percentage=0,
sequence_number=cls._next_sequence_number(mp),
bank_account_debit_fee=0,
bank_account_debit_variable_fee_percentage=0,
bank_account_debit_variable_fee_cap=0,
reversal_fee=0,
settle_at=record.settle_at,
account_debit_variable_fee_percentage=0,
account_debit_fixed_fee=0,
account_debit_variable_fee_cap=0,
cheque_credit_fixed_fee=0
)
invoice.chargeback_fixed_fee = 15
invoice.total_fee = record.total_fee
invoice.lost_debit_chargebacks_total_amount = record.dispute_amount
invoice.lost_debit_chargebacks_count = record.dispute_count
Session.add(invoice)
Session.flush()
return invoice
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
'-d', '--data',
required=True
)
args = parser.parse_args()
with open(args.data, 'cU') as fo:
records = map(Record, list(csv.DictReader(fo)))
map(create_invoice, records)
if __name__ == '__main__':
main()
Session.commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment