Naïve question, fields depended on external source of data

I have the fields:

item_serial_number = fields.Char(....,help = 'The serial number of an item')
model = fields.Char('Model',...
manufacturer = fields.Char('Original manufacturer'
year_of_production = fields.Date('Year'

based on item_serial_number I could request from REST API of the manufacturer’s web-site to obtain data to fill the fields for the user’s convenience: model, manufacturer, year_of_production. What function do you recommend to apply?
I feel that the use

Model.on_change_with_<field_name>

would be correct but how to make ONE API request for all three dependent fields?

Constantine.

I am thinking of using

Model.on_change_

to change all at once inside this def on_change_item_serial_number()
and fill out other fields. Is that correct? And if you could point me to the example if any?

Constantine.

Which API are you talking?

It is not clear what is your purpose. Who is obtaining the data? Where are they filled?

I understand, that I was not clear enough. I have edited the original question.
So, I want Tryton fills these fields automatically, based on serial number from user and data pulled from manufacturer’s server trough API.
I want to make user’s life easier and fill the form: so it would be easier just to enter the serial number and other data will be filled automatically.

  1. User enters ‘item_serial_number’
  2. Press Store
  3. Tryton pulls data trough API based on data from ‘items_serial_number’
  4. Tryton fills rest of the fileds with this data.

Constantine.

Yes it is the way.
So your method should look like:

@fields.depends('item_serial_number')
def on_change_item_serial_number(self):
   data = request.post(…)
   self.model = data['model']
   self.manufacturer = data['manufacturer']
   self.year_or_production = dt.datetime.strptime(data['date'], '%Y-%m-%d').date()
1 Like

Wonderful!
Thank you!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.