跳至內容
選單
此問題已被標幟
1 回覆
10477 瀏覽次數

I created an automated action in Odoo that is triggered when a purchase order is updated from `state = draft` to `state = sent`. This automated action simply calls a server action that runs the following code:


    record.button_confirm()


The idea is I am trying to confirm the purchase order automatically after the RFQ is sent to the vendor.


After sending the RFQ the PO is confirmed as expected. However, the vendor on the PO also receives a notification from the system related to the picking that was created. It will say something like:


"This transfer has been created from: PO00007"


If I disable my automated action and instead confirm the PO manually by clicking the "Confirm Order" button on the PO form, the order is approved, a picking is created, and this notification is not sent.


I would like my automatic approval to mimic the manual approval. Meaning, I do not want this notification to be sent.


After searching the source code, I was able to accomplish what I wanted by passing in a context key like this in the server action:


    record.with_context(message_create_from_mail_mail=True).button_confirm()


I came across this solution here in the source code:


https://github.com/odoo/odoo/blob/df60828488a702acb64757f518b4be12b7a95a04/addons/mail/models/mail_message.py#L729


However, I don't understand why this is necessary or if it's even the correct way to solve this problem. I honestly don't even know what it means. I just know it works. I don't see the manual "button_confirm" method passing in this context key anywhere.


Can anyone offer any guidance here as to why this notification email is sent when I simply run `button_confirm()` from a server action rather than triggering it manually with a button from the UI? Also, is my solution correct or does it have some sort of side effect I am not aware of?

頭像
捨棄
最佳答案

As per my understand you want to confirm the order in automated action right?
Here is a solution for trigger button_confirm() programmatically without override full method:

For purchase order: purchase_record.button_confirm()
For sale order: sale_record.action_confirm()

頭像
捨棄

Hi Ghoda, could you tell us how to create automated action to create invoice and receive goods when a purchase order is confirmed !

相關帖文 回覆 瀏覽次數 活動
2
10月 20
6991
2
5月 25
1195
1
1月 25
643
3
12月 24
4512
2
8月 24
730