Record creation helper

(Nicolas Évrard) #1


For some referential data there is sometimes a source that can be used as an authoritative origin (it could be a website, another database or even a file stored somewhere).
Tryton should have a mechanism to allow users to use it when creating a new record.


Our proposition is to use something that would look like the auto-completion drop-down that people can find currently below the Many2One fields.

This drop-down could be completed with results from the a query to the different sources for this specific model. Something like:


(I suck at gimp :smile:)

Once selecting a party from another source, the default_get is called with the external_source context to fill the new form.

Of course we want this process to be also available when the user click directly on the “Create” button for a model that supports this operation. But in this case the process should be a bit different as selecting a Tryton record would go to this record while selecting a record from another source would open the form with the data from the source.

This process could be used to create on request some data that we currently create from XML files (countries and currencies).


The implementation would rely on the following mixin class:


  • get_external_sources(name: str) → list
    Query the external data source and return a list of dictionaries with the keys source, id and name.
  • extend Model.default_get to use contextual key external_source.

The modules providing new data sources will use the Tryton inheritance to implement both method for their own data source. How they do it is left to the implementer.

The inheritance of the mixin class will be transmitted to the client so that he knows which process should be launched when clicking on the “New” button.

Further developments

The existence of a data source for some records could be used to trigger an update of the actual data. This will at least require to store the source and id. We can expect people to always agree with the authoritative source and thus displaying the changes is probably not necessary.

Crowd-funding campaign
(Sergi Almacellas Abellana) #2

I’m wondering if instead of creating the record that it won’t be better to return only the defaults values for the record, so the user can customize and complete the record if desired. So the method will be:

create_record(source: str, id: str) → dict
Create the record identified by id from source , returns a dictionary with the default values for the record.

This will simplify the following part:

By using the standard form for creating the record.

(Cédric Krier) #3

I totally agree because the data from the external source may not be complete nor valid to make the creation.

(Nicolas Évrard) #4

Shouldn’it be named differently? There is no record creation, what about retrieve_defaults ?

(Cédric Krier) #5

For me, the default_get can be reuse with a special context keyword which provide the external source id.

(Dominique Chabord) #6

Can the external source be another Tryton server ?

(Cédric Krier) #7

It could be anything that can be reach with Python code.
So it will be possible to create an entry point on a Tryton server that will be used another Tryton server.

(Thierry Bruyere) #8

Will it be possible to have a request for additional information to the user before the call to the service?

For example for the creation of a company via the VIES register, we will have to ask for the VAT number for the search, how can the user give this information?

(Cédric Krier) #9

It is the data entered in the search that will be used. Of course it works only if it is the party is searched by VAT number.

But of course when the user click on a “create” button without any searched data, it will be redirected first to a search input:

(Cédric Krier) #10

Another use case would be to replace the GNU Health Federation Resource Locator plugin in a more integrated and flexible way.