defonchange(*args): """ Return a decorator to decorate an onchange method for given fields. Each argument must be a field name:: @api.onchange('partner_id') def _onchange_partner(self): self.message = "Dear %s" % (self.partner_id.name or "") In the form views where the field appears, the method will be called when one of the given fields is modified. The method is invoked on a pseudo-record that contains the values present in the form. Field assignments on that record are automatically sent back to the client. The method may return a dictionary for changing field domains and pop up a warning message, like in the old API:: return { 'domain': {'other_id': [('partner_id', '=', partner_id)]}, 'warning': {'title': "Warning", 'message': "What is this?", 'type': 'notification'}, } If the type is set to notification, the warning will be displayed in a notification. Otherwise it will be displayed in a dialog as default. .. danger:: Since ``@onchange`` returns a recordset of pseudo-records, calling any one of the CRUD methods (:meth:`create`, :meth:`read`, :meth:`write`, :meth:`unlink`) on the aforementioned recordset is undefined behaviour, as they potentially do not exist in the database yet. Instead, simply set the record's field like shown in the example above or call the :meth:`update` method. .. warning:: ``@onchange`` only supports simple field names, dotted names (fields of relational fields e.g. ``partner_id.tz``) are not supported and will be ignored """ return attrsetter('_onchange', args)
defattrsetter(attr, value): """ Return a function that sets ``attr`` on its argument and returns it. """ returnlambda method: setattr(method, attr, value) or method
defonchange(self, values, field_name, field_onchange): """ Perform an onchange on the given field. :param values: dictionary mapping field names to values, giving the current state of modification :param field_name: name of the modified field, or list of field names (in view order), or False :param field_onchange: dictionary mapping field names to their on_change attribute """ # this is for tests using `Form` self.flush() ... 省略 ... return result