Closed elliotxin closed 3 years ago
Copy the JSON below into the Edit JSON
(wrench icon) of a Select field/component.
This fetches all res.partner
records and shows its name
field value.
How this basically works can be studied (see comments or code):
Currently only authenticated users can use this data URL.
{
"label": "Customer",
"widget": "choicesjs",
"tableView": true,
"dataSrc": "url",
"data": {
"url": "/data",
"headers": [
{
"key": "",
"value": ""
}
],
"values": [],
"json": "",
"resource": "",
"custom": ""
},
"selectThreshold": 0.3,
"key": "customer",
"type": "select",
"indexeddb": {
"filter": {}
},
"filter": "model=res.partner&label=name",
"input": true,
"disableLimit": false,
"placeholder": "",
"prefix": "",
"customClass": "",
"suffix": "",
"multiple": false,
"defaultValue": null,
"protected": false,
"unique": false,
"persistent": true,
"hidden": false,
"clearOnHide": true,
"refreshOn": "",
"redrawOn": "",
"modalEdit": false,
"labelPosition": "top",
"description": "",
"errorLabel": "",
"tooltip": "",
"hideLabel": false,
"tabindex": "",
"disabled": false,
"autofocus": false,
"dbIndex": false,
"customDefaultValue": "",
"calculateValue": "",
"calculateServer": false,
"attributes": {},
"validateOn": "change",
"validate": {
"required": false,
"custom": "",
"customPrivate": false,
"strictDateValidation": false,
"multiple": false,
"unique": false
},
"conditional": {
"show": null,
"when": null,
"eq": ""
},
"overlay": {
"style": "",
"left": "",
"top": "",
"width": "",
"height": ""
},
"allowCalculateOverride": false,
"encrypted": false,
"showCharCount": false,
"showWordCount": false,
"properties": {},
"allowMultipleMasks": false,
"clearOnRefresh": false,
"limit": 100,
"valueProperty": "",
"lazyLoad": true,
"searchEnabled": true,
"searchField": "",
"minSearch": 0,
"readOnlyValue": false,
"authenticate": false,
"template": "<span>{{ item.label }}</span>",
"selectFields": "",
"searchThreshold": 0.3,
"uniqueOptions": false,
"fuseOptions": {
"include": "score",
"threshold": 0.3
},
"customOptions": {},
"id": "ewcr0yf"
}
@elliotxin Could you confirm whether this is solved?
I followed your instruction, unfortunately, its seems not working.
@elliotxin thanks for sharing!
Following questions and remarks. Please answer so we can analyse and have a clear case.
Could you share theresponse of the /data
request(s) ?
Any error visible in the odoo log?
The /data
and /res_data
requests only allow authenticated users.
In case you're using in website (public user) this won't work (yet).
The Res(ource) Model
fields (also res_id
) ain't involved in the /data
request.
Those Res(ource) Model
fields can be used in the /res_data
request, implemented in https://github.com/novacode-nl/odoo-formio/blob/14.0/formio/controllers/main.py#L227
@bobslee Actually, it's working in the backend, but won't work on the website, in my requirement, I want it to work on the website.
@elliotxin Ok, glad you experienced it works in backend.
To implement (access) this on the website, it involves some security considerations and good practice. I don't want to open/grant requests to every model in Odoo.
Do you've a suggestion? Feel free to describe and maybe submit a PR? Otherwise you could send me a DM (mail), so we can agree on broader support and efforts from my end.
@elliotxin I assume you don't want to elaborate further on this anymore?
Please re-open and comment if the request remains.
@elliotxin Populating a select component (now) works for a Form on the website. Just setup model access (fine grain with record rules) for the public user group.
In Odoo 13, I create one form, and in the Res Model, I choose sale.order, I want to create one select field, the user can use this select field to select the Odoo customer name, which like the "res. partner " name to show in the select field. Anyone can guide me on how to do this? Thanks a lot.