Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

export excel in openerp v7

By
lam a bao
on 4/14/14, 6:26 AM 1,210 views

Hi everyone i have module 'cnd_quotations',now i have code :

  def exportexcel(self,req,salecorder,server):

    now = datetime.datetime.now()
    now.hour
    now.year
    now.day
    now.month
    #workbook = xlsxwriter.Workbook("/cnd_quotations/static/src/data/"+str(now.day)+"_"+str(now.month)+"_"+str(now.year)+"_"+str(salecorder)+'.xlsx')
    workbook = xlsxwriter.Workbook("openerp/addons/cnd_quotations/static/src/data/"+str(now.day)+"_"+str(now.month)+"_"+str(now.year)+"_"+str(salecorder)+'.xlsx')
    worksheet = workbook.add_worksheet()
    worksheet.set_column('A:A', 20)
    bold = workbook.add_format({'bold': True})
    worksheet.write('A1', 'Sale order code')
    worksheet.write(0, 1, 123)
    cookie_db = req.httprequest.cookies.get('last_used_database')
    resgister=RegistryManager.get(cookie_db)
    with resgister.cursor() as cr:
        cp=resgister.get('cvs.quoations.chitiet.dichvu.tigia')
        cp_search=cp.read(cr,SUPERUSER_ID,cp.search(cr,SUPERUSER_ID,[('saleorder','=',str(salecorder))]),[])
        for item in cp_search:
            worksheet.write('A5', str('Giá Nhôm Thị Trường (USD)').decode('utf-8'), bold)
            worksheet.write(5, 0, item['gianhomthitruong'])
            worksheet.write('B5', str('Tỉ Giá(VNĐ)').decode('utf-8'), bold)
            worksheet.write(5, 1, item['tigia'])
            worksheet.write('C5', str('Tỉ Lệ').decode('utf-8'), bold)
            worksheet.write(5, 2, item['tile'])
        cp1=resgister.get('cvs.quoations.baogia.new.nhom')
        cp_search1=cp1.read(cr,SUPERUSER_ID,cp1.search(cr,SUPERUSER_ID,[('saleorder','=',str(salecorder))]),[])


        worksheet.write('A9', str('Hạng Mục').decode('utf-8'), bold)
        worksheet.write('B9', str('Chiều Rộng(mm)').decode('utf-8'), bold)
        worksheet.write('C9', str('Chiều Cao(mm)').decode('utf-8'), bold)
        worksheet.write('D9', str('Số Lượng').decode('utf-8'), bold)
        worksheet.write('E9', str('ĐVT').decode('utf-8'), bold)
        worksheet.write('F9', str('Dịch Vụ').decode('utf-8'), bold)
        worksheet.write('G9', str('Trọng Lượng').decode('utf-8'), bold)
        worksheet.write('H9', str('Đơn Giá').decode('utf-8'), bold)
        worksheet.write('I9', str('Thành Tiền').decode('utf-8'), bold)
        _icr=10;
        for item1 in cp_search1:
            worksheet.write(_icr,0,item1['tennhom'])
            worksheet.write(_icr, 1, item1['chieurong'])
            worksheet.write(_icr, 2, item1['chieucao'])
            worksheet.write(_icr, 3, item1['soluong'])
            worksheet.write(_icr, 4, item1['dvt'])
            #worksheet.write(5, 5, item['tile'])
            worksheet.write(_icr, 6, item1['trongluong'])
            worksheet.write(_icr, 7, item1['dongia'])
            worksheet.write(_icr, 8, item1['thanhtien'])
            _icr=_icr+1
        cp2=resgister.get('cvs.quoations.baogia.new.kinh')
        cp_search2=cp2.read(cr,SUPERUSER_ID,cp2.search(cr,SUPERUSER_ID,[('saleorder','=',str(salecorder))]),[])
        worksheet.write('A'+str((_icr+2)), str('Kính').decode('utf-8'), bold)
        worksheet.write('B'+str((_icr+2)), str('Chiều Rộng(mm)').decode('utf-8'), bold)
        worksheet.write('C'+str((_icr+2)), str('Chiều Cao(mm)').decode('utf-8'), bold)

        worksheet.write('D'+str((_icr+2)), str('ĐVT').decode('utf-8'), bold)
        worksheet.write('E'+str((_icr+2)), str('Dịch Vụ').decode('utf-8'), bold)

        worksheet.write('F'+str((_icr+2)), str('Đơn Giá').decode('utf-8'), bold)
        worksheet.write('G'+str((_icr+2)), str('Thành Tiền').decode('utf-8'), bold)
        _ho=_icr+3
        for item2 in cp_search2:
            worksheet.write(_ho,0,item2['tenkinh'])
            worksheet.write(_ho, 1, item2['chieurong'])
            worksheet.write(_ho, 2, item2['chieucao'])
            worksheet.write(_ho, 3, item2['dvt'])
            #worksheet.write(5, 5, item['tile'])
            worksheet.write(_ho, 4, item2['dongia'])
            worksheet.write(_ho, 5, item2['thanhtien'])
        cp3=resgister.get('cvs.quoations.baogia.new.phukien')
        cp_search3=cp3.read(cr,SUPERUSER_ID,cp3.search(cr,SUPERUSER_ID,[('saleorder','=',str(salecorder))]),[])

        worksheet.write('A'+str((_ho+2)), str('Tên Phụ Kiện').decode('utf-8'), bold)
        worksheet.write('B'+str((_ho+2)), str('Số Lượng)').decode('utf-8'), bold)
        worksheet.write('C'+str((_ho+2)), str('ĐVT').decode('utf-8'), bold)
        worksheet.write('F'+str((_ho+2)), str('Đơn Giá').decode('utf-8'), bold)
        worksheet.write('G'+str((_ho+2)), str('Thành Tiền').decode('utf-8'), bold)
        _ko=_ho+3
        for item3 in cp_search3:
            worksheet.write(_ko,0,item3['tenphukien'])
            worksheet.write(_ko, 1, item3['soluong'])
            worksheet.write(_ko, 2, item3['dvt'])
            worksheet.write(_ko, 4, item3['dongia'])
            worksheet.write(_ko, 5, item3['thanhtien'])


    workbook.close()

but error "Uncaught TypeError: Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided"

can you help me?

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 4/14/14, 6:26 AM
Seen: 1210 times
Last updated: 3/16/15, 8:10 AM