Insertion/updation of ledgers: for the case of ledgers Tally has a clause called @@dupkeycombine as specified in the sample xml request.
from flask import Flask, request, redirect, url_for, flash, render_template_string
import requests
app = Flask(__name__)
app.secret_key = 'your_secret_key' # Replace with a strong key for production
# Tally server URL
tally_url = 'http://localhost:9000'
# HTML template as a string
html_template = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tally Ledger Entry Form</title>
</head>
<body>
<h1>Tally Ledger Entry Form</h1>
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
<ul>
{% for category, message in messages %}
<li class="{{ category }}">{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{% endwith %}
<form action="{{ url_for('submit_data') }}" method="POST">
<label for="company_name">Company Name:</label><br>
<input type="text" id="company_name" name="company_name" required><br><br>
<label for="ledger_name">Ledger Name:</label><br>
<input type="text" id="ledger_name" name="ledger_name" required><br><br>
<label for="ledger_parent">Ledger Parent:</label><br>
<input type="text" id="ledger_parent" name="ledger_parent" required><br><br>
<button type="submit">Submit to Tally</button>
</form>
</body>
</html>
"""
@app.route('/')
def index():
return render_template_string(html_template)
@app.route('/submit', methods=['POST'])
def submit_data():
# Collect data from form
company_name = request.form['company_name']
ledger_name = request.form['ledger_name']
#reserved_name = request.form['reserved_name']
ledger_parent = request.form['ledger_parent']
#ledger_name = request.form['ledger_name']
#amount = request.form['amount']
# XML payload
xml_data = f"""<ENVELOPE>
<HEADER>
<VERSION>1</VERSION>
<TALLYREQUEST>Import</TALLYREQUEST>
<TYPE>Data</TYPE>
<ID>AllMasters</ID>
</HEADER>
<BODY>
<DESC>
<STATICVARIABLES>
<IMPORTDUPS>@@DUPKEYCOMBINE</IMPORTDUPS>
<SVCURRENTCOMPANY>{company_name}</SVCURRENTCOMPANY>
</STATICVARIABLES>
</DESC>
<DATA>
<TALLYMESSAGE>
<LEDGER NAME="{ledger_name}">
<OLDAUDITENTRYIDS.LIST TYPE="Number">
<OLDAUDITENTRYIDS>-1</OLDAUDITENTRYIDS>
</OLDAUDITENTRYIDS.LIST>
<CREATEDDATE>20231224</CREATEDDATE>
<PARENT>{ledger_parent}</PARENT>
<ENTEREDBY>a</ENTEREDBY>
<CREATEDBY>a</CREATEDBY>
<TAXCLASSIFICATIONNAME> Not Applicable</TAXCLASSIFICATIONNAME>
<TAXTYPE>Others</TAXTYPE>
<GSTTYPE> Not Applicable</GSTTYPE>
<APPROPRIATEFOR> Not Applicable</APPROPRIATEFOR>
<SERVICECATEGORY> Not Applicable</SERVICECATEGORY>
<EXCISELEDGERCLASSIFICATION> Not Applicable</EXCISELEDGERCLASSIFICATION>
<EXCISEDUTYTYPE> Not Applicable</EXCISEDUTYTYPE>
<EXCISENATUREOFPURCHASE> Not Applicable</EXCISENATUREOFPURCHASE>
<LEDGERFBTCATEGORY> Not Applicable</LEDGERFBTCATEGORY>
<ISBILLWISEON>No</ISBILLWISEON>
<ISCOSTCENTRESON>No</ISCOSTCENTRESON>
<ISINTERESTON>No</ISINTERESTON>
<ALLOWINMOBILE>No</ALLOWINMOBILE>
<ISCOSTTRACKINGON>No</ISCOSTTRACKINGON>
<ISBENEFICIARYCODEON>No</ISBENEFICIARYCODEON>
<ISEXPORTONVCHCREATE>No</ISEXPORTONVCHCREATE>
<PLASINCOMEEXPENSE>No</PLASINCOMEEXPENSE>
<ISUPDATINGTARGETID>No</ISUPDATINGTARGETID>
<ISDELETED>No</ISDELETED>
<ISSECURITYONWHENENTERED>No</ISSECURITYONWHENENTERED>
<ASORIGINAL>No</ASORIGINAL>
<ISCONDENSED>No</ISCONDENSED>
<AFFECTSSTOCK>No</AFFECTSSTOCK>
<ISRATEINCLUSIVEVAT>No</ISRATEINCLUSIVEVAT>
<FORPAYROLL>No</FORPAYROLL>
<ISABCENABLED>No</ISABCENABLED>
<ISCREDITDAYSCHKON>No</ISCREDITDAYSCHKON>
<INTERESTONBILLWISE>No</INTERESTONBILLWISE>
<OVERRIDEINTEREST>No</OVERRIDEINTEREST>
<OVERRIDEADVINTEREST>No</OVERRIDEADVINTEREST>
<USEFORVAT>No</USEFORVAT>
<IGNORETDSEXEMPT>No</IGNORETDSEXEMPT>
<ISTCSAPPLICABLE>No</ISTCSAPPLICABLE>
<ISTDSAPPLICABLE>No</ISTDSAPPLICABLE>
<ISFBTAPPLICABLE>No</ISFBTAPPLICABLE>
<ISGSTAPPLICABLE>No</ISGSTAPPLICABLE>
<ISEXCISEAPPLICABLE>No</ISEXCISEAPPLICABLE>
<ISTDSEXPENSE>No</ISTDSEXPENSE>
<ISEDLIAPPLICABLE>No</ISEDLIAPPLICABLE>
<ISRELATEDPARTY>No</ISRELATEDPARTY>
<USEFORESIELIGIBILITY>No</USEFORESIELIGIBILITY>
<ISINTERESTINCLLASTDAY>No</ISINTERESTINCLLASTDAY>
<APPROPRIATETAXVALUE>No</APPROPRIATETAXVALUE>
<ISBEHAVEASDUTY>No</ISBEHAVEASDUTY>
<INTERESTINCLDAYOFADDITION>No</INTERESTINCLDAYOFADDITION>
<INTERESTINCLDAYOFDEDUCTION>No</INTERESTINCLDAYOFDEDUCTION>
<ISOTHTERRITORYASSESSEE>No</ISOTHTERRITORYASSESSEE>
<IGNOREMISMATCHWITHWARNING>No</IGNOREMISMATCHWITHWARNING>
<USEASNOTIONALBANK>No</USEASNOTIONALBANK>
<BEHAVEASPAYMENTGATEWAY>No</BEHAVEASPAYMENTGATEWAY>
<OVERRIDECREDITLIMIT>No</OVERRIDECREDITLIMIT>
<ISAGAINSTFORMC>No</ISAGAINSTFORMC>
<ISCHEQUEPRINTINGENABLED>Yes</ISCHEQUEPRINTINGENABLED>
<ISPAYUPLOAD>No</ISPAYUPLOAD>
<ISPAYBATCHONLYSAL>No</ISPAYBATCHONLYSAL>
<ISBNFCODESUPPORTED>No</ISBNFCODESUPPORTED>
<ALLOWEXPORTWITHERRORS>No</ALLOWEXPORTWITHERRORS>
<CONSIDERPURCHASEFOREXPORT>No</CONSIDERPURCHASEFOREXPORT>
<ISTRANSPORTER>No</ISTRANSPORTER>
<ISECASHLEDGER>No</ISECASHLEDGER>
<USEFORNOTIONALITC>No</USEFORNOTIONALITC>
<ISECOMMOPERATOR>No</ISECOMMOPERATOR>
<OVERRIDEBASEDONREALIZATION>No</OVERRIDEBASEDONREALIZATION>
<ISECDIFFINSDATE>No</ISECDIFFINSDATE>
<SHOWINPAYSLIP>No</SHOWINPAYSLIP>
<USEFORGRATUITY>No</USEFORGRATUITY>
<ISTDSPROJECTED>No</ISTDSPROJECTED>
<ISSALARYMULFILE>No</ISSALARYMULFILE>
<FORSERVICETAX>No</FORSERVICETAX>
<ISINPUTCREDIT>No</ISINPUTCREDIT>
<ISEXEMPTED>No</ISEXEMPTED>
<ISABATEMENTAPPLICABLE>No</ISABATEMENTAPPLICABLE>
<ISSTXPARTY>No</ISSTXPARTY>
<ISSTXNONREALIZEDTYPE>No</ISSTXNONREALIZEDTYPE>
<USEFORKKC>No</USEFORKKC>
<USEFORSBC>No</USEFORSBC>
<ISUSEDFORCVD>No</ISUSEDFORCVD>
<LEDBELONGSTONONTAXABLE>No</LEDBELONGSTONONTAXABLE>
<ISEXCISEMERCHANTEXPORTER>No</ISEXCISEMERCHANTEXPORTER>
<ISPARTYEXEMPTED>No</ISPARTYEXEMPTED>
<ISSEZPARTY>No</ISSEZPARTY>
<TDSDEDUCTEEISSPECIALRATE>No</TDSDEDUCTEEISSPECIALRATE>
<ISECHEQUESUPPORTED>No</ISECHEQUESUPPORTED>
<ISEDDSUPPORTED>No</ISEDDSUPPORTED>
<HASECHEQUEDELIVERYMODE>No</HASECHEQUEDELIVERYMODE>
<HASECHEQUEDELIVERYTO>No</HASECHEQUEDELIVERYTO>
<HASECHEQUEPRINTLOCATION>No</HASECHEQUEPRINTLOCATION>
<HASECHEQUEPAYABLELOCATION>No</HASECHEQUEPAYABLELOCATION>
<HASECHEQUEBANKLOCATION>No</HASECHEQUEBANKLOCATION>
<HASEDDDELIVERYMODE>No</HASEDDDELIVERYMODE>
<HASEDDDELIVERYTO>No</HASEDDDELIVERYTO>
<HASEDDPRINTLOCATION>No</HASEDDPRINTLOCATION>
<HASEDDPAYABLELOCATION>No</HASEDDPAYABLELOCATION>
<HASEDDBANKLOCATION>No</HASEDDBANKLOCATION>
<ISEBANKINGENABLED>No</ISEBANKINGENABLED>
<ISEXPORTFILEENCRYPTED>No</ISEXPORTFILEENCRYPTED>
<ISBATCHENABLED>No</ISBATCHENABLED>
<ISPRODUCTCODEBASED>No</ISPRODUCTCODEBASED>
<HASEDDCITY>No</HASEDDCITY>
<HASECHEQUECITY>No</HASECHEQUECITY>
<ISFILENAMEFORMATSUPPORTED>No</ISFILENAMEFORMATSUPPORTED>
<HASCLIENTCODE>No</HASCLIENTCODE>
<PAYINSISBATCHAPPLICABLE>No</PAYINSISBATCHAPPLICABLE>
<PAYINSISFILENUMAPP>No</PAYINSISFILENUMAPP>
<ISSALARYTRANSGROUPEDFORBRS>No</ISSALARYTRANSGROUPEDFORBRS>
<ISEBANKINGSUPPORTED>No</ISEBANKINGSUPPORTED>
<ISSCBUAE>No</ISSCBUAE>
<ISBANKSTATUSAPP>No</ISBANKSTATUSAPP>
<ISSALARYGROUPED>No</ISSALARYGROUPED>
<USEFORPURCHASETAX>No</USEFORPURCHASETAX>
<AUDITED>No</AUDITED>
<SORTPOSITION> 1000</SORTPOSITION>
<ALTERID> 10511</ALTERID>
<OPENINGBALANCE>0.00</OPENINGBALANCE>
<SERVICETAXDETAILS.LIST> </SERVICETAXDETAILS.LIST>
<LBTREGNDETAILS.LIST> </LBTREGNDETAILS.LIST>
<VATDETAILS.LIST> </VATDETAILS.LIST>
<SALESTAXCESSDETAILS.LIST> </SALESTAXCESSDETAILS.LIST>
<GSTDETAILS.LIST> </GSTDETAILS.LIST>
<HSNDETAILS.LIST> </HSNDETAILS.LIST>
<LANGUAGENAME.LIST>
<NAME.LIST TYPE="String">
<NAME>{ledger_name}</NAME>
</NAME.LIST>
<LANGUAGEID> 1033</LANGUAGEID>
</LANGUAGENAME.LIST>
<XBRLDETAIL.LIST> </XBRLDETAIL.LIST>
<AUDITDETAILS.LIST> </AUDITDETAILS.LIST>
<SCHVIDETAILS.LIST> </SCHVIDETAILS.LIST>
<EXCISETARIFFDETAILS.LIST> </EXCISETARIFFDETAILS.LIST>
<TCSCATEGORYDETAILS.LIST> </TCSCATEGORYDETAILS.LIST>
<TDSCATEGORYDETAILS.LIST> </TDSCATEGORYDETAILS.LIST>
<SLABPERIOD.LIST> </SLABPERIOD.LIST>
<GRATUITYPERIOD.LIST> </GRATUITYPERIOD.LIST>
<ADDITIONALCOMPUTATIONS.LIST> </ADDITIONALCOMPUTATIONS.LIST>
<EXCISEJURISDICTIONDETAILS.LIST> </EXCISEJURISDICTIONDETAILS.LIST>
<EXCLUDEDTAXATIONS.LIST> </EXCLUDEDTAXATIONS.LIST>
<BANKALLOCATIONS.LIST> </BANKALLOCATIONS.LIST>
<PAYMENTDETAILS.LIST> </PAYMENTDETAILS.LIST>
<BANKEXPORTFORMATS.LIST> </BANKEXPORTFORMATS.LIST>
<BILLALLOCATIONS.LIST> </BILLALLOCATIONS.LIST>
<INTERESTCOLLECTION.LIST> </INTERESTCOLLECTION.LIST>
<LEDGERCLOSINGVALUES.LIST> </LEDGERCLOSINGVALUES.LIST>
<LEDGERAUDITCLASS.LIST> </LEDGERAUDITCLASS.LIST>
<OLDAUDITENTRIES.LIST> </OLDAUDITENTRIES.LIST>
<TDSEXEMPTIONRULES.LIST> </TDSEXEMPTIONRULES.LIST>
<DEDUCTINSAMEVCHRULES.LIST> </DEDUCTINSAMEVCHRULES.LIST>
<LOWERDEDUCTION.LIST> </LOWERDEDUCTION.LIST>
<STXABATEMENTDETAILS.LIST> </STXABATEMENTDETAILS.LIST>
<LEDMULTIADDRESSLIST.LIST> </LEDMULTIADDRESSLIST.LIST>
<STXTAXDETAILS.LIST> </STXTAXDETAILS.LIST>
<CHEQUERANGE.LIST> </CHEQUERANGE.LIST>
<DEFAULTVCHCHEQUEDETAILS.LIST> </DEFAULTVCHCHEQUEDETAILS.LIST>
<ACCOUNTAUDITENTRIES.LIST> </ACCOUNTAUDITENTRIES.LIST>
<AUDITENTRIES.LIST> </AUDITENTRIES.LIST>
<BRSIMPORTEDINFO.LIST> </BRSIMPORTEDINFO.LIST>
<AUTOBRSCONFIGS.LIST> </AUTOBRSCONFIGS.LIST>
<BANKURENTRIES.LIST> </BANKURENTRIES.LIST>
<DEFAULTCHEQUEDETAILS.LIST> </DEFAULTCHEQUEDETAILS.LIST>
<DEFAULTOPENINGCHEQUEDETAILS.LIST> </DEFAULTOPENINGCHEQUEDETAILS.LIST>
<CANCELLEDPAYALLOCATIONS.LIST> </CANCELLEDPAYALLOCATIONS.LIST>
<ECHEQUEPRINTLOCATION.LIST> </ECHEQUEPRINTLOCATION.LIST>
<ECHEQUEPAYABLELOCATION.LIST> </ECHEQUEPAYABLELOCATION.LIST>
<EDDPRINTLOCATION.LIST> </EDDPRINTLOCATION.LIST>
<EDDPAYABLELOCATION.LIST> </EDDPAYABLELOCATION.LIST>
<AVAILABLETRANSACTIONTYPES.LIST> </AVAILABLETRANSACTIONTYPES.LIST>
<LEDPAYINSCONFIGS.LIST> </LEDPAYINSCONFIGS.LIST>
<TYPECODEDETAILS.LIST> </TYPECODEDETAILS.LIST>
<FIELDVALIDATIONDETAILS.LIST> </FIELDVALIDATIONDETAILS.LIST>
<INPUTCRALLOCS.LIST> </INPUTCRALLOCS.LIST>
<TCSMETHODOFCALCULATION.LIST> </TCSMETHODOFCALCULATION.LIST>
<LEDGSTREGDETAILS.LIST> </LEDGSTREGDETAILS.LIST>
<LEDMAILINGDETAILS.LIST>
<ADDRESS.LIST TYPE="String">
<ADDRESS>NANANA</ADDRESS>
</ADDRESS.LIST>
<APPLICABLEFROM>20170401</APPLICABLEFROM>
</LEDMAILINGDETAILS.LIST>
<GSTRECONPREFIXSUFFIXDETAILS.LIST> </GSTRECONPREFIXSUFFIXDETAILS.LIST>
<CONTACTDETAILS.LIST> </CONTACTDETAILS.LIST>
<GSTCLASSFNIGSTRATES.LIST> </GSTCLASSFNIGSTRATES.LIST>
<EXTARIFFDUTYHEADDETAILS.LIST> </EXTARIFFDUTYHEADDETAILS.LIST>
<TEMPGSTITEMSLABRATES.LIST> </TEMPGSTITEMSLABRATES.LIST>
<VOUCHERTYPEPRODUCTCODES.LIST> </VOUCHERTYPEPRODUCTCODES.LIST>
<LEDADDRESS.LIST> </LEDADDRESS.LIST>
<DEFMULTIPLETOPHONENO.LIST> </DEFMULTIPLETOPHONENO.LIST>
</LEDGER>
</TALLYMESSAGE>
</DATA>
</BODY>
</ENVELOPE>
"""
# Send data to Tally
headers = {'Content-Type': 'application/xml'}
response = requests.post(tally_url, data=xml_data.encode('utf-8'), headers=headers)
# Handle response
if response.status_code == 200:
flash("Data submitted to Tally successfully.", "success")
else:
flash("Failed to submit data to Tally.", "error")
return redirect(url_for('index'))
if __name__ == '__main__':
app.run(debug=True, use_reloader=False)
These are the key points to be attached with the xml import for vouchers.
Tally import with tdl:
The data for masters and transactions can also be imported with tdl.
In case of TDL it becomes a little bit more complex since the matching of the ledger names code needs to be added. Sample function is given below:
[function: Add_Stockitem]
00: Walk Collection: testcoll
0X: IF : $$IsEmpty:@@itemexists
Variable:setdate:Date
Variable:setrate:Rate
00A:Set:setdate:$$Date:"01-04-2023"
01E:Set:setrate:$$AsRate:"100"
01A: New Object: StockItem
01BA: Set VALUE:NAME:$$LocaleString:$item_name;$item_name
01BC: Set VALUE:PARENT:$item_type;$item_name
01BD: Set VALUE:CATEGORY:$sub_category_name
01BD1: Set VALUE:DESCRIPTION:$sku_code
01BE: Set VALUE:GSTAPPLICABLE:$$LocaleString:"Applicable"
01bF: Set Value: BASEUNITS:$$LocaleString:$Uom
01bG: Set Value: NARRATION:$$LocaleString:$sku_code
;; Set cost & selling price
0010 : INSERT COLLECTION OBJECT : STANDARDCOSTLIST
0011 : Set Value : Date : "1-11-2017"
0012 : Set Value : Rate : $$TgtObject:$$AsRate:@@RateVal1
0013 : Set Target : ..
0014 : INSERT COLLECTION OBJECT : STANDARDPRICELIST
0015 : Set Value : Date : "1-11-2017"
0016 : Set Value : Rate : $$TgtObject:$$AsRate:@@RateVal2
0017 : Set Target : ..
01D1:SAVE Target
01D:End If
;02: END WALK
02: END WALK
021CC:Create Target