Siirry sisältöön
Odoo Menu
  • Kirjaudu sisään
  • Kokeile ilmaiseksi
  • Sovellukset
    Talous
    • Kirjanpito
    • Laskutus
    • Kulut
    • Datataulukot (BI)
    • Asiakirjat
    • Allekirjoita
    Myynti
    • CRM
    • Myynti
    • Kassajärjestelmä myymälään
    • Kassajärjestelmä ravintolaan
    • Tilaukset
    • Vuokraus
    Verkkosivut
    • Verkkosivun Rakennustyökalu
    • Verkkokauppa
    • Blogi
    • Foorumi
    • Livechat
    • Verkko-oppiminen
    Toimitusketju
    • Varastointi
    • Tuotanto
    • Tuotteen elinkaaren hallinta (PLM)
    • Ostot
    • Huolto
    • Laatu
    Henkilöstöhallinto
    • Työntekijät
    • Rekrytointi
    • Vapaat
    • Arvioinnit
    • Suositukset
    • Kuljetuskalusto
    Markkinointi
    • Somemarkkinointi
    • Sähköpostimarkkinointi
    • Tekstiviestimarkkinointi
    • Tapahtumat
    • Markkinoinnin automaatio
    • Kyselyt
    Palvelut
    • Projekti
    • Työaikakirjaukset
    • Kenttähuolto
    • Asiakaspalvelu
    • Suunnittelu
    • Ajanvaraukset
    Tuottavuus
    • Viestintä
    • Tekoäly
    • IoT
    • IP-puhe
    • Tietokirjasto
    • WhatsApp
    Kolmannen osapuolen sovellukset Odoo-Studio Odoo-Pilvialusta
  • Toimialat
    Vähittäiskauppa
    • Kirjakauppa
    • Vaatekauppa
    • Huonekaluliike
    • Ruokakauppa
    • Laitteistokauppa
    • Lelukauppa
    Ruoka & Majoitus
    • Baari ja Pubi
    • Ravintola
    • Pikaruoka
    • Majatalo
    • Juomien jakelija
    • Hotelli
    Kiinteistöt
    • Kiinteistönvälitystoimisto
    • Arkkitehtitoimisto
    • Rakentaminen
    • Kiinteistönhallinto
    • Puutarhanhoito
    • Kiinteistönomistajien yhdistys
    Konsultointi
    • Tilitoimisto
    • Odoo-kumppani
    • Markkinointitoimisto
    • Lakitoimisto
    • Osaajahankinta
    • Tilintarkastus & sertifiointi
    Tuotanto
    • Tekstiili
    • Metalli
    • Huonekalut
    • Ruoka
    • Panimo
    • Yrityslahjat
    Terveys & Liikunta
    • Urheiluseura
    • Silmälasiliike
    • Kuntokeskus
    • Hyvinvointialan ammattilaiset
    • Apteekki
    • Kampaamo
    Kaupat
    • Yleismies
    • IT-laitteisto & Tuki
    • Aurinkoenergiajärjestelmät
    • Suutari
    • Siivouspalvelut
    • LVI-palvelut
    Muut
    • Voittoa tavoittelematon järjestö
    • Ympäristötoimisto
    • Mainostaulujen vuokraus  
    • Valokuvaus
    • Leasing-pyörät
    • Ohjelmistojen jälleenmyyjä
    Selaa kaikkia toimialoja
  • Yhteisö
    Opi
    • Kurssit
    • Dokumentaatio
    • Todistukset
    • Koulutus
    • Blogi
    • Podcast
    Kannusta kouluttautumaan
    • Koulutusohjelmat
    • Scale Up! Liiketoimintapeli
    • Vieraile Odoolla
    Hanki ohjelmisto
    • Lataa
    • Vertaile versioita
    • Julkaisut
    Tee yhteistyötä
    • Github
    • Foorumi
    • Tapahtumat
    • Käännökset
    • Ryhdy kumppaniksi
    • Kumppanipalvelut
    • Rekisteröi tilitoimistosi
    Hanki palveluja
    • Löydä kumppani
    • Löydä kirjanpitäjä
    • Varaa asiantuntijatapaaminen
    • Implementaatiopalvelut
    • Asiakasreferenssit
    • Tuki
    • Versionkorotukset
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Varaa demo
  • Hinnoittelu
  • Asiakaspalvelu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Kaikki kirjoitukset Ihmiset Merkit
Tunnisteet (Näytä kaikki)
odoo accounting v14 pos v15
Tietoa tästä foorumista
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Kaikki kirjoitukset Ihmiset Merkit
Tunnisteet (Näytä kaikki)
odoo accounting v14 pos v15
Tietoa tästä foorumista
Apua

How to download the Pivot table Excel using python code?

Tilaa

Saat ilmoituksen, kun tähän viestiin ilmaantuu aktiviteettia

Tämä kysymys on merkitty
3 Vastaukset
5848 Näkymät
Avatar
Tintuk Tomin

We know that in every pivot table we have the option to download the excel file of that pivot table in a single click using the download button.
Now what i need to do is to get this report and attach this report with the mail and send it to the employee every day.

I found the way to attach the document to the mail and send it automatically. But am unable to find a way to download the excel from the pivote table through code. 

Is anyone having the solution please help me.

0
Avatar
Hylkää
Avatar
Mohammed.Samy
Paras vastaus

Hi there,

You have hit a very common roadblock in Odoo development. The reason you cannot simply call a Python method to "download the pivot table" is because the pivot table export is generated client-side by JavaScript, not server-side by Python.

