I can import Comma Separated Values (CSV) data through the admin pages, into most models. This process handles the external IDs so that the data can be added to or amended as appropriate in later CSV imports. This is a manial action.
Through the API, the same records can be created and amended, and external IDs can be set. This, however, requires a lot of the logic that would otherwise be handled by the CSV importer to be coded by hand, in the external application that uses the API to push in data. Pushing data through the API can be automated.
Is there a way the API can be used (so no changes need to be made to code within Odoo) to push CSV data (so the logic for insert/update/relationships/external IDs/ etc. is handled by Odoo)? This would be a kind of hybrid approach, and I am trying to avoid the need to create import modules within Odoo.
Edit: the "external ID" is often called the "XML ID". I think it is a terminology that has stuck from earlier versions of OpenERP, rather than having anything specific to do with XML.
This page describes a load() function that pushes CSV-like data through a pipeline to load it into the system:
http://openerp-server.readthedocs.org/en/latest/06_misc_import.html
I can't see how to translate the summary on that page into an operation through the API, if indeed that is possible. I'm guessing I will need the interface (entry point), model, method (load()
, probably), and some additional parameters, but the details are beyond me.
CSV stands for comma separated values. CSV file format consists of one or more records, separated by newlines. Each record consists of one or more fields, separated by commas. Will my API persist data? Yes, your API has GET, PUT, POST, PATCH, and DELETE endpoints for reading + writing to your dataset.
We can add new data in this exported file. Now we can import this data by clicking the Import button. But in Odoo 14, to import data go to Favorites and then select Import records. Then click on the Load File button and select the file we need to import.
Clicking on the Import Records from Favorites, you will be navigated to upload the file to import. The two formats will be Odoo automatically uploaded. Now, as seen in the above screenshot, you can click on the UPLOAD button and import the file you require.
Sales>Products Subsequent to choosing the item go to the Action button. A drop-down list will be seen after clicking on the "Action" button, and there we can see the "Export" option. Choose or add the mandatory fields then click the "Export" button.
The answer is kind of "yes".
The load()
method can be used against any model to load data. This method takes data in the same structure as a CSV file would provide.
The API will return a list of errors where they are catered for by OpenERP. Many errors, however, just result in database exceptions on OpenERP and so need to be picked up as an API failure. This is largely because the OpenERP API is not designed as a generic API, but as a part of the GUI, and so the data sent to the API is very much bound to the current state of the application through that GUI. In other words, invalid data will seldom find its way to the API using the OpenERP GUI.
I have wrapped the loader functionality, catching errors and exceptions, in my PHP OpenERP API library here:
https://github.com/academe/openerpapi/blob/master/src/App/Loader.php
Hopefully that will be useful to others too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With