Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
1046 Zobrazení

I'm trying to export products with diffrent prices from the PRICE lists can I get help

Avatar
Zrušit
Nejlepší odpověď

There’s no direct way in Odoo to export a report that shows which product has what price across different price lists. However, you can achieve this by writing a Python script that loops through all your products, checks each price list for the product, and then exports the results to an Excel file.

The script below scans all price lists for product variants, retrieves their prices, and writes them into an Excel file:

import xlsxwriter

import odoo

from odoo import api, models


def export_pricelist_data(env):

    """Exports all product prices across all price lists into an Excel file."""

   

    # Create an Excel file

    file_path = "/tmp/pricelist_export.xlsx"  # Change path if needed

    workbook = xlsxwriter.Workbook(file_path)

    worksheet = workbook.add_worksheet("Pricelists")

   

    # Define column headers

    headers = ["Product Variant", "Product Name", "Pricelist", "Price"]

    for col, header in enumerate(headers):

        worksheet.write(0, col, header)


    row = 1  # Start writing data from row 1

   

    # Fetch all product variants and pricelists

    product_variants = env['product.product'].search([])

    pricelists = env['product.pricelist'].search([])


    for product in product_variants:

        for pricelist in pricelists:

            price = pricelist._get_product_price(product, 1.0)  # Get price for 1 unit

           

            if price:  # Only include products that exist in the pricelist

                worksheet.write(row, 0, product.default_code or product.id)

                worksheet.write(row, 1, product.name)

                worksheet.write(row, 2, pricelist.name)

                worksheet.write(row, 3, price)

                row += 1


    # Save and close the workbook

    workbook.close()

    print(f"Pricelist data exported successfully to {file_path}")

    return file_path  # Return file path for reference


This is a rough idea about the code and you can refine it the way you want it to be. I hope it helps.

Thanks,
Abhay

Avatar
Zrušit
Autor

Thanks So much abahy
but what about export just one PRICE list but the PRICE is formula OR percentage I need to show the final PRICE of the PRICE list

Related Posts Odpovědi Zobrazení Aktivita
1
srp 25
170
2
srp 25
147
3
srp 25
787
1
srp 25
303
0
srp 25
453