跳至内容
菜单
此问题已终结
1 回复
2772 查看

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!

形象
丢弃
最佳答案

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

形象
丢弃
编写者

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!

相关帖文 回复 查看 活动
0
4月 24
1198
4
12月 23
20224
0
12月 21
5391
4
5月 25
2496
2
5月 25
5855