This question has been flagged
1 Reply
799 Views

Hi,


I'm looking for a way to add default field values as a URL parameter.

Example: I want to open the form view to create a new helpdesk ticket, and automatically fill in for example the partner (assuming I know the ID beforehand), or the phone number.

Base url would be something like:

.com/web#cids=1&menu_id=227&action=326&active_id=1&model=helpdesk.ticket&view_type=form

Is there a possibility to add to this like a context parameter, to then automatically fill in 1 or more fields? looking for something like: "&context={'default_partner_id': 1}"

If this is not a possibility, how would I go about customizing this? Is there a specific function I can override to allow passing of context values? Looking for a generic solution, I want this functionality not just in helpdesk tickets but for example contacts as well.


Thanks!

Avatar
Discard
Best Answer

Hi,

Try using "default_get" it returns default values for the fields in "fields_list". Default values are determined by the context, user defaults, and the model itself. Here is the examble below.
def default_get(self, fields_list):
    res = super().default_get(fields_list)
    res['partner_id'] = self._context.get('default_field')
    return res


Hope it helps

Avatar
Discard
Author

Hi,
Thanks for the reply. Was kind of hoping it was possible without customization, but I ended up fixing it like this:
def default_get(self, fields_list):
res = super().default_get(fields_list)
for param in self._context.get('params', {}):
if param not in DEFAULT_PARAMS_ODOO:
res[param] = self._context.get('params').get(param, False)
return res

Where default_params_odoo is just a list of parameter odoo adds, like cids, menu_id etc.
Thanks for your help!