Hi!
There is a report in our application.
Report’s columns are dynamically selected from the specified fields of the specified database tables.
Description of the dynamic fields (columns) in our model:
We would like column labels ‘Attr1’, ‘Attr2’, ‘Attr3’ to change into ‘Field1’, ‘Field5’, ‘Field10’ respectively
(both in query results tree view and in ods-report).
We managed to do this in ods-report, but failed in tree view.
We tried to change ‘string’ attributes of these columns in view_attribute() method, but this does not work.
Is it doable in Tryton?
In fact, users can generate many reports and see results in one tree view.
They choose the type of report in the context of the tree view.
Each report has its own set of columns and labels.
We would like to change the column labels (‘string’ attributes)
in the same tree view after choosing the required report.
The column attr1 is hidden if checkbox1 == True and it is shown if checkbox1 == False.
But the label of the column attr1 does not depend on the field label1 and it is always equal to {"__class__": "Eval", "v": "label1", "d": "Attr1"}.
What are we doing wrong?
P.S. We use “usual” Tryton client (not web client).
You can not have PYSON statement for the string. The string must always be static.
You can change the string value in view_attributes conditionally depending on the context.
This only works when you first call Tryton client.
After changing the field label1 in the context, the label of the column attr1 does not change.
It does not change even if we add the call of view_attributes() to our table_query() method.
No, you can not because the value of a field does not exist in the absolute. It only exists for a record.
So as I said with my example you can change the string of a label but only for another static value.
This makes sense in our case. We implemented a report designer in our application. Users can create their own reports with the specified fields (columns) from the specified database tables.
So we need to change the column labels dynamically.
We managed to do this in ods-reports, but failed in tree view.
We just want to change column labels in tree view dynamically. We have already learned how to change report columns and even column labels in ods reports dynamically.
It is not supported. Once the view is displayed in a tab, the label are static for this tab.
You must open the view using an action with a context that define which labels to display for the all life of the tab.
Lately we have been busy with another task.
But finally our problem with dynamic columns was solved.
Many thanks to everyone for the valuable advice.
Special thanks to @pokoli for the good example.