Unexpected behavior differences between normal model forms vs wizard forms

I have a strange situation with the party.address form in which it loads different subdivisions lists depending on where the form was loaded. In the normal circumstances, when I open a party from the party list, the party form loads correctly. All the values in the party.address model are loaded including the party.address.subdivision_types field. This field is of type function, and is needed to filter the choices of subdivisions for a given country so only certain category for example provinces or states are displayed.
However when this same form is loaded as a result of a wizard action, the party.address.subdivision_types value appears not loaded. I looked at the XHR messages between SAO and the server and found that the returned JSON object from the wizard’s execute call has this field’s missing in the defaults values dictionary. Hence, SAO, on its next request to read the subdivisions list, passes a domain without subdivision_types filter and the server returns all possible subdivisions for the particular country, which is not correct.
I don’t know yet where the source of the problem is, but I suspect it may be related to the fact that functions fields are lazy loading by default and it may contribute to the server not returning it unless the clients requests it.

Has anyone seen this problem before?

In general using an existing model in a wizard is usually a bad idea.
subdivision_types is a Function field that depends on country. So it is filled only once a country is selected.

I thought code reuse is one of Tryton’s strengths, specially in forms (CRUD operations) to reduce duplicated code. So in this particular case, is it an exception and the outcome is expected?

I understand that subdivision_types field relies on the function on_change_with_subdivision_types to get its value and it is declared to depend on country. However I am curious as to why the server does not return the subdivision_types value as part of the JSON if it is already returning the rest of the values including country; or the client (SAO) does not make a XHR call to fetch the subdivision_types if it see that it is missing?

No record is read on a wizard. A wizard is a empty shell form.

I looked into my code and figured what I did wrong. For using the party form in a wizard I had previously created a dict with all the values for the form, including those fields of type function. But with the addition of the field subdivision_types on version 5.6, I forgot to add this value in the dict, hence the mentioned problem.
So to summarize what I have learned from this is that with normal forms to be used in a wizard, one must to make sure to pass all the values from the fields including the those of type function in the defaults for it to properly work.

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