تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
5 الردود
16080 أدوات العرض

Hello, I associated with a button a method that allows the generation of an xlsx file, I would like to return the file just created, as for a normal file, with the Save as...

This is my code, I do not know how to write the return, I need help.

   @api.multi
    def export(self):
        workbook = xlsxwriter.Workbook('/tmp/test.xlsx')
        worksheet = workbook.add_worksheet()
        row = 0
        col = 0
        for vals in self.carrier_line_ids:
            worksheet.write(row, 0, vals.reference)
            ...
            ...
            row += 1


        workbook.close()
الصورة الرمزية
إهمال
الكاتب أفضل إجابة

My solution:

@api.multi
    def export(self):
        file_name = 'temp'
        workbook = xlsxwriter.Workbook(file_name, {'in_memory': True})
        worksheet = workbook.add_worksheet()
        row = 0
        col = 0
        for e in header:
            worksheet.write(row, col, e)
            col += 1
        row += 1
        for vals in self.carrier_line_ids:
            worksheet.write(row, 0, vals.reference)
            ...
            ...
        workbook.close()
        with open(file_name, "rb") as file:
            file_base64 = base64.b64encode(file.read())
         self.carrier_xlsx_document_name = self.name + '.xlsx'
        self.write({'carrier_xlsx_document': file_base64, })

carrier_xlsx_document is a binary


view.xml

<field name="carrier_xlsx_document" widget="binary" filename="carrier_xlsx_document_name"
attrs="{'invisible':[('state','=', 'draft')]}" readonly="1"/>
<field name="carrier_xlsx_document_name" invisible="1"/>

Add to import xlsxwriter and base64

I hope this solution can help other programmers.

A request for mods: you can change the name of the thread and add SOLVED, I can't.

الصورة الرمزية
إهمال

Hi, I am trying this solution but I get the following error message:
FileNotFoundError: [Errno 2] No such file or directory: 'Registro_Ventas_12/2021.xlsx'
Do you know why is this happening?
This is my code:
def write_xlsx(self, file_name, header_list, field_list):
workbook = xlsxwriter.Workbook(file_name, {'in_memory': True})
worksheet = workbook.add_worksheet()
row = col = 0
# Write header row
for header in header_list:
worksheet.write(row, col, header)
col += 1
row += 1
# Write value rows
n = 1
for line in self.lcv_line_ids:
line_registry = self.env['lcv.line'].browse([line.id])
worksheet.write(row, 0, n)
col = 1
for field in field_list:
if isinstance(getattr(line_registry, field), float):
value = str(round(getattr(line_registry, field), 2))
else:
value = str(getattr(line_registry, field))
worksheet.write(row, col, value)
col += 1
n += 1
row += 1
workbook.close()
with open(file_name, "wb") as file:
file_base64 = base64.b64encode(file.read())
return file_base64

أفضل إجابة

I have no clue how to help you, but the forum software won't let me ask my question until I've answered other people's questions, so I'm going to go with a classic answer: paint ram's blood over your doorway.

الصورة الرمزية
إهمال
أفضل إجابة

Hi Paolo,

Go to,

Setting>>Translation>>Import/ Export>>Export Translation

The popup wizard generate the translation file and allow you to download the file.

This will give you an idea how you can make it to work with your module.

You will find the reference code inside base mdoule

I hope this will give you an idea, how you can hit the goal.

Rgds,

Anil.





الصورة الرمزية
إهمال
أفضل إجابة

Hi,

We have a written a blog about how to create XLS report in odoo 10, you can go through it: How to Create an XLS Report in Odoo ?


Thanks

الصورة الرمزية
إهمال
الكاتب

This does not help me, I create an xlsx file and I want it to be saved, for now I create it but I can not generate the window with a direct link to the file.

المنشورات ذات الصلة الردود أدوات العرض النشاط
2
أبريل 24
22281
0
يونيو 23
3137
0
أكتوبر 20
3403
3
يونيو 20
9110
0
أبريل 16
6237