def test_get_gl_transactions_happy_path(self): cp = Counterparty(id='test_cp', name="Test C/P") cp.save() trans = CreditCardTrans(company=self.default_company, trans_date=datetime.date(2015,1,1), type='sale', amount='100', counterparty=cp) transactions = trans.get_gl_transactions() self.assertEqual(len(transactions), 1)
def process_mastercard(file_name): incoming_name = os.path.join(INCOMING_ROOT, file_name) statement = OfxParser.parse(file(incoming_name)).account card_number = statement.account_id transactions = statement.statement.transactions trans_ids = [tr.id for tr in transactions] dupes = [tr.trans_id for tr in CreditCardTrans.objects.filter(trans_id__in=trans_ids)] errors = [] dupes_ctr = len(dupes) new_trans_ctr = 0 error_ctr = 0 for t in [t for t in transactions if t.id not in dupes]: # these should all be new try: trans_info = {} trans_info['card_company_id'] = 'MCARD' trans_info['counterparty_id'] = 'unknown' trans_info['trans_date'] = t.date trans_info['post_date'] = t.date trans_info['trans_type'] = t.type trans_info['trans_id'] = t.id trans_info['payee'] = t.payee trans_info['amount'] = t.amount trans_info['description'] = t.mcc if t.memo != '': trans_info['description'] += ': %s' % t.memo trans_info['card_number'] = card_number trans_obj = CreditCardTrans(**trans_info) trans_obj.save() new_trans_ctr += 1 except Exception, e: errors.append(str(e)) error_ctr += 1