Skip to Content
Menu
This question has been flagged
1 Reply
2667 Views

Hello my friend;

Please i have a question and i want your help.

In fact, i have two fields with a complicated structure.

* First Field: Its an integer but want when it is displayed to show it with 2caracters and then carriage return.

Example: the number is 254789 when it is displayed it must be showed as 25 then 47 and then 89.

*Second Field: its a char when its is displayed it has to show it with 4caracters and then carriage return.

Example: the char is 'today' when it is displayed it must be showed as toda then y.

Need your help please.

Is here any suggestion.

Thanks a lot in advance.

Regards.

Avatar
Discard
Best Answer

Dear Drees Far,

Using on change method you can perform your structure.

Step 1: Create two new field which has char data type

Step 2: Now you will put on change method in First Field(integer) and Second Field(char) 

Step 3: On change method return the value as per you set logic in python file and set those value in new two char field.

Example:

in .XML file

<field name="first_field" on_change="change_first_field(first_field)" />

<field name="second_field" on_change="change_second_field(second_field)" />

in .PY file

First create two new field which have char data type

'new_first_field': fields.char('New First Field'),

'new_second_field': fields.char('New Second Field'),

def change_first_field(self, cr, uid, ids, first_field, context=None):

    if not first_field:

        return {}

    new_str = str(first_field)

    new_value_first = new_str[0:2] + ' Then ' + new_str[2:4] + ' Then ' + new_str[4:6]

    return {

        'value': {    

            'new_first_field': new_value_first,

        }

    }


def change_second_field(self, cr, uid, ids, second_field, context=None):

if not second_field:

    return {}

new_str = str(second_field)

new_value_second = new_str[0:4] + ' Then ' + new_str[4:5]

return {

    'value': {

        'new_second_field': new_value_second,

    }

}

May this code will help you

Thanks & Regards

Ankit H Gandhi

Avatar
Discard
Related Posts Replies Views Activity
4
Oct 16
29680
1
Jun 15
111
0
Apr 15
81
2
Apr 15
270
0
Apr 15
59