コンテンツへスキップ
Odoo メニュー
  • サインイン
  • 無料で15日試す
  • アプリ
    財務
    • 会計
    • 請求
    • 経費
    • スプレッドシート(BI)
    • ドキュメント管理
    • 署名
    販売
    • CRM
    • 販売
    • POSショップ
    • POSレストラン
    • サブスクリプション
    • レンタル
    ウェブサイト
    • ウェブサイトビルダー
    • eコマース
    • ブログ
    • フォーラム
    • ライブチャット
    • eラーニング
    サプライチェーン
    • 在庫
    • 製造
    • 製品ライフサイクル管理 (PLM)
    • 購買
    • 整備
    • 品質
    人事業務
    • 従業員管理
    • 採用
    • 休暇管理
    • 人事評価
    • リファラル
    • フリート
    マーケティング
    • ソーシャルマーケティング
    • メールマーケティング
    • SMSマーケティング
    • イベント
    • マーケティングオートメーション
    • アンケート調査
    サービス
    • プロジェクト管理
    • タイムシート
    • フィールドサービス
    • ヘルプデスク
    • 計画
    • アポイントメント
    生産性向上ツール
    • ディスカッション
    • 人工知能
    • IoT
    • VoIP
    • ナレッジ
    • WhatsApp
    サードパーティアプリ Odooスタジオ Odooクラウドプラットホーム
  • インダストリー(業種別ソリューション)
    小売
    • 書店
    • アパレルショップ
    • 家具店
    • 食料品店
    • 金物店
    • 玩具店
    飲食・ホスピタリティ業界
    • バー・パブ
    • レストラン
    • ファストフード
    • ゲストハウス
    • 飲料販売代理店
    • ホテル
    不動産
    • 不動産会社
    • 建築事務所
    • 建設
    • 不動産管理
    • 造園
    • 住宅所有者組合
    コンサルティング
    • 会計事務所
    • Odooパートナー
    • マーケティングエージェンシー
    • 法律事務所
    • 人材派遣
    • 監査・認証
    製造
    • テキスタイル
    • 金属
    • 家具
    • 飲食
    • ブルワリー
    • コーポレートギフト
    ヘルス & フィットネス
    • スポーツクラブ
    • 眼鏡店
    • フィットネスセンター
    • ウェルネス専門家
    • 薬局
    • ヘアサロン
    業種
    • 便利屋
    • IT ハードウェア・サポート
    • 太陽エネルギーシステム
    • 靴メーカー
    • クリーニングサービス
    • 空調設備サービス
    その他
    • 非営利団体
    • 環境機関
    • ビルボードレンタル
    • 写真
    • 自転車リース
    • ソフトウェアリセラー
    すべての業種を見る
  • コミュニティ
    学ぶ
    • チュートリアル
    • ドキュメンテーション
    • 認定
    • トレーニング
    • ブログ
    • ポッドキャスト
    教育サポート
    • 教育プログラム
    • Scale Up! ビジネスゲーム
    • Odooオフィス訪問
    ソフトを入手
    • ダウンロード
    • エディションを比較
    • リリース
    コラボレーション
    • Github
    • フォーラム
    • イベント
    • 翻訳
    • パートナーになる
    • パートナー様向けサービス
    • 会計事務所を登録
    サービス利用
    • パートナー一覧
    • 会計事務所一覧
    • 今すぐ相談する
    • 導入支援サービス
    • お客様一覧
    • サポート
    • アップグレード
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    製品デモを利用する
  • 料金
  • ヘルプ
コミュニティで交流するには登録する必要があります。
全てのポスト 人々 バッジ
タグ (全て表示)
odoo accounting v14 pos v15
このフォーラムについて
コミュニティで交流するには登録する必要があります。
全てのポスト 人々 バッジ
タグ (全て表示)
odoo accounting v14 pos v15
このフォーラムについて
ヘルプ

How to download the Pivot table Excel using python code?

購読

この投稿に活動があった際に通知を受け取ります

この質問にフラグが付けられました
3 返信
5886 ビュー
アバター
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
アバター
破棄
アバター
Mohammed.Samy
最善の回答

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
アバター
破棄
アバター
Yeison X
最善の回答

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

0
アバター
破棄
Tintuk Tomin
著作者

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

アバター
Jothimani Rajagopal
最善の回答

Hi Tintuk Tomin,

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

0
アバター
破棄
ディスカッションを楽しんでいますか?読むだけでなく、参加しましょう!

今すぐアカウントを作成して、限定機能を利用したり、素晴らしいコミュニティと交流しましょう!

登録
コミュニティ
  • チュートリアル
  • ドキュメンテーション
  • フォーラム
オープンソース
  • ダウンロード
  • Github
  • Runbot
  • 翻訳
サービス
  • Odoo.shホスティング
  • サポート
  • アップグレード
  • カスタム開発
  • 教育
  • 会計事務所一覧
  • パートナー一覧
  • パートナーになる
企業情報
  • 会社概要
  • ブランドアセット
  • お問い合わせ
  • 採用情報
  • イベント
  • ポッドキャスト
  • ブログ
  • お客様一覧
  • リーガル情報 • プライバシーポリシー
  • セキュリティ
الْعَرَبيّة 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(オドゥー)は、CRM、eコマース、会計、在庫管理、POS、プロジェクト管理など、企業のさまざまな業務を一つのシステムで管理できる、ベルギー発のオープンソースのERPソフトウェアです。

高機能で使いやすく、完全に統合されたERPとして、ユニークな価値を提供しています。

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