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.
Proposal
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 )
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).
Implementation
The implementation would rely on the following mixin class:
ExternalDataSourceMixin
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.
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.
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.
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.
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?