コンテンツへスキップ
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 is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • 会計
  • 在庫
  • PoS
  • プロジェクト
  • MRP
All apps
コミュニティで交流するには登録する必要があります。
全てのポスト 人々 バッジ
タグ (全て表示)
odoo accounting v14 pos v15
このフォーラムについて
コミュニティで交流するには登録する必要があります。
全てのポスト 人々 バッジ
タグ (全て表示)
odoo accounting v14 pos v15
このフォーラムについて
ヘルプ

Binary field as attachment in mail

購読

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

この質問にフラグが付けられました
mailinvoiceattachmentbinary
5 返信
17881 ビュー
アバター
Hugo M.

Hello,

I'm developing a module to extend Invoice (Odoo 11). I have added a binary field into the Invoice model, and I want to be able to send this binary via mail.

Sending an e-mail directly and attaching a binary is simple, but I want to open the composer wizard with the binary as an attachment. Currently, the "Send by e-mail" button opens the composer with Odoo's default PDF report; I want to add another file in that view.

This is my current code to try to attach the files. This piece of code itself runs and doesn't generate any errors, but the composer wizard just ignores the added info.

@api.multi
def action_invoice_sent(self):
self.ensure_one()

result = super(AccountInvoice,self).action_invoice_sent()

pdf_attachment_id = self.env['ir.attachment'].create({
'name': ("%s" %self.pdf),
'datas': self.pdfname,
'datas_fname': self.pdf,
'res_model': 'mail.compose.message',
'res_id': 0,
'type': 'binary'
})

result['context'].update({
'attachment_ids': [(6,0,[pdf_attachment_id.id])]
})

return result

Thanks a lot!
1
アバター
破棄
アバター
Hugo M.
著作者 最善の回答

Thanks but that's not my question. I don't want to attach a PDF report, the default invoice's e-mail template already does that. I want to add *another* file in the e-mail

I already solved it by extending the Composer wizard to retrieve the added files in context, but thanks anyway.

0
アバター
破棄
アバター
Megha Patel
最善の回答

Hugo M.

Firstly you have to check that the attachment you are sending is in pdf format or not, if its not then convert it using get_pdf method.

here is the example of attached report,

@api.multi
def action_rfq_send(self):
    self.ensure_one()
    ir_model_data = self.env['ir.model.data']
    try:
        if self.env.context.get('send_rfq', False):
            temp_id = self.env.ref('purchase.email_template_edi_purchase')
        else:
            temp_id = self.env.ref(
                               'purchase.email_template_edi_purchase_done')
    except ValueError:
        temp_id = False
    try:
        compose_form_id = ir_model_data.get_object_reference('mail',
                         'email_compose_message_wizard_form')[1]
    except ValueError:
        compose_form_id = False

    attach_obj = self.env['ir.attachment']

    pdf_rfq_quote = self.env['report'].sudo().get_pdf([self.id],
                                             'report name')
    result_rfq_quote = base64.b64encode(pdf_rfq_quote)

    attachment_ids = []
    if result:
        attach_data = {
            'name': 'name.pdf',
            'datas': result_rfq_quote,
            'datas_fname': 'name.pdf',
            'res_model': 'ir.ui.view',
            }
        attach_id = attach_obj.create(attach_data)
        attachment_ids.append(attach_id.id)
    if attachment_ids:
        temp_id.write({'attachment_ids': [(6, 0, attachment_ids)]})

    ctx = dict(self.env.context or {})
        ctx.update({
            'default_model': 'purchase.order',
            'default_res_id': self.ids[0],
            'default_use_template': bool(temp_id.id),
            'default_template_id': temp_id.id,
            'default_composition_mode': 'comment',
        })
        return {
            'name': _('Compose Email'),
            'type': 'ir.actions.act_window',
            'view_type': 'form',
            'view_mode': 'form',
            'res_model': 'mail.compose.message',
            'views': [(compose_form_id, 'form')],
            'view_id': compose_form_id,
            'target': 'new',
            'context': ctx,
        }
       

Thank You

1
アバター
破棄
アバター
Mohamed Amine Kaabi
最善の回答

it works with pdf file ?


0
アバター
破棄
アバター
Gabriel Hernandez
最善の回答
Thanks but that's not my question. I don't want to attach a PDF report, the default invoice's e-mail template already does that. I want to add *another* file in the e-mail
I already solved it by extending the Composer wizard to retrieve the added files in context, but thanks anyway.


I want to do the same, how to solve this?

Thank you.
0
アバター
破棄
アバター
Carlos Alberto García Brizuela
最善の回答

Hello, this is my implementation using odoo email wizard:

def send_mail(self):
self.ensure_one()
template = self.env.ref('my_module.email_template_payroll', False)
compose_form = self.env.ref('mail.email_compose_message_wizard_form', False)

# attach xml from binary field
if self.xml_data:
xml_name = '%s.xml' % self.name
attachment_ids = []
encoded_data = base64.b64encode(self.xml_data)
decoded_data = base64.b64decode(encoded_data)

if decoded_data:
attach_data = {
'name': xml_name,
'res_name': xml_name,
'datas': decoded_data,
'res_model': 'hr.payslip',
'res_id': self.id,
}
attach_id = self.env['ir.attachment'].create(attach_data)
attachment_ids.append(attach_id.id)

if attachment_ids:
template.write({'attachment_ids': [(6, 0, attachment_ids)]})

ctx = dict()
ctx.update({
'default_model': 'hr.payslip',
'default_res_id': self.id,
'default_use_template': bool(template),
'default_template_id': template.id,
'default_composition_mode': 'comment',
})


return {
'name': _('Compose Email'),
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'mail.compose.message',
'views': [(compose_form.id, 'form')],
'view_id': compose_form.id,
'target': 'new',
'context': ctx,
}

Be careful with the indentation of the code, it got lost when paste text.

Hope it helps


0
アバター
破棄
Mohamed Amine Kaabi

xml_data a existing field ?

Carlos Alberto García Brizuela

"xml_data" field is a binary stored field in the same model of your method "send_mail". not remember if its a native odoo field or a custom one.

Mohamed Amine Kaabi

it works with pdf file ?

Carlos Alberto García Brizuela

I think should work too, pdf files are stored by odoo in binary fields as well.

Mohamed Amine Kaabi

i have this error

File "/home/ibs/Bureau/workspace/odoo13/odoo/api.py", line 390, in call_kw
result = _call_kw_multi(method, model, args, kwargs)
File "/home/ibs/Bureau/workspace/odoo13/odoo/api.py", line 377, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "/home/ibs/Bureau/workspace/odoo13/test_erp/spc_intranet_sfr/models/hs_commande.py", line 278, in action_commande_send
encoded_data = base64.b64encode(self.attachment_access_adsl)
File "/usr/lib/python3.8/base64.py", line 58, in b64encode
encoded = binascii.b2a_base64(s, newline=False)
TypeError: a bytes-like object is required, not 'ir.attachment'

Mohamed Amine Kaabi

This is the function
def action_commande_send(self):
self.ensure_one()
template = self.env.ref('spc_intranet_sfr.email_template_hs_commande', False)
compose_form = self.env.ref('mail.email_compose_message_wizard_form', False)

if self.attachment_access_adsl:
pdf_name = '%s.pdf' % self.name
attachment_ids = []
encoded_data = base64.b64encode(self.attachment_access_adsl)
decoded_data = base64.b64decode(encoded_data)

if decoded_data:
attach_data = {
'name': pdf_name,
'res_name': pdf_name,
'datas': decoded_data,
'res_model': 'hs.commande',
'res_id': self.id,
}
attach_id = self.env['ir.attachment'].create(attach_data)
attachment_ids.append(attach_id.id)

if attachment_ids:
template.write({'attachment_ids': [(6, 0, attachment_ids)]})

ctx = dict()
ctx.update({
'default_model': 'hs.commande',
'default_res_id': self.id,
'default_use_template': bool(template),
'default_template_id': template.id,
'default_composition_mode': 'comment',
})
return {
'name': _('Compose Email'),
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'mail.compose.message',
'views': [(compose_form.id, 'form')],
'view_id': compose_form.id,
'target': 'new',
'context': ctx,
}

Carlos Alberto García Brizuela

The error is in this line:
encoded_data = base64.b64encode(self.attachment_access_adsl)

I think you are passing the full model or class object, but you need to pass the binary field instead, for example:

encoded_data = base64.b64encode(self.attachment_access_adsl.bin_field_name)

Mohamed Amine Kaabi

bin_field_name ?!!!!!!

Carlos Alberto García Brizuela

base64.b64encode(*)

This method expects binary data as a parameter, you are passing an instance object of the class "ir.attachment".

what you need to pass is the binary field of the class "ir.attachment". In odoo 15 the binary field name is "datas"

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

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

登録
関連投稿 返信 ビュー 活動
Send a mail with fields.binary attached
mail attachment send binary
アバター
アバター
4
6月 17
11121
send email with multiple attachment
mail attachment
アバター
1
8月 24
2696
Send a mail with automatic attachment ofa binary field from a model
wizard mail attachment template binary
アバター
1
3月 15
7716
Attachments in openerp 7.0
invoice attachment
アバター
アバター
アバター
3
3月 15
9783
Send invoice by email: attachments creation
invoice attachment
アバター
アバター
1
3月 15
7111
コミュニティ
  • チュートリアル
  • ドキュメンテーション
  • フォーラム
オープンソース
  • ダウンロード
  • 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 ภาษาไทย 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