Odoo Aide

1
1 Answer
1
Avatar

Yenthe Van Ginneken

--Yenthe Van Ginneken--
15098
| 8 8 10
Belgique
--Yenthe Van Ginneken--

My Odoo blog: http://www.odoo.yenthevg.com/

My Twitter: https://twitter.com/Yenthe666


Yenthe Van Ginneken
17/11/2018 04:48

Hi Pawan,

You're adding a worksheet per contact in your for loop over the partners. If you move that part outside of the for loop it will add all partners in one single page. You where also setting the format again for every single contact. This should work:

from odoo.addons.report_xlsx.report.report_xlsx import ReportXlsx

class PartnerXlsx(ReportXlsx):
    def generate_xlsx_report(self, workbook, data, partners):
	    report_name = obj.name
        print("REPRTTTTTTT", report_name, report_name[:31])
        # One sheet by partner
        sheet = workbook.add_worksheet(report_name[:31])
        bold = workbook.add_format({'bold': True})
        index = 0
        for obj in partners:
            sheet.write(index, 0, obj.name, bold)
            sheet.write(index, 1, obj.email, bold)
            sheet.write(index, 2, obj.telephone, bold)
            index +=1
PartnerXlsx('report.res.partner.xlsx', 'res.partner')

Note: You're writing on row "0" every time with sheet.write(0). You might want to add an index/counter to the function and use this as I've did in this code.

Regards,
Yenthe

6 Comments
SunArc Technologies, Pawan Sharma
17/11/2018 05:20

Hello Yenthe,

Now, i am getting only single sheet but show only single row(last record). I think some append condition missing in above code.

Yenthe Van Ginneken
17/11/2018 06:41

Hi Pawan, I see your issue. You keep setting the values on the first row (sheet.write(0)) always applies on the first. Add an index to it.

Yenthe Van Ginneken
17/11/2018 06:42

I've updated the code to reflect that too.

SunArc Technologies, Pawan Sharma
17/11/2018 08:03

Thanks Yenthe,

i updated code with "for index, obj in enumerate(partners):"

Yenthe Van Ginneken
17/11/2018 11:05

You're welcome, best of luck!

SunArc Technologies, Pawan Sharma
18/11/2018 23:53

Thanks...

Poser une question
Writer
Étiquettes
Keep Informed
1 Abonné(e)s
About This Community

This platform 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.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now