Notify Odoo with "Odoo API" modification


This modification adds features for sending woocommerce orders and customers via odoo API.




Index:



Installation

1) Install it as a wordpress plugin.

2) Generate odoo API key.
In the odoo admin panel click on the administrator name at the top right corner of the page and select "Preferences". (screenshot)
In the "Account Security" tab click on "NEW API KEY". (screenshot)
Specify any name for your key like "api_key_for_woocommerce" and click the "Generate Key" button. (screenshot)
Save the generated key somewhere. Odoo will not display it for you again.

NOTE: the key should be generated for the administrator. To allow administrator access to the odoo system.
  If you generate it for some other odoo user then this plugin will not be able to create odoo orders.

3) Specify access details.
3.1 Connect to your website via FTP.
(if you have no FTP access you can update the file with wordpress Plugin File Editor:
 Wordress dashboard -> Plugins -> Plugin File Editor (screenshot)
 Just don't forget to disable plugin before editing.)

3.2 Specify odoo URL, user, API key and the odoo database name:
protected $_odoo_url = 'http://127.0.0.1:8069';

protected $_odoo_user = 'admin';
protected $_odoo_api_key = '032267a7bc585234027f833bed701eb230ffec05';
protected $_odoo_db = 'odoo16';

in the file:
wp-content/plugins/notify-odoo/Model/OdooApi.php

NOTE: for a real website use secure protocol "https". For localhost you can use "http" ex.: http://127.0.0.1:8069

4) Set up server cron to run wordpress "wp-cron.php" script every 5 minutes.
4.1 Go to your hosting cpanel -> Cron Job Management (screenshot)
And set this linux cron command (if your website is hosted on a linux server):
*/5 * * * * wget -q -O - 'https://yourwebsite.com/wp-cron.php?doing_wp_cron' >/dev/null 2>&1
(screenshot)

Replace "yourwebsite.com" with your website domain.

If you cannot set up the server cron ask your hosting support to do it.
Also you can use some online cron service instead of the server cron.

4.2 Disable wordpress web cron by setting:
define('DISABLE_WP_CRON', true);

in the file:
wp-config.php

(Wordpress web cron is not reliable. It runs only when someone visits your website. It is why we disable it and enable the server cron instead of it.)




Back to the index


An example of how to use it

1) Go to WordPress dashboard -> Notify Odoo -> Odoo API
And click the "Add last order to queue" button. (screenshot)
The order should appear in the queue. (screenshot)
Or it will appear in the Queue history as last processed. (screenshot)

NOTE: if there are no woocommerce orders. You should create one.
Then if the "Notify About New Order" checkbox is checked (screenshot) the new created order should appear in the queue.

2) Wait for 1-5 minutes. Then reload the page. If cron job is set up, the order should be processed and appear as last processed. (screenshot)
Processed means that it was summited to the odoo server.
The last processed record contains the result of the transfer. (screenshot)
The succesful result means that the new order was successfully transfered to the odoo server. So you should go to the odoo admin panel and try to find the new order there. (screenshot)

A failed transfer means that there was a problem during submitting the order. You should check the error log file at the botton of the page for more details. (screenshot)
Also you can resubmit the order with debug info to get more details of what was the problem during submitting the last order. (screenshot 1, screenshot 2)




Back to the index


Debugging

To debug the server cron job:
Go to WordPress dashboard -> Notify Odoo -> Odoo API
And click the "Add last order to queue" button. (screenshot)

Wait for five minutes. The order should appear in the last processed. (screenshot)

If the order does not appear in the last processed in five minutes.
Try to emulate cron job by accessing the wp-cron.php file with your browser:
http://yourwebsite.com/wp-cron.php

This page does not display anything.
But the browser can display the loading state. So you should not interrupt the page loading process and wait.
Then check if the order appears as last processed.

NOTE 1: Don't access the wp-cron.php script more frequently than 1 minute.
The action function of this plugin is scheduled to be executed in one minute interval.
So if you access it more often it will not start.

NOTE 2: Other way to check if server cron is set up is to check when the cron scheduled action was last executed. (screenshot)
If the server cron is set up, it should execute the scheduled action every 5 minutes.

To debug connection:
Go to WordPress dashboard -> Notify Odoo -> Odoo API
And click the "Send last order with debug info" or "Send last customer with debug info" button. (screenshot)

In the processing should start in a new browser tab and then display the result.

Check the output. If it was able to get the odoo version, it means that the odoo URL is correct. (screenshot )

So you should check the odoo user and the API key in the file:
wp-content/plugins/notify-odoo/Model/OdooApi.php
(screenshot )

Wrong database name will produce long error message. With a fatal error at the end.
Example:
FATAL: database "_odoo17" does not exist
(screenshot )




Back to the index


Trouble shooting:

Error: Object sale.order doesn't exist
Solution:
Activate the "Odoo Sales" (sale_management) module in Odoo admin panel -> Apps. (screenshot)




Back to the index