Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
11164 Widoki

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?

Awatar
Odrzuć
Najlepsza odpowiedź

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()

Awatar
Odrzuć

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

Powiązane posty Odpowiedzi Widoki Czynność
2
paź 20
7590
2
maj 25
2103
1
sty 25
1321
3
gru 24
6116
2
sie 24
1431