Tally integration on odoo

How can I export tax analysis in invoice in tally to xml request?

url1 = "http://localhost:9000"
        xml = "<ENVELOPE><HEADER><VERSION>1</VERSION><TALLYREQUEST>EXPORT</TALLYREQUEST><TYPE>DATA</TYPE>"
        xml += "<ID>VoucherRegister</ID></HEADER><BODY><DESC><STATICVARIABLES>"
        xml += "<EXPLODEVNUM>Yes</EXPLODEVNUM><ISVATDUTYPAID>Yes</ISVATDUTYPAID><DBINVEXPLODEFLAG>Yes</DBINVEXPLODEFLAG>"
        xml+="<DBBILLEXPLODEFLAG>Yes</DBBILLEXPLODEFLAG><SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT><SVFROMDATE Type='DATE'>"+self.startdate+"</SVFROMDATE><SVTODATE Type='DATE'>"+self.enddate+"</SVTODATE><VOUCHERTYPENAME>"+self.sale_name+"</VOUCHERTYPENAME><EXPLODEFLAG>Yes</EXPLODEFLAG><REPORTNAME>Ledger Cost Breakup</REPORTNAME></STATICVARIABLES>"
        xml += "<TDL><TDLMESSAGE><COLLECTION><FETCH>GSTDetails.LIST</FETCH></COLLECTION></TDLMESSAGE></TDL></DESC></BODY></ENVELOPE>"

        req = requests.post(url = url1,data=xml)


        # res = req.text.decode("UTF-8")
        response = req.text.strip().replace("&","&amp;")
        # scrubbedXML = re.sub('&.+[0-9]+;', '', response)
        # print(response)
        responseXML = Et.fromstring(response)
        values=database.data()
        print(values)
        url_odoo=values['urls']
        db_odoo=values['database']
        email_odoo=values['email']
        password_odoo=values['password']
        print(url_odoo)
        url=url_odoo
        db=db_odoo
        username=email_odoo
        password=password_odoo
        common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url),allow_none=True)
        uid = common.authenticate(db, username, password, {})
        models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url),allow_none=True)


        for vch in responseXML.findall("./BODY/DATA/TALLYMESSAGE/VOUCHER"):
            mylist=[]
            mylist2=[]
            myliist3=[]
            stockslist=[]
            amountlist=[]
            quantitylist=[] 
            roundofflist=[]
            discountlist=[]

            try:
                if len(vch.findall('INVENTORYENTRIES.LIST'))>=0:
                    try:
                        # stk = vch.findall("INVENTORYENTRIES.LIST").__getitem__(0).find("STOCKITEMNAME").text
                        for stockss in vch.findall("INVENTORYENTRIES.LIST"):
                            stks=stockss.find('STOCKITEMNAME').text
                            # print(stks)
                            stockslist.append(stks)
                    except:
                        stk='na'
                        pass

                    try:
                        for discoun in vch.findall("INVENTORYENTRIES.LIST"):
                            disc=float(discoun.find('DISCOUNT').text)
                            print(disc)
                            discountlist.append(disc)
                            # stockslist.append(stks)

                    except:
                        disc=0
                        discountlist.append(disc)
                        pass
                    try:
                        # rt = vch.findall("INVENTORYENTRIES.LIST").__getitem__(0).find("RATE").text
                        for rates in vch.findall('INVENTORYENTRIES.LIST'):
                            perrattes=rates.find('RATE').text
                            ratee=(re.findall(r'-?\d+\.?\d*', perrattes))
                            for s in ratee:
                                perrate=float(s)
                                # print(perrate)
                                amountlist.append(perrate)
                    except:
                        perrate=0
                        # print(perrate)
                        pass
                    try:
                        # Ktk = vch.findall("INVENTORYENTRIES.LIST").__getitem__(0).find("BILLEDQTY").text
                        for ktks in vch.findall('INVENTORYENTRIES.LIST'):
                            ktk= ktks.find('BILLEDQTY').text
                            billedqu=(re.findall(r'-?\d+\.?\d*', ktk))
                            for b in billedqu:
                                quan=float(b)
                                # print(quan)
                                quantitylist.append(quan)
                    except:
                        quan=1.0
                        quantitylist.append(quan)
                        # print(quan)
            except:
                continue

                    

            if len(vch.findall("LEDGERENTRIES.LIST"))>=0:
                try:
                    for  ro in vch.findall("LEDGERENTRIES.LIST"):
                        roundoff=ro.find('AMOUNT').text
                        round=float(roundoff)
                        if round>0 and round<1.0 or round< 0 and round>-1.0:
                            roff=float(round)
                            roundofflist.append(roff)
       
                    
                    for items in  vch.findall("LEDGERENTRIES.LIST"):
                        vall=items.find('LEDGERNAME').text
                        
                        mylist.append(vall)
                        print(mylist)
                
                except:
                    amount=0
                    toname='na'
                    # print(toname)
                    pass
            else:
                try:
                    amount = vch.findall("ALLLEDGERENTRIES.LIST").__getitem__(0).find("LEDGERNAME").text

                except:
                    amount='na'
                    pass
            
                
            try:
                vch_dt=vch.find("DATE").text
                vch_date=self.change_date_format(vch_dt)
                
            except:
                vch_date='na'
                pass
            try:
                vch_led= vch.find("VOUCHERTYPENAME").text
                print(vch_led)
            except:
                vch_led='na'
                pass
            try:
                vch_type= vch.find("VOUCHERNUMBER").text
                print(vch_type)
            except:
                vch_type='na'
                pass
            try:
                vch_no= vch.find("PARTYLEDGERNAME").text
        

            except:
                vch_no= 'na'
                pass


            print(mylist)
            try:
                del mylist[0]
            except:
                pass
            
                
            
            for valll in mylist:
                pid=models.execute_kw(db, uid, password, 'account.tax','search',[[['name', '=',valll]]])
                print(pid)

                mylist2.append(pid)
            # del mylist2[0]
            print(mylist2,'check')

            for value1 in mylist2:
                try:
                    val2=value1[0]

                except:
                    pass
                try:
                    myliist3.append(val2)
                    print(myliist3)
                except:
                    pass
            xid=models.execute_kw(db, uid, password, 'account.invoice','search_count',[[['origin', '=', vch_type]]])
            # print(xid)
            lid=models.execute_kw(db, uid, password, 'account.invoice','search',[[['origin', '=', vch_type]]])
            try:
                sid=models.execute_kw(db,uid, password, 'res.partner','search',[[['name', '=', vch_no]]])
                print(sid)
            except:
                continue
            

            
            
            
            # print(sid)
            # print(mid)
            print(stockslist)
            print(amountlist)
            print(quantitylist)
            for vill in  sid:
                if xid>=1:
                    continue
        
                else:
                    rslt =models.execute_kw(db, uid, password, 'account.invoice','create',[{'partner_id': vill,
                    'date_invoice':vch_date,'date_due':vch_date,'journal_id':1,'state':'draft','origin':vch_type}])
                    print(rslt)

                    for st,ratt,quant,discon  in zip(stockslist,amountlist,quantitylist,discountlist):
                        # rateval=calculate_rate(ratt,quant)
                        ratevals=float(ratt)
                        mid=models.execute_kw(db,uid, password, 'product.product','search',[[['name', '=', st]]])
                        print(mid,'bye')
                        for stockna in mid:
                            stock=stockna
                            va=models.execute_kw(db, uid, password,'product.product', 'read',[mid], {'fields': [ 'taxes_id']})
                            print(va)
                            for taxed in va:
                                taxfv=taxed['taxes_id']
                            print(taxfv,'hi')
                            if taxfv==[]:
                                taxfv=myliist3

                                # Oid=models.execute_kw(db, uid, password, 'account.tax','search',[[['name', '=','CGST'],['type_tax_use','=','sale']]])
                                # Otd=models.execute_kw(db, uid, password, 'account.tax','search',[[['name', '=','SGST'],['type_tax_use','=','sale']]])
                                # Oid=Oid+Otd
                                # taxfv=Oidk
                                # print(Oid)
                            else:
                                taxfv==taxfv

                            print(taxfv,'final')

                            




                            res=models.execute_kw(db, uid, password, 'account.invoice','write',[[rslt],{'invoice_line_ids':
                            [(0,4, {'name': st,
                            'origin': vch_type,
                            'account_id':31,
                            'price_unit': ratevals,
                            'quantity': quant,
                            'is_rounding_line': True,
                            'discount':discon,
                        
                            'uom_id': 1,
                            
                            
                            'product_id': stock,

                            'invoice_line_tax_ids': [[6,True, taxfv]]
                            }
                        
                            )
                            ]
                            }
                            ]
                            

                            )
                        
                            res=models.execute_kw(db, uid, password, 'account.invoice','compute_taxes',[rslt])
                    # print(roundofflist)
                    for ron in roundofflist:
                        round=models.execute_kw(db, uid, password, 'account.invoice','write',[[rslt],{'invoice_line_ids':[(0,4, {'name': 'Rounded off',
                        'account_id': 284,
                        'price_unit': ron,
                        'quantity': 1})]}])
                    vali=models.execute_kw(db, uid, password, 'account.invoice','action_invoice_open',[rslt])

enter image description here

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum