Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
6414 Lượt xem

Hello,
I am new in odoo. I wanted to generate a report - an excel format. I am looking for a python approach example for these sample data.

This my xml for the qweb in my pdf format:

<tbody class="table_data">
<t t-set="pickings" t-value="o.get_pickings(date_start, date_end)" />
<t t-foreach="pickings" t-as="pick">
<t t-set="line_items" t-value="o.get_line_items(pick)"/>
    <t t-foreach="line_items" t-as="line">
        <tr>
         <td><span t-esc="i"/><t t-set="i" t-value="i+1"/></td>
            <td><span t-esc="line.get('partner_name')" /></td>
            <td><span t-esc="line.get('si_number')" /></td>
            <td><span t-esc="line.get('product_name')" /></td>
            <td><span t-esc="line.get('done_qty')" /></td>
            <t t-set="qty" t-value="qty + line.get('done_qty')"/>
        </tr>
    </t>
</t>
<tr class="total">
<td colspan="3"></td>
<td><span>Total:</span></td>
<td><span t-esc="qty" /></td>
</tr>
</tbody>

I tried to display this in excel but got error.

the items:

    @api.multi
    def get_line_items(self, picking_id):
        line_items = picking_id.pack_operation_ids
        items = []
        for item in line_items:
            items.append({"product_name": item.product_id.name, "done_qty": item.qty_done, 
                          "si_number": " ".join([ invoice.name for invoice in picking_id.sale_id.invoice_ids]),
                          "partner_name": picking_id.partner_id.name })
        
       
        return items


for excel:

        sheet.write(0, 1, "REPORT", header_title)    
        sheet.write(4, 0, "CUSTOMER NAME")
        sheet.write(4, 1, "I.S. #")
        sheet.write(4, 2, "PRODUCT NAME")
        sheet.write(4, 3, "NO. OF BAGS")
               
        get_line_items = self.get_line_items(picking_id)     
                
        for i in get_line_items:
            print("get_line_items",i)      

error:

get_line_items = self.get_line_items(picking_id)
NameError: global name 'picking_id' is not defined
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

You can try this connector from odoo appstore
It is easy to install and is integrated in excel itself
https://apps.odoo.com/apps/modules/18.0/excel_connector

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

If you are looking how to create excel report in odoo, see this tutorial explaining the same:  How to Create Excel report in Odoo


An example of XLSX report for partners on a module called module_name:

A python class

from odoo import models

class PartnerXlsx(models.AbstractModel):
    _name = 'report.module_name.report_name'
    _inherit = 'report.report_xlsx.abstract'

    def generate_xlsx_report(self, workbook, data, partners):
        for obj in partners:
            report_name = obj.name
            # One sheet by partner
            sheet = workbook.add_worksheet(report_name[:31])
            bold = workbook.add_format({'bold': True})
            sheet.write(0, 0, obj.name, bold)

To manipulate the workbook and sheet objects, refer to the documentation of xlsxwriter.

A report XML record

<report
    id="partner_xlsx"
    model="res.partner"
    string="Print to XLSX"
    report_type="xlsx"
    name="module_name.report_name"
    file="res_partner"
    attachment_use="False"
/>
Supporting Module:  Base report xlsx

Thanks

Ảnh đại diện
Huỷ bỏ
Tác giả

Hello, thank you for your kind response. I updated my post. I am having an error to get the items from get_line_items().

get_line_items = self.get_line_items(picking_id) , what is picking_id here refers to ?

Tác giả

@api.multi

def get_partner_name(self, picking_id):

partner_name = picking_id.partner_id.name

return partner_name

@api.multi

def get_line_items(self, picking_id):

line_items = picking_id.pack_operation_ids

items = []

for item in line_items:

items.append({"product_name": item.product_id.name, "done_qty": item.qty_done,

"si_number": " ".join([ invoice.name for invoice in picking_id.sale_id.invoice_ids]),

"partner_name": picking_id.partner_id.name })

return items

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 7 21
176
0
thg 4 21
331
1
thg 11 18
6393
3
thg 11 17
23230
0
thg 3 21
6663