Confirm purchase order from automated action in Odoo - odoo

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?

Related

Odoo 12 Enterprise Issue in Manufacturing. It is not possible to unreserve more products of "Product Name" than you have in stock

Impacted versions: odoo12
Steps to reproduce: Created a Manufacturing Order. Completed the Work order. Clicking Mark as Done. The error is coming.
Current behavior: Struggling with the error. I duplicated the Manufacturing order and processed it. It closed smoothly without any issue/error.
Expected behavior: Manufacturing order should move to done state as soon as Mark As done is clicked.
Video/Screenshot link (optional): https://ibb.co/Lp5PntS
Follow the below steps to fix the bug for odoo stock issue.
In order to implement it you need to follow below steps:
Debug mode
Technical/server actions
Create
Action name: e.g. fix unreserved qty
model: ir.actions.server
Action to do: “execute python code”
copy/paste the fix underneath the pre-existing code
“save”
“create contextual action”
Refresh page
Action/fix “fix unreserved qty”
Wait for it to load
“remove contextual action”
Action/delete
It happens because the reserved quantity in your inventory does not reflect the one on your pickings. It’s probably due to a small configuration change while some pickings where open.
An easy way to remove it is to create a server action that executes this code
https://gist.github.com/jaa-odoo/8eb0a7250e1cecb2e412563ae6346052
Solution Code.
It should repair all the inconsistencies in your data.
Fix Decimal for stock unreversed issue.
https://gist.github.com/jaa-odoo/a6315513bf7b2d8525a60c6f36c0f897
code

Send WhatsApp messages automatically with Automate-App

