def parse(self, file_obj): parser_utility = UploadCSVParserUtility() for row in csv.reader(file_obj, delimiter="\t"): if self.ok_to_parse(row): ref = parser_utility.normalize_ref(row[col.b]) posting_date = parser_utility.normalize_date(row[col.c], self.date_format) acct_number = parser_utility.normalize_acct_numb(row[col.d]) ccy = parser_utility.normalize(row[col.f]) amount_raw = parser_utility.normalize_amount(row[col.j]) amount = -amount_raw if row[col.h] == "D" else amount_raw narration = parser_utility.normalize(row[col.g]) success = parser_utility.normalize(row[col.j]) post_obj = TIPostingStatusReport.objects.filter( ref=ref, posting_date=posting_date, amount=amount, ccy=ccy, narration=narration ) if not post_obj.exists(): TIPostingStatusReport.objects.create( ref=ref, posting_date=posting_date, amount=amount, acct_number=acct_number, ccy=ccy, success=success, narration=narration, ) else: post = post_obj[0] if post.success != success and post.acct_number: post.success = success post.save()
def parse(self, fobj): parser_utility = UploadCSVParserUtility() for row in csv.reader(fobj, delimiter="\t"): if self.ok_to_parse(row): booking_date = parser_utility.normalize_date(row[col.g], self.date_format) liq_date = parser_utility.normalize_date(row[col.h], self.date_format) fx_amt = parser_utility.normalize_amount(row[col.j]) ngn_amt = parser_utility.normalize_amount(row[col.k]) narration = parser_utility.normalize(row[col.l]) flex_module = row[col.d] gl_code = row[col.b] ccy = row[col.i] ti_ref_pattern = LC_REF_RE.search(narration) ti_ref = ti_ref_pattern and ti_ref_pattern.group() or "" flex_ref = row[col.a] if not ContingentReport.objects.filter( flex_ref=flex_ref, gl_code=gl_code, ccy=ccy, booking_date=booking_date, flex_module=flex_module, fx_amt=fx_amt, narration=narration, ).exists(): ContingentReport.objects.create( flex_ref=flex_ref, flex_module=flex_module, gl_code=gl_code, booking_date=booking_date, liq_date=liq_date, ccy=ccy, fx_amt=fx_amt, ngn_amt=ngn_amt, ti_ref=ti_ref, narration=narration, acct_numb=ContingentAccount.objects.get(gl_code=gl_code), )