I have encountered a strange behavior in the web-client (SAO) while working on a custom module for loading additional subdivisions for a specific country. I will try my best to explain the behavior as follows hoping someone could tell me if this is a bug or an expected behavior.
1- I have created a list of close to 2000+ subdivisions for Costa Rica that are organized according to the country’s normal geo division that goes from provinces, cantons, districts, to finally neighborhoods. All of them are loaded into the country.subdivision table.
2- So upon creating a new party and I try to select Costa Rica from the country list, I notice that the subdivision list will take some time to finish populating all the 2000+ subdivisions. This is expected because the list is long. So in order to reduce the loading time, I decided to create an entry in the “address subdivision types” for that country (CR) to filter only “province” type and limit the subdivisions to be loaded.
3- The expected behavior would be that after limiting the type to only “province”, the subdivision list will populate faster, as there is only 7 provinces. This behavior is carry out correctly for the first time I create the party. But if I load an existing party, move to change the country to any other country, and without saving select back Costa Rica again, the subdivision list will load all the 2000+ entries as if the address subdivision type filter wasn’t set.
4- I traced the web client XHR communication with the server using Firefox’s Developer Tools kit and found out, when the strange behavior happens, it makes the following sequence of calls:
- model.country.subdivision.search_read([“country”, “=”, 53], 0, null, null)
As you can see, the call (line 2) to read the subdivisions is called with the domain clause (“type”, “in”, [“province”]) missing, hence it fetches all the subdivisions. I believe this is because (line 3) the on_change_with_subdivision_types is called afterwards when it should come before line 2. Line 3 is needed to provide the missing domain clause from above. So, the question is if there is a way to ensure that line 3 is called before line 2 at all times?