When a user clicks that download button, Odoo's frontend JavaScript reads the current matrix on their screen and sends a formatted dictionary to a web controller (usually /web/pivot/export_xls), which then returns the file. Because your automated action (cron job) runs entirely in the backend without a browser interface, it cannot trigger that JavaScript process.

To achieve this automatically via code, you have to recreate the data pull and the Excel file generation in Python. Here is the standard architectural approach to do this using Odoo's built-in xlsxwriter library:

1. The Python Logic

You will need to write a Python method (which your scheduled action will call) that does three things:

  1. Queries the data using read_group() (this is the same ORM method the pivot view uses).

  2. Writes that data into a virtual Excel file using xlsxwriter and io.BytesIO.

  3. Encodes the file to Base64 and creates an ir.attachment.

2. Example Code Template

Here is a boilerplate template using sale.order as an example. You will need to adapt the read_group parameters and the worksheet loops to match your specific model and columns.

Python

import io
import base64
import xlsxwriter
from odoo import models, fields, api

class DailyPivotReport(models.Model):
    _name = 'daily.pivot.report'
    _description = 'Automated Pivot Excel Generator'

    @api.model
    def generate_and_send_pivot_excel(self):
        # 1. Fetch the aggregated data (simulate the pivot backend)
        domain = [('state', 'in', ['sale', 'done'])]
        fields_to_read = ['amount_total']
        groupby = ['user_id']
        
        # read_group returns a list of dictionaries with your grouped data
        pivot_data = self.env['sale.order'].read_group(domain, fields_to_read, groupby)

        # 2. Create the Excel file in memory
        output = io.BytesIO()
        workbook = xlsxwriter.Workbook(output, {'in_memory': True})
        worksheet = workbook.add_worksheet('Daily Report')

        # Formatting (Optional)
        bold = workbook.add_format({'bold': True})

        # Write Headers
        worksheet.write(0, 0, 'Salesperson', bold)
        worksheet.write(0, 1, 'Total Sales', bold)

        # Write Data
        row = 1
        for record in pivot_data:
            # Handle cases where user_id might be False
            user_name = record['user_id'][1] if record.get('user_id') else 'Undefined'
            total = record.get('amount_total', 0.0)
            
            worksheet.write(row, 0, user_name)
            worksheet.write(row, 1, total)
            row += 1

        # Close and prepare the file for attachment
        workbook.close()
        output.seek(0)
        excel_data = output.read()
        excel_base64 = base64.b64encode(excel_data)

        # 3. Create the Attachment
        attachment = self.env['ir.attachment'].create({
            'name': 'Daily_Sales_Pivot.xlsx',
            'type': 'binary',
            'datas': excel_base64,
            'mimetype': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
        })

        # 4. Attach to your email template and send
        template = self.env.ref('your_module.your_mail_template_id')
        
        # Temporarily link attachment to template, send, then clean up
        template.attachment_ids = [(4, attachment.id)]
        template.send_mail(self.id, force_send=True)
        template.attachment_ids = [(3, attachment.id)] 

Summary of Next Steps

Since you already have the email automation figured out, you just need to drop this logic into your cron job's target method. Adjust the domain, fields_to_read, and groupby variables to match the exact filters and groupings you have set up in your frontend pivot view.

It takes a bit of manual formatting to get the Python-generated Excel file to look exactly like the Odoo UI version, but this io.BytesIO method is the cleanest, most standard way to generate backend .xlsx files in Odoo without relying on third-party apps.

0
Avatar
Hylkää
Avatar
Yeison X
Paras vastaus

Hello! You've done it? I also want to automatically send a pivot report.

0
Avatar
Hylkää
Tintuk Tomin
Tekijä

No... Not yet

Jothimani Rajagopal

Send Pivot reports automatically by minutes, hours, days, weeks and months from Odoo.

https://apps.odoo.com/apps/modules/13.0/pivot_scheduler

Avatar
Jothimani Rajagopal
Paras vastaus

Hi Tintuk Tomin,

Please review this module https://apps.odoo.com/apps/modules/13.0/pivot_scheduler, I hope it would help you.

0
Avatar
Hylkää
Nautitko keskustelusta? Älä vain lue, vaan osallistu!

Luo tili jo tänään nauttiaksesi yksinoikeusominaisuuksista ja osallistuaksesi mahtavaan yhteisöömme!

Rekisteröidy
Yhteisö
  • Kurssit
  • Dokumentaatio
  • Foorumi
Avoin lähdekoodi
  • Lataa
  • Github
  • Runbot
  • Käännökset
Palvelut
  • Odoo.sh hosting
  • Tuki
  • Versionkorotus
  • Räätälöidyt kehitykset
  • Koulutus
  • Löydä kirjanpitäjä
  • Löydä kumppani
  • Ryhdy kumppaniksi
Meistä
  • Yrityksemme
  • Brändiominaisuudet
  • Ota yhteyttä
  • Työpaikat
  • Tapahtumat
  • Podcast
  • Blogi
  • Asiakkaat
  • Oikeudellinen ilmoitus • Yksityisyys
  • Tietoturva
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk Slovenščina Español (América Latina) Español Svenska ภาษาไทย Türkçe українська Tiếng Việt

Odoo on kokoelma avoimen lähdekoodin yrityssovelluksia, jotka kattavat kaikki yrityksesi tarpeet: asiakkuudenhallinta eli CRM, verkkokauppa, kirjanpito, varastointi, kassajärjestelmä, projektinhallinta, jne.

Odoon ainutlaatuinen arvolupaus on olla samanaikaisesti erittäin helppokäyttöinen ja täysin integroitu.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now