def test_add_batch_no_start_entry_counter(self): settings = { 'company_id': '999999999', 'company_name': 'CAULIFLOWER LTD', 'immediate_dest': '123456789', 'immediate_dest_name': 'DESTRO INC', 'immediate_org': 'ORANG LLC', 'immediate_org_name': 'ORANG LLC', 'file_gen_datetime': datetime(2020, 1, 1) } entries = [{ 'type': '22', 'routing_number': '234567890', 'account_number': '3456789012', 'amount': 45.67, 'name': 'Nonce Cornelius', 'id_number': '5555555555', }] f = AchFile('A', settings) f.add_batch(std_ent_cls_code='PPD', batch_entries=entries) lines = f.render_to_string().split('\n') entry_line = lines[2].split() assert entry_line[len(entry_line) - 1] == '0123456780000001'
def generate_ach_file(self): self.ensure_one() inbound_payment = self.payment_type == "inbound" file_mod = self.get_file_id_mod() ach_file = AchFile(file_id_mod=file_mod, settings=self.ach_settings()) filename = "{today}_{bank}_{file_mod}.txt".format( today=fields.Date.today(), bank=self.company_partner_bank_id.id, file_mod=file_mod, ) entries = [] for line in self.bank_line_ids: if inbound_payment: self.validate_mandates(line) self.validate_banking(line) amount = line.amount_currency entries.append( { "type": self.get_transaction_type(amount=amount), "routing_number": line.partner_bank_id.bank_id.routing_number, "account_number": line.partner_bank_id.acc_number, "amount": str(amount), "name": line.partner_id.name, "addenda": [{"payment_related_info": line.communication}], } ) outbound_payment = self.payment_type == "outbound" ach_file.add_batch( "PPD", entries, credits=outbound_payment, debits=inbound_payment ) return ach_file.render_to_string().encode("utf-8"), filename
def create_ach_files(content): lines = content.splitlines() for i in range(0, len(banks)): # For each bank ach_file = AchFile('A', create_setting_entry(lines)) # Initiate ACH file entries = [] for j in range(2, len(lines)): # Read lines if lines[j][3:11] == banks[i][ 0]: # If match for destination (RDFI) # Add an entry routing_number = lines[j][3:11] # RDFI bank (customer's bank) account_number = lines[j][12:29] # Customer account number amount = str(float(lines[j][29:39]) / 100) # Amount name = lines[j][54:76] # Customer name entries.append({ 'type': '27', # We're creatign debits only 'routing_number': routing_number, 'account_number': account_number, 'amount': amount, 'name': name }) if len(entries) != 0: #We have transactions ach_file.add_batch('POS', entries, credits=True, debits=True) # Save generated file to merchant-upload bucket bucket_name = 'ach-rdfi-' + banks[i][ 0] # Based on RDFI rounting number file_name = str(uuid.uuid4()) + '.ach' # Generate unique name ach_content = ach_file.render_to_string() save_file(bucket_name, file_name, ach_content)
def setup(self): self.settings = { 'immediate_dest': '123456780', 'immediate_org': '123456780', 'immediate_dest_name': 'YOUR BANK', 'immediate_org_name': 'YOUR COMPANY', 'company_id': '1234567890', #tax number } self.ach_file = AchFile('A', self.settings) #file Id mod self.entries = [ { 'type': '22', # type of 'routing_number': '12345678', 'account_number': '11232132', 'amount': '10.00', 'name': 'Alice Wanderdust', 'addenda': [ { 'payment_related_info': 'Here is some additional information', }, ], }, { 'type': '27', 'routing_number': '12345678', 'account_number': '234234234', 'amount': '150.00', 'name': 'Billy Holiday', }, { 'type': '22', 'routing_number': '123232318', 'account_number': '123123123', 'amount': '12.13', 'name': 'Rachel Welch', 'id_number': '3333', }, ] self.ach_file.add_batch('PPD', self.entries, credits=True, debits=True)
from ach.builder import AchFile settings = { 'immediate_dest': '123456780', 'immediate_org': '123456780', 'immediate_dest_name': 'YOUR BANK', 'immediate_org_name': 'YOUR COMPANY', 'company_id': '1234567890', #tax number } ach_file = AchFile('A', settings) #file Id mod entries = [ { 'type': '22', # type of 'routing_number': '12345678', 'account_number': '11232132', 'amount': '10.00', 'name': 'Alice Wanderdust', 'addenda': [ { 'payment_related_info': 'Here is some additional information', }, ], }, {
password=db_password, host=db_host, database=db_db) cursor = cnx.cursor() query = 'INSERT INTO merchant_upload(time,entry) SELECT CURRENT_TIMESTAMP(), 1;' cursor.execute(query) cnx.commit() cursor.close() cnx.close() except Exception as e: logging.error(f"Unexpected error: {e}") raise # Initialize a new ACH file ach_file = AchFile('A', create_setting_entry()) # Create entries entries = create_transactions_entries() # Populate ACH file with generated entries ach_file.add_batch('POS', entries, credits=True, debits=True) # Save generated file to merchant-upload bucket bucket_name = 'ach-merchant-upload' file_name = str(uuid.uuid4()) + '.ach' content = ach_file.render_to_string() save_file(bucket_name, file_name, content) update_merchant_upload()