Exemplo n.º 1
0
def process_frb(file_name):
    incoming_name = os.path.join(INCOMING_ROOT, file_name)
    cf_records, errors = FRBCSVModel.import_data(data=open(incoming_name, 'rU'), skip_rows=3)
    
    new_recs_ctr = 0
    exist_recs_ctr = 0
    errors_cnt = len(errors)

    # HARDCODE
    ext_account = ExternalAccount.objects.get(gl_account__id='1001')

    for rec in cf_records:
        rec['amount'] = rec.pop('debit') + rec.pop('credit')
        rec_obj = Cashflow.objects \
                          .filter(post_date=rec['post_date']) \
                          .filter(amount=rec['amount']) \
                          .filter(external_id=rec['external_id']) \
                          .count()
        if rec_obj > 0:
            exist_recs_ctr += 1
        else:
            new_recs_ctr += 1
            rec['ext_account'] = ext_account
            rec_obj = Cashflow(**rec)
            rec_obj.save()

    summary_msg = 'Loaded FRB file: %d new records, %d duplicate records, %d bad rows' \
                                    % (new_recs_ctr, exist_recs_ctr, errors_cnt)
    return summary_msg, errors
Exemplo n.º 2
0
    def test_get_gl_transactions_checking(self):
        trans = Cashflow(
            ext_account=ExternalAccount.objects.get(label="CHK"),
            post_date=datetime.date(2015, 1, 1),
            description="test",
            trans_type=Account.objects.get(id="3000"),
            amount="100.2",
            counterparty=Counterparty.objects.get(id="test_cp"),
        )

        transactions = trans.get_gl_transactions()
        self.assertEqual(len(transactions), 1)
        lines = transactions[0]["lines"]
        self.assertEqual(len(lines), 2)

        self.assertEqual(set([(self.chk, 100.2, self.cp1), (self.ap, -100.2, self.cp2)]), set(lines))