Search code examples
collectionstally

I Want to Fetch profit and loss account from tally erp using collection


Hi i want to fetch tally erp data for profit and loss using collection and i am having hard time to get the method to write collection for the same as it does not have anything available of Profit and loss account. can any one help me with the same.


Solution

  • Most important thing to run this script successfully Tally and script has to be on same machine

    import pyodbc for odbc operation

    import pyodbc
    import pandas as pd
    

    Connection string will be your Tally server name and port

    conn = pyodbc.connect('DSN=TallyODBC64_9000;SERVER=({local});DRIVER=Tally ODBC Driver64;PORT=9000')
    cursor=conn.cursor()
    

    Select command for fetching record, be careful here because Select * might fail while converting to csv as it has limitation of rows

    Company = cursor.execute("SELECT $Name, $Address, $Website, 
    $GUID, $EMail, $StateName, $PINCode, $PhoneNumber, 
    $ShowBankDetails FROM Company")
    

    rest is pretty simple

    columns = [column[0] for column in Company.description]
    actual_cols=[s.strip('$') for s in columns]
    rows = Company.fetchall()
    df = pd.DataFrame.from_records(rows)
    df.columns=actual_cols
    pd.DataFrame.from_records(rows)
    columns=actual_cols
    df.to_csv("D:\\Company.csv", index=False)