novacode-nl / odoo-formio

Odoo Forms app & modules
https://apps.odoo.com/apps/modules/18.0/formio/
Other
69 stars 90 forks source link

How to populate the odoo data in select filed via odoo 13? #116

Closed elliotxin closed 3 years ago

elliotxin commented 3 years ago

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.

bobslee commented 3 years ago

Copy the JSON below into the Edit JSON (wrench icon) of a Select field/component. image

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"
}
bobslee commented 3 years ago

@elliotxin Could you confirm whether this is solved?

elliotxin commented 3 years ago

I followed your instruction, unfortunately, its seems not working. image image

bobslee commented 3 years ago

@elliotxin thanks for sharing!

Following questions and remarks. Please answer so we can analyse and have a clear case.

  1. Could you share theresponse of the /data request(s) ?

  2. Any error visible in the odoo log?

  3. The /data and /res_data requests only allow authenticated users. In case you're using in website (public user) this won't work (yet).

  4. 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

elliotxin commented 3 years ago

@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.

bobslee commented 3 years ago

@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.

bobslee commented 3 years ago

@elliotxin I assume you don't want to elaborate further on this anymore?

bobslee commented 3 years ago

Please re-open and comment if the request remains.

bobslee commented 2 years ago

@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.