Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
457 views
in Technique[技术] by (71.8m points)

xlsxwriter - Remove Duplicate Items in odoo Looping

Hy , I want to print odoo in XLSX, this is my code:

    def generate_xlsx_report(self, workbook, data, lines):
    format = workbook.add_format({'font_size' : 12, 'align': 'center', 'bold' : True})
    format1 = workbook.add_format({'font_size': 12, 'align': 'center', 'bold': False})
    sheet = workbook.add_worksheet("Assets")
    sheet.set_row(0, 24)
    sheet.set_column('A1:O1', 20)
    headers = [
        "No",
        "Asset Name",
        "Category",
        "Date",
        "Partners",
        "Gros Value",
        "Residual Value",
        "Value",
        "Number Of Depreciations",
        "Number of Month in a Period"
        "Depre Date",
    ]

    column = 0
    row = 0
    for col in headers:
        sheet.write(row, column, col, format)
        column += 1

    row = 1
    final_data = []
    no = 1
    for data in lines:
            for datas in data:
                for depre in datas.depreciation_line_ids:
                    final_data.append([
                    no,
                    datas.name,
                    datas.category_id.name,
                    datas.date.strftime("%Y-%m-%d"),
                    "Maju mundur",
                    datas.value,
                    datas.salvage_value,
                    datas.value_residual,
                    datas.method_number,
                    datas.method_period,
                    depre.depreciation_date.strftime("%Y-%m-%d"),
                    ])
                    no += 1

    for data in final_data:
        column = 0
        for col in data:
            sheet.write(row, column, col,format1)
            column += 1
        row += 1

    workbook.close()

And this is my expecation output

enter image description here

Each assets have many depreciation, but when I print assets, output like below :

enter image description here

How to just return each assets ( no duplicate) , look , Asset Name, Category and Date is duplicate data, even tough is just 1 data , how to print output each assets and have many depreciation date?
Thanks


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...