I want to send a WhatsApp message to a specific contact with the Automate-app. How can do I do this?
This is the link to the app:
https://play.google.com/store/apps/details?id=com.llamalab.automate
I know this is pretty late reply.
You can make use of below blocks and build
App start block and choose activity class as
com.whatsapp.ContactPicker
Use Interact blocks for searching, selecting and messaging
Extend with Variable for searching contact and for message text
I have been trying different ways but many of them fall short of full automation.
currently, I am using blocks to send a message to (unsaved) contact. This skips the contactPicker window.
the flow blocks:
[start flow] --> [view content] --> [interact]
that's it!
in view content, you will need to specify the content uri (change number and msg):
https://api.whatsapp.com/send?phone=+966xxxxxxxxx&text=msg
in interact block, specify the (proceed) when element appeared.
the (action) is click.
and (XPATH):
fn:reverse((.//[{("android.widget.ImageButton") = null ? "true()" : "fn:choose(#class,string(#class),name())={"android.widget.ImageButton";xpathEncode}"} and {("com.whatsapp:id/send") = null ? "true()" : "#android:id={"#" ++ ("com.whatsapp:id/send");xpathEncode}"}])[1]/ancestor-or-self::)
that's it.

Detecting user canceling SKReceiptRefreshRequest to sign in

When we need to refresh an iOS7 receipt, the appropriate way to do that is to use SKReceiptRefreshRequest. This brings up an Apple dialog for the user to sign in using their Apple ID. It also allows them to Cancel. How can we detect if the user presses Cancel? (Of course, in iOS6, this can be done using catching the cancel event for [[SKPaymentQueue defaultQueue] restoreCompletedTransactions]).
The SKReceiptRefreshRequest object has a delegate with two methods:
- (void)requestDidFinish:(SKRequest *)request;
- (void)request:(SKRequest *)request didFailWithError:(NSError *)error;
In my code the requestDidFinish delegate method is called if the user does or does not press cancel.
The reason this is important to me is that I want to cancel the restore process if the user presses Cancel. If there was simply no receipt present after the refresh request, this might be relatively easy. However, sometimes there is a receipt (with some purchases) present in the app before the SKReceiptRefreshRequest, and so it stays in the app if the user cancels from the sign-in dialog.
I have two ideas for how to do this:
1) Delete the receipt from the bundle prior to the refresh request. The apparent problem with this is that the app can't remove files from the bundle (e.g., see Delete file from bundle after install). I tried. Nope.
2) Check the bytes of the receipt before the refresh request and after; if they differ, then this should indicate the user didn't press Cancel. If they don't differ, I'm not sure that does indicate they pressed Cancel. If the receipt contains purchases, I think that the bytes will differ because a refreshed receipt should have different transaction id's (but the same "original" transaction id's). If the receipt contains no purchases, I'm not sure about that.
Update, 11/9/15; I've just noticed that the delegate response to the user pressing Cancel appears to have changed. Now, didFailWithError is called. The problem of detecting user cancellation remains, however. How can we distinguish between the user pressing Cancel and a genuine error? I've been testing on iOS8.4 and iOS9.2 (beta). I have now reported this lack of distinguishability as a bug to Apple (bug #23476210).
Update, 11/10/15; This issue does not appear with iOS 9.0.2! I just tried this now with all three systems, with the same app binary, in the same approximate interval of time (within 20 minutes for all three systems): (A) iOS9.2 (13C5050d): Issue does occur (didFailWithError is called and can't distinguish between a real error and user pressing cancel), (B) iOS9.0.2, issue does not occur (requestDidFinish is called), and (C) iOS8.4.1, issue does occur. With all three system versions, this is running on real hardware, not the simulator.
iOS 9.2.1, Xcode 7.2.1, ARC enabled
I understand you asked this 2 years ago, but I recently had my run in with this issue and found a solution, and wanted to share here so others can save some time.
1) You may elect to store the receipt into keychain and access a copy of it, this allows you to delete it or refresh it as you see fit.
2) Yeah you can definitely check if it changed, I think the simplest way to do that is to use:
[receipt isEqualToData:(NSData *)(copyReceiptObject)]
My suggestion is as follows:
The key is to expect the error you get from the method:
- (void)request:(SKRequest *)request didFailWithError:(NSError *)error;
that gets called when the user taps cancel after the log in dialogue comes up to sign in to iTunes Store. There are many custom was you could do the refresh request, so the results may vary, but here is the different error you get for my request:
When there is no connection to iTunes:
Error Domain=SSErrorDomain Code=110 "Cannot connect to iTunes Store"
UserInfo={NSLocalizedDescription=Cannot connect to iTunes Store,
NSUnderlyingError=0x13c76d680 {Error Domain=NSURLErrorDomain
Code=-1009 "Cannot connect to iTunes Store"
UserInfo={NSLocalizedDescription=Cannot connect to iTunes Store,
NSErrorFailingURLStringKey=
{ your product ids and corresponding URIs here }
, _kCFStreamErrorCodeKey=8, _kCFStreamErrorDomainKey=12,
NSLocalizedDescription=The Internet connection appears to be offline.}}}
When the user taps cancel:
Error Domain=SSErrorDomain Code=16 "Cannot connect to iTunes Store"
UserInfo={NSLocalizedDescription=Cannot connect to iTunes Store,
NSUnderlyingError=0x13c6ac7b0 {Error Domain=AKAuthenticationError
Code=-7003 "(null)"}}
The easiest I think is to check the error.code, if you want to get more complicated you may choose to parse the full error string to get more details about the error.
In my case, no connection error code is 110 and when the user cancels the log in the error code is 16. Handle the error.

RavenDB Push Notifications: Actual document not included?

I've successfully implemented push notifications with RavenDB (see code below). I was expecting the actual document to be included with the change notification. That way, all the UI clients can display the information. However, it seems that only the Id and Etag properties are available for the changed document.
What am I supposed to do if I want the client to be able to display information about the document? Does the client now need to make a DB call to get the document based on the ID? It seems inefficient to have to make a DB call to get the information. But, is that what is supposed to happen?
documentStore.Changes()
.ForDocumentsStartingWith("LogMessages")
.Subscribe(change =>
{
if (change.Type == DocumentChangeTypes.Put)
{
// Fire event so consumers can display document info
// Uh oh, are change.Id and change.Etag all we have here?
DatabaseItemAdded(null, new EventArgs<string>(change.Id));
}
});
Yes, you need to call the db to get the new document.
The reason for that is that it would be expensive to send the document (which may be very big) if all you need is just the notification on the change).

libPusher + updating an open NSMenu

I have an NSMenu that I want to update with items pushed to my app through pusherapp and received using the libPusher client library. But events seem not to be received in NSEventTrackingRunLoopMode.
Given the following snippet:
[channel bindToEventNamed:#"my_event" handleWithBlock:^(PTPusherEvent *event) {
NSLog(#"event received");
}];
And I wait for a push to occur while I maintain the menu open, I expect to receive the event immediately but I only receive it when I close the menu.
I also tried passing the main queue to bindToEventNamed:handleWithBlock:queue: (using dispatch_get_main_queue();), to no avail.
So I'm left wondering whether I'm doing something wrong or there's a bug in libPusher?
I'm the author of libPusher. The reason you are seeing this problem is because the underlying WebSocket library used by libPusher, SocketRocket only works in the default run loop mode.
The good news is that this has been fixed in the latest HEAD of SocketRocket. I have tested libPusher agains the latest SocketRocket and can confirm that it fixes this issue and I intend to roll these changes in to the next release.
Now, I've just checked the outstanding Github issue and realised that you were the original reporter of this bug, so you probably know all this already but I'm going to post this answer anyway for posterity.
libPusher issue
SocketRocket issue