Skip to Content
Menu
This question has been flagged
2 Replies
8829 Views

I Created two buttons one for creating excel file and one for downloading created excel file. My XML code:

<group string="Employee Attendance">
                                          <group>
                                      <button string="Generate Attendance" name="generate_attendance_file" type="object"/>
                                      </group>
                                      <group>
                                        <button string="Download Attendance File" name="download_attendance_file" type="download_file" />

                                          </group>
                                    </group>

And my Python code:

def generate_attendance_file(self):
        workbook = xlsxwriter.Workbook('test.xlsx')
        worksheet1 = workbook.add_worksheet('My 1')
        worksheet1.write('A1','Col 1')
        worksheet1.write('B1','Col 2')
        worksheet1.write('C1','Col 3')
        db = pyodbc.connect('DRIVER={SQL Server};SERVER=OWNER-PC\SQLEXPRESS;DATABASE=etimetracklite;UID=test;PWD=rimt')
        cursor = db.cursor()
        sql = "select StatusCode from AttendanceLogs where EmployeeId='3010' AND AttendanceDate Between '2018-11-1' AND '2018-11-14'"
        cursor.execute(sql)
        results = cursor.fetchall()
        i = 2;
        for row in results:
            worksheet1.write('A' + str(i), row[0])
            i += 1
        bold = workbook.add_format({'bold': True})
        db.close()
        workbook.close()


   
    @api.multi
    def download_attendance_file(self):
        wb = xlrd.open_workbook('test.xlsx')
        output = io.Bytes()
        workbook.save(output)
        output.seek(0)
        data = output.read()
        return data

But I have following issue in downloading button:

Error:
TypeError: this.do_execute_action(...) is undefined

http://localhost:8069/web/content/1960-cc3f4ba/web.assets_backend.js:469
Traceback:
execute_action@http://localhost:8069/web/content/1960-cc3f4ba/web.assets_backend.js:469:620
proxy/<@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:3923:8
trigger@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:3921:166
_trigger_up@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:3927:340
_trigger_up@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:3927:442
trigger_up@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:3927:275
_callButtonAction@http://localhost:8069/web/content/1960-cc3f4ba/web.assets_backend.js:1310:1689
saveAndExecuteAction/<@http://localhost:8069/web/content/1960-cc3f4ba/web.assets_backend.js:1412:648
then/</</<@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:802:678
fire@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:796:281
add@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:797:467
then/</<@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:802:649
each@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:625:758
then/<@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:802:553
Deferred@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:803:189
then@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:802:518
saveAndExecuteAction@http://localhost:8069/web/content/1960-cc3f4ba/web.assets_backend.js:1412:577
_onButtonClicked@http://localhost:8069/web/content/1960-cc3f4ba/web.assets_backend.js:1413:340
proxy/<@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:3923:8
trigger@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:3921:166
_trigger_up@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:3927:340
_trigger_up@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:3927:442
trigger_up@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:3927:275
_addOnClickAction/<@http://localhost:8069/web/content/1960-cc3f4ba/web.assets_backend.js:1372:329
dispatch@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:892:378
add/elemData.handle@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:865:151

Avatar
Discard
Best Answer

Hello,

Check below code for how to create xls report

class SalesXlsx(ReportXlsx):

    def generate_xlsx_report(self, workbook, data, sales_order):
        sheet = workbook.add_worksheet('Sales Customer Report')
        bold = workbook.add_format({'bold': True})
        sheet.write(0, 0, 'Customer', bold)
        sheet.write(0, 1, 'Number', bold)
        for index, obj in enumerate(rental):
            index = index+1
            if obj.partner_id:sheet.write(index, 0, obj.partner_id)
            if obj.telephone:sheet.write(index, 1, obj.telephone)
           
RentalXlsx('sale.order.xlsx', 'sale.order')


May Be it's help you.

Avatar
Discard
Author Best Answer

same error

Error:
TypeError: this.do_execute_action(...) is undefined

http://localhost:8069/web/content/1960-cc3f4ba/web.assets_backend.js:469
Traceback:
execute_action@http://localhost:8069/web/content/1960-cc3f4ba/web.assets_backend.js:469:620
proxy/<@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:3923:8
trigger@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:3921:166
_trigger_up@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:3927:340
_trigger_up@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:3927:442
trigger_up@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:3927:275
_callButtonAction@http://localhost:8069/web/content/1960-cc3f4ba/web.assets_backend.js:1310:1689
saveAndExecuteAction/<@http://localhost:8069/web/content/1960-cc3f4ba/web.assets_backend.js:1412:648
then/</</<@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:802:678
fire@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:796:281
add@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:797:467
then/</<@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:802:649
each@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:625:758
then/<@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:802:553
Deferred@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:803:189
then@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:802:518
saveAndExecuteAction@http://localhost:8069/web/content/1960-cc3f4ba/web.assets_backend.js:1412:577
_onButtonClicked@http://localhost:8069/web/content/1960-cc3f4ba/web.assets_backend.js:1413:340
proxy/<@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:3923:8
trigger@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:3921:166
_trigger_up@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:3927:340
_trigger_up@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:3927:442
trigger_up@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:3927:275
_addOnClickAction/<@http://localhost:8069/web/content/1960-cc3f4ba/web.assets_backend.js:1372:329
dispatch@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:892:378
add/elemData.handle@http://localhost:8069/web/content/1723-e9a3b9f/web.assets_common.js:865:151

Avatar
Discard
Related Posts Replies Views Activity
2
Sep 18
6363
1
Jan 19
4531
0
Dec 18
2908
2
Apr 18
6820
4
Dec 23
16370