Can I send CSV data to OpenERP / Odoo via API?

I can import comma-delimited data (CSV) through the administration pages into most models. This process processes external identifiers so that data can be added or modified accordingly in subsequent imported CSV files. This is a manic action.

Through the API, you can create and modify the same records as external identifiers. However, this requires a lot of logic that would otherwise be handled by the CSV importer, which must be manually encoded, in an external application that uses the API to enter data. Clicking data through the API can be automated.

Is it possible to use an API (so there is no need to make any changes to the Odoo code) to pop CSV data (so that the logic for inserting / updating / relations / external identifiers, etc. is processed by Odoo)? This will be a kind of hybrid approach, and I try to avoid the need to create import modules in Odoo.

Edit: The "external ID" is often referred to as the "XML ID". I think this is terminology that is stuck from earlier versions of OpenERP, and not with anything specific related to XML.

Edit

This page describes the load () function, which 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 cannot figure out how to translate the summary on this page into an operation via the API, if it is really possible. I assume that I will need an interface (entry point), model, method ( load() , probably) and some additional parameters, but the details do not exceed me.

+6
source share
2 answers

The answer is yes.

The load() method can be used against any model to load data. This method accepts data in the same structure as the CSV file.

  • The first parameter is an array of field names, such as column headers when importing CSV.
  • The second parameter is an array of records. Each record is an array of values ​​corresponding to each field.

The API will return a list of errors in which OpenERP handles them. However, many errors lead to database exceptions in OpenERP, and therefore should be taken as an API failure. This is largely due to the fact that the OpenERP API is not designed as a common API, but as part of the graphical interface, so the data sent to the API is very tied to the current state of the application through this graphical interface. In other words, invalid data will rarely be encountered in the API using the OpenERP GUI.

In my PHP OpenERP API library, I wrapped the bootloader functionality by detecting errors and exceptions,

https://github.com/academe/openerpapi/blob/master/src/App/Loader.php

Hope this will be helpful to others as well.

+4
source

I think the answer is no.

However, this method explained to me:

  • Create a module with few files except CSV for import.
  • Install the module.
  • When you need to import a new CSV file, transfer it to a module (FTP or similar).
  • After the transfer, run the update () method for the module. This can be done through the API.

The update method scans and downloads all CSV files installed in the module. It is necessary to ensure that at any time only one download / update transaction is completed.

I will talk about additional details here when I succeeded, or will gladly accept an alternative answer if there is a better way to handle this.

0
source

Source: https://habr.com/ru/post/972699/


All Articles