Due to the length of the inspection process, it is common that not all the points are completed in 1 session.
The main issue arises when saving an inspection, that if no value has been defined at a point of type != Boolean, this point is removed from the inspection. So if the user wants to re-add them, the point is added at the end of the points, and it results in a different order than the one defined in the control, that is the one that should be followed, plus it’s not intuitive.
How we could ensure that even if some point has no value it’s not removed?
Update:
Deleting the condition of that method trytond/trytond/model/fields/dict.py · a4f79a9e9193f8e622d2235112fba9b34ae5ecb1 · Tryton / Tryton · GitLab, no points are removed when saving, but I tried to create another CustomDict class inheriting Dict class field, to override the method sql_format
, but I can’t redefine points field with new CustomDict. How can I achieve this?
That modification could have some side effect?
Anyways when you save the inspection, exit the view, and return to it, it’s reordered without following the order in the control as I said.
There is no order guarantee in control points (there is no sequence).
And as it is stored as a JSON object, there is not guarantee that the order will be preserved (like for any Dict field).
So there is no way to customize the order that the points are shown? Overriding some method maybe?
The client widget is not design to respect any order.
But if someone has a elegant solution, it could be a nice improvement.
I know that as it’s a dict and it doesn’t preserve an order, but because of the tests that I’ve been doing, it seems that it’s ordered alphabetically and case sensitive.
since Python dicts
keeps insertion order since version 3.7 why not introduce a sequence for each dict-field and save the order as a separate list entry in the JSON with a reserved name like __order__
. With this information we can re-build an ordered dict.
The order will not be preserved through JSON-RPC (and probably neither for XML-RPC).
Also JavaScript objects do not have the same behavior: Does JavaScript guarantee object property order? - Stack Overflow
The order of the fields should be packed into the same JSON structure.
Ordered items like
{
keyA: test,
keyB: 1234-5678-9012-3456,
keyC: 999,
}
can be packed to a JSON like this:
{
"keyC": 999,
"keyB": "1234-5678-9012-3456",
"__order__": ["keyA", "keyB", "keyC"],
"keyA": "test"
}
When unpacking the JSON, we could build the dict like
_dict = {}
for key in _json["__order__"]:
_dict[key] = _json[key]