コンテンツへスキップ
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
このフォーラムについて
ヘルプ

odoo 14 call action invoice sent from another model

購読

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

この質問にフラグが付けられました
invoiceactionsodoomodels.Model
3 返信
8959 ビュー
アバター
Joao Almeida

Right now I'm trying to call  programmatically, from  another  model,  the action 'action_invoice_sent'  that exists in the invoice details  page  as  a  button  called  'Send  &  Print'  (I'm not able to post images).

I call the action as a method: 'invoice_object.action_invoice_sent()' but nothing happens. Does anyone knows how to send invoices programmatically?

Thanks


1
アバター
破棄
アバター
Mohamed Lamine Lalmi
最善の回答

Hello Joao,

The function action_invoice_sent  return  an  action  in  dictionary  format.  You have to return the result of this function to perform the action.

def  my_action(self):    
    action = invoice_object.action_invoice_sent()
    return  action

Otherwise, if you want to perform sending the Invoice directly (without opening the wizard), so you will have to create account.invoice.send object with the following context values:



def action_send_invoice_directly(self):
    # Search for your invoice_object
    invoice_object = ...

template = self.env.ref('account.email_template_edi_invoice', raise_if_not_found=False)
lang = False

if template:
lang = template._render_lang(invoice_object.ids)[invoice_object.id]

if not lang:
lang = get_lang(self.env).code

ctx = dict(
mark_invoice_as_sent=True,
active_ids=invoice_object.ids, # Use ids and not id (it has to be a list)
custom_layout="mail.mail_notification_paynow",
model_description=invoice_object.with_context(lang=lang).type_name,
force_email=True,
default_res_model='account.move',
default_use_template=bool(template),
)
values = {
'model': 'account.move',
'res_id': invoice_object.id,
'template_id': template and template.id or False,
'composition_mode': 'comment',
}

wizard = self.env['account.invoice.send'].with_context(ctx).create(values)
    wizard._compute_composition_mode()
wizard.onchange_template_id()
wizard.onchange_is_email()

    # If you want to send without printing the invoice use this function

    wizard._send_email()

# If you want to send and print use this function
    # wizard.send_and_print_action()

Hope my answer helps you.

4
アバター
破棄
Joao Almeida
著作者

hi Mahamed,
in this case I want it to run without returning it, since it's an automated processing of invoices. Is this possible?

Mohamed Lamine Lalmi

Hey again,
Yes, It is possible but in a different way. In this cas you can't use the function action_invoice_sent because this function will not send the invoice, it will open the Wizard "account.invoice.send" then this wizard has it own function the send the invoice (_send_email). I'll update my response according to your needs.

Joao Almeida
著作者

it makes sense. In that case, how can I send the invoice?

Mohamed Lamine Lalmi

Dear Joao,
I've updated my answer.
Good luck.

Joao Almeida
著作者

wow, that is so great! looked all over the internet to find something like that. Than you so much.

One doubt: what is the "self.ids" in this line?
lang = template._render_lang(self.ids)[self.id]

Joao Almeida
著作者

it's almost working. The invoice is marked as sent, but the email is not actually sent (it's not even on emails list that failed on odoo settings, so it's not an SMTP configuration problem)
I tried to look into the system's 'account.move.send' model and didn't find what could be the possible cause.

Joao Almeida
著作者

found the solution, 3 methods must be called before send:

wizard = self.env['account.invoice.send'].with_context(ctx).create(values)

wizard._compute_composition_mode()
wizard.onchange_template_id()
wizard.onchange_is_email()

# If you want to send without printing the invoice use this function
wizard._send_email()

Joao Almeida
著作者

now, the only thing that is not working is the invoice 'move_to_sent' is not set as true.

Mohamed Lamine Lalmi

Dear Joao,
for this line: lang = template._render_lang(self.ids)[self.id],
I did a mistake and i've updated the code.
_render_lang: Given some record ids, return the lang for each record based on lang field of template or through specific context-based key.
This line is added to ensure that the email will be sent in the correct language.

Mohamed Lamine Lalmi

Good catch Joao!

found the solution, 3 methods must be called before send:

wizard = self.env['account.invoice.send'].with_context(ctx).create(values)

wizard._compute_composition_mode()
wizard.onchange_template_id()
wizard.onchange_is_email()

Mohamed Lamine Lalmi

Dear Joao, could you please add a positif vote on my solution. :)

Joao Almeida
著作者

added a positive vote :)

also could you change your post to reflect the corrections we discussed here? Just to help someone in the future that stumbles upon this post.

Also, in this line 'model_description=self.with_context(lang=lang).type_name,' self is actually invoice_object? At least I had to use it

Also, I had to create a composer instance:
composer = http.request.env['mail.compose.message'].create({
'composition_mode': 'comment'
})

then use it in the values:
values = {
'model': 'account.move',
'is_email': True,
'res_id': invoice_object.id,
'template_id': template and template.id or False,
'composition_mode': 'comment',
'composer_id': composer.id,
'invoice_ids': invoice_object.ids,
}

Mohamed Lamine Lalmi

Thank you for the positive vote :)
Yes, you were right, it should be invoice_object.
Updates are made on my response.
Thank you for your feedback, it was like a teamwork.

Joao Almeida
著作者

Hi Mohamed

thank you so much for your help :) yes it felt like team work. With this, now anyone can implement the same

Gouranga Kala

Hi Mohammad,
The above code fits to my requirements, but the only problem is it is generating 2 emails.
1. from user to customer
2.from user to user itself (which is not required)
Can you please help me ?
I am using odoo 16 enterprise. Thanks in advance

アバター
Răzvan Anastasescu
最善の回答

I think that using the wizard (which will generate some data in temp tables) and composer (which is not used anyway) it's a little bit too complex (and actually slower)

I'd use something like this:

def action_send_invoice(self):
# one 'account.move' object
invoice = self.env['account.move'].search([], limit=1)

template = self.env.ref('account.email_template_edi_invoice')

if not(invoice and template):
return False

res = template.send_mail(invoice.id, force_send=True, notif_layout='mail.mail_notification_paynow')

# or:
res = invoice.with_context(force_send=True).message_post_with_template(template.id, email_layout_xmlid='mail.mail_notification_paynow')

if res:
invoice.is_move_sent = True

return res

Attachments and partner language will be automatically taken care of, but you have to manually set the invoice as sent if success

1
アバター
破棄
アバター
J. Blanco Caura
最善の回答

Excellent. I congratulate you, of someone out of shape trying to catch the thread of programming again

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

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

登録
関連投稿 返信 ビュー 活動
Odoo - Return record lists on form view
actions odoo
アバター
アバター
アバター
アバター
3
7月 24
6539
What are the value need to pass in field 'type' of account.invoice table in Odoo to get Customer_Invoice & Supplier_Invoice ?
invoice odoo
アバター
アバター
1
10月 18
4664
Error Converting Sale Orders to Invoice
invoice odoo
アバター
0
10月 15
4113
How to remove product description from invoice lines?
invoice odoo v18
アバター
アバター
アバター
2
8月 25
2920
Remove link from offer and invoice email 解決済
invoice emailtemplate odoo
アバター
アバター
アバター
2
11月 24
3686
コミュニティ
  • チュートリアル
  • ドキュメンテーション
  • フォーラム
オープンソース
  • ダウンロード
  • 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