def post(self): entry_gen_trxn = EntryGeneratingTransaction.objects.get( short_name='AVAILMENT') narration = 'COVER MOVEMENT %s' % self.lc_number entry_code = EntryCode.objects.get(code='TRF') dr_acct = LedgerAccount.objects.get(external_number=self.acct) cr_acct = self.memo_acct contras = EntryContra.objects.filter( amount=self.amount, code=entry_code, narration=narration) if contras.exists(): for contra in contras: if contra.content_object == self: return False post_data = [] for amt, acct in ((-self.amount, dr_acct), (self.amount, cr_acct)): post_data.append({ 'account': acct, 'amount': amt, 'narration': narration, 'entry_code': entry_code, 'entry_gen_trxn': entry_gen_trxn, 'model': self}) return EntryContra.post_entry(*post_data)
def post_entries(self, data): entry_gen_trxn = EntryGeneratingTransaction.objects.get( short_name='ACCTTOACCTTRF') entry_code = EntryCode.objects.get(code='AAT') amount = float(data['manual_post_amount']) post_data = [] for amt, acct in ((-amount, data['dr_acct'],), (amount, data['cr_acct'],)): post_data.append({ 'amount': amt, 'account': LedgerAccount.objects.get(pk=acct), 'entry_code': entry_code, 'entry_gen_trxn': entry_gen_trxn, 'narration': data['manual_post_narration'], }) if EntryContra.post_entry(*post_data): del data['posting_enum'] clirec_details = '\n'.join( '%d\t%s' % (i + 1, c.details,) for i, c in enumerate(self.clirecs)) logger.info( 'Manual Posting for clirec details:\n%s\n\nPost Data:\n%s\n\n', clirec_details, data, ) return True return False
def avail(self): entry_gen_trxn = EntryGeneratingTransaction.objects.get( short_name='AVAILMENT') narration, entry_code, dr_acct, cr_acct = \ self.set_narration_and_entry_code() contras = EntryContra.objects.filter( amount=self.drawn_amt, code=entry_code, narration__contains=self.lc_number) if contras.exists(): for contra in contras: if contra.content_object == self: return False post_data = [] for amt, acct in ( (-self.drawn_amt, dr_acct), (self.drawn_amt, cr_acct)): post_data.append({ 'account': acct, 'amount': amt, 'narration': narration, 'entry_code': entry_code, 'entry_gen_trxn': entry_gen_trxn, 'unmatched': self.unmatched, 'model': self}) return EntryContra.post_entry(*post_data)
def test_entry_contras_post_entry_method_with_minimal_data(self): """We test entrycontra with the minimum amount of attributes possible. """ posted = EntryContra.post_entry(*self.entries) self.assertTrue(posted) self.assertEqual(EntryContra.objects.count(), 2) self.assertTrue(self.entry.contras_dr_equals_cr())
def write_posting(self): assert self.customer is not None, 'You must provide customer details' entry_code = EntryCode.objects.get(code='AAT') entry_gen_trxn = EntryGeneratingTransaction.objects.get( short_name='ITF INTEREST') narration = 'ITF INTEREST %s %s' % ( self.lc_number, self.customer.name) contras = EntryContra.objects.filter( amount=self.amount, code=entry_code, narration=narration, entry_gen_trxn=entry_gen_trxn) if contras.exists(): for contra in contras: if contra.content_object == self: return False post_data = [] for amt in (self.amount, -self.amount): if amt > 0: acct = LedgerAccount.objects.get( number='IN3101010 %s' % self.currency()) rm_code = self.rel_manager() and \ self.rel_manager().rmcode or '' brn = self.customer.branch_for_itf if brn: code = brn.code branch_for_itf_int = code != '026' and code or '' else: branch_for_itf_int = 'NO ITF BRN' else: acct = LedgerAccount.objects.get(external_number=self.acct) rm_code = '' branch_for_itf_int = '' post_data.append( { 'amount': amt, 'account': acct, 'ref': self.lc_number, 'narration': narration, 'rm_code': rm_code, 'branch_for_itf_int': branch_for_itf_int, 'entry_code': entry_code, 'entry_gen_trxn': entry_gen_trxn, 'model': self } ) return EntryContra.post_entry(*post_data)
def post(self): form = ManualPostingForm(self.request.POST) if form.is_valid(): cd = form.cleaned_data _ids = cd['clirec_ids'].split(',') self.clirecs = UnmatchedClarec.objects.filter(pk__in=_ids) memo_acct = LedgerAccount.objects.get(pk=self.request.POST['contra-acct']) amount_taken = float(self.request.POST['amount-taken']) taken_to_memo = TakenToMemo.objects.create( date=date.today(), amount=amount_taken, acct=memo_acct, contra_acct=NostroAccount.objects.get(pk=self.request.POST['memo-acct']), # clirecs=self.clirecs, ) taken_to_memo.clirecs.add(*[c for c in self.clirecs]) entry_gen_trxn = EntryGeneratingTransaction.objects.get( short_name='ACCTTOACCTTRF') entry_code = EntryCode.objects.get(code='AAT') amount = float(cd['manual_post_amount']) post_data = [] for amt, acct in ((-amount, cd['dr_acct'],), (amount, cd['cr_acct'],)): post_data.append({ 'amount': amt, 'account': LedgerAccount.objects.get(pk=acct), 'entry_code': entry_code, 'entry_gen_trxn': entry_gen_trxn, 'narration': cd['manual_post_narration'], }) if EntryContra.post_entry(*post_data): comment = self.update_comment(cd['posting_enum']) del cd['posting_enum'] clirec_details = '\n'.join( '%d\t%s' % (i + 1, c.details,) for i, c in enumerate(self.clirecs)) logger.info( 'Clirec details:\n%s\n\nPost Data:\n%s\n\nTaken to memo\n\n\n', clirec_details, cd, ) return HttpResponse( json.dumps( {'msg': '{:,.2f} taken to account {}'.format(amount_taken, memo_acct, ), 'ids': _ids, 'comment': comment, }), content_type='application/json' ) return self.set_and_return_errors(form.errors)
def test_entry_contras_post_entry_method_with_generic_foreign_key(self): dr, cr = self.entries dr.update({'model': self.ledger}) cr.update({'model': self.ledger}) posted = EntryContra.post_entry(*self.entries) self.assertTrue(posted) self.assertEqual(EntryContra.objects.count(), 2) self.assertTrue(self.entry.contras_dr_equals_cr()) self.assertEqual( EntryContra.objects.get(pk=1).content_object, self.ledger)
def post(self): form = ManualPostingForm(self.request.POST) if form.is_valid(): cd = form.cleaned_data _ids = cd['clirec_ids'].split(',') self.clirecs = UnmatchedClarec.objects.filter(pk__in=_ids) entry_gen_trxn = EntryGeneratingTransaction.objects.get(short_name='ACCTTOACCTTRF') entry_code = EntryCode.objects.get(code='AAT') amount = float(cd['manual_post_amount']) post_data = [] for amt, acct in ((-amount, cd['dr_acct'],), (amount, cd['cr_acct'],)): post_data.append({ 'amount': amt, 'account': LedgerAccount.objects.get(pk=acct), 'entry_code': entry_code, 'entry_gen_trxn': entry_gen_trxn, 'narration': 'INTEREST ON NOSTRO A/C DEPOSITS', }) if EntryContra.post_entry(*post_data): comment = self.update_comment(cd['posting_enum']) del cd['posting_enum'] clirec_details = '\n'.join( '%d\t%s' % (i + 1, c.details,) for i, c in enumerate(self.clirecs)) logger.info( 'Manual Posting for clirec details:\n%s\n\nPost Data:\n%s\n\n', clirec_details, cd, ) return HttpResponse( json.dumps({'msg': 'Entries Posted', 'ids': _ids, 'comment': comment, }), content_type='application/json' ) return self.set_and_return_errors(form.errors)