Update field string dynamically

Hi all,

Is there any way to update tree/form string attribute dynamically based on certain field value? I’ve tried to add the logic in view_attributes() but it did not work.

    @classmethod
    def view_attributes(cls):
        return super(x, cls).view_attributes() + [
            ('//label[@name="quantity"]', 'string',If(Eval('transfer_type') =='request', 'Request Quantity', 'Transfer Quantity'))]

The quantity string will be updated based on transfer_type value. If user select “request” type, the quantity will be displayed as “Request Quantity” instead.

Thank you.

Hello,

For tree views this is impossible AFAIK, since the column name is independent of the list of records.

For form views, a workaround would be to define a separate Function (Char) field, and use it as a label for the field.
So the string value would be computed in the function field getter, and displayed in place of the label of the main field.

Basically, replace:

<label name="quantity"/>

with

<label name="quantity_label" string=""/>

Edit: used string= rather than widget= in xml

No the string of labels are static. This is mainly because they are used on list as column header.

On form you can put some labels in side the same group and make them visible one at a time using a PYSON expression on each one.
But the general idea of Tryton is that a field represents a unique concept.

Thank you for your prompt reply. I was thinking to use view_ids on field to separate the form and tree views. Is there any way to dynamically set the view_ids based on record value?
For instance, set the view_ids to X when Eval(‘transfer_type’) ==‘request’ whereas set the view_ids to Y when Eval(‘transfer_type’) ==‘return’.

Thank you

No, you must consider that in Tryton all the views are static (and you can just manage to hide/show (with states) parts of it).

Thank you for your clarification.