0
votes

In an Odoo9 instance, I need to create a functionality to read the values of two custom fields inside the product's create/update form (module is in place, fields are in there and working) and combine the inputs there into a string, then inject this string into a third field (namely the product name).

The idea behind that: there is an internal part number (e.g. 123456) and an internal part name (e.g. "High pressure valve"). The final unique name (standard Odoo name field) is therefore supposed to be "123456 High pressure valve" and this needs to be auto-generated from the two other fields.

As a sidenote: all fields are in the same form view.

Any help greatly appreciated!

1

1 Answers

0
votes

I found the answer and post it here for reference in case someone else needs this:

You have to add onchange=myonchangefunction to the field's XML in your module, then define an onchange handler like so:

@api.onchange('myonchangefunction')
    def _some_meaningful_name(self):
        self.field3 = self.field1 + " " + self.field2
        return

In this example, field3 is updated with the concatenated values of field1 and field2.