odoo-formio
odoo-formio copied to clipboard
QWeb Select component: dict value with data source URL
Regular select component stores the selected value. However, with datasource URL it stores a dict.
Problem: This results in empty select component (input) in the QWeb report. No value visible.
Hi, It's curious because it returns an empty boolean object in QWEB render 🤔 However, in screen views there is no problem
@zuher83 What's your question actually?
@bobslee , I'm looking for an idea to help solve the bug because it's been unresolved for a long time. I've spent a few hours debugging and I still haven't found anything...
Url returns a dictionary eg: {'id': self.id, 'value_label': self.name} this is stored (object or str) I've tried everything and it's visible everywhere except when printing.
When debugging with ipb I see that it has an object but it's empty.
My question is, do you have any idea how to fix this bug or a different way of displaying the values?
@zuher83 Can you provide some test data:
- Builder JSON
- Form submission JSON
Maybe I can find some time to fix this... upcoming days, weeks.
@bobslee ok thanks
This is form builder JSON
{"components": [{"label": "Partner", "labelPosition": "top", "widget": "choicesjs", "placeholder": "", "description": "", "tooltip": "", "customClass": "", "tabindex": "", "hidden": false, "hideLabel": false, "uniqueOptions": false, "autofocus": false, "disabled": false, "tableView": true, "modalEdit": false, "multiple": false, "dataSrc": "url", "data": {"resource": "", "url": "ressource/partner", "json": "", "custom": "", "headers": [{"key": "", "value": ""}], "values": [{"label": "", "value": ""}]}, "dataType": "", "idPath": "id", "valueProperty": "value_labels", "template": "<span>{{ item.label }}</span>", "refreshOn": "", "refreshOnBlur": "", "clearOnRefresh": false, "searchEnabled": true, "selectThreshold": 0.3, "readOnlyValue": false, "customOptions": {}, "useExactSearch": false, "persistent": true, "protected": false, "dbIndex": false, "encrypted": false, "clearOnHide": true, "customDefaultValue": "", "calculateValue": "", "calculateServer": false, "allowCalculateOverride": false, "validateOn": "change", "validate": {"required": false, "customMessage": "", "custom": "", "customPrivate": false, "json": "", "strictDateValidation": false, "multiple": false, "unique": false, "onlyAvailableItems": false}, "unique": false, "errorLabel": "", "errors": "", "key": "partner", "tags": [], "properties": {}, "conditional": {"show": null, "when": null, "eq": "", "json": ""}, "customConditional": "", "logic": [], "attributes": {}, "overlay": {"style": "", "page": "", "left": "", "top": "", "width": "", "height": ""}, "type": "select", "indexeddb": {"filter": {}}, "selectFields": "", "searchField": "", "searchDebounce": 0.3, "minSearch": 0, "filter": "", "limit": 100, "redrawOn": "", "input": true, "prefix": "", "suffix": "", "dataGridLabel": false, "showCharCount": false, "showWordCount": false, "allowMultipleMasks": false, "addons": [], "authenticate": false, "ignoreCache": false, "lazyLoad": true, "fuseOptions": {"include": "score", "threshold": 0.3}, "id": "emqxebi", "defaultValue": "", "selectValues": "", "disableLimit": false, "sort": "", "noRefreshOnScroll": false}, {"type": "button", "label": "Submit", "key": "submit", "size": "md", "block": false, "action": "submit", "disableOnInvalid": true, "theme": "primary", "id": "eooush2", "input": true, "placeholder": "", "prefix": "", "customClass": "", "suffix": "", "multiple": false, "defaultValue": null, "protected": false, "unique": false, "persistent": false, "hidden": false, "clearOnHide": true, "refreshOn": "", "redrawOn": "", "tableView": false, "modalEdit": false, "dataGridLabel": true, "labelPosition": "top", "description": "", "errorLabel": "", "tooltip": "", "hideLabel": false, "tabindex": "", "disabled": false, "autofocus": false, "dbIndex": false, "customDefaultValue": "", "calculateValue": "", "calculateServer": false, "widget": {"type": "input"}, "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, "addons": [], "leftIcon": "", "rightIcon": ""}]}
Create test controller:
import logging
from odoo.http import request
from odoo.addons.formio.controllers.main import FormioController
class FormioController(FormioController):
@http.route(['/formio/form/ressource/partner', '/formio/builder/ressource/partner'], type='http', auth='user', csrf=False)
def get_partner_data(self, **kwargs):
partners = request.env['res.partner'].sudo().search(
[('active', '=', True)])
partners_ids = []
for partner in partners:
label = '%s - %s' % (partner.name, partner.ref)
vals = {
'id': partner.id,
'name': partner.name,
'display_name': partner.display_name,
'email': partner.email or '',
'phone': partner.phone or '',
'mobile': partner.mobile or '',
'street': partner.street or '',
'street2': partner.street2 or '',
'zip': partner.zip or '',
'city': partner.city or '',
'country_id': partner.country_id.name or '',
'function': partner.function or '',
'vat': partner.vat or '',
'ref': partner.ref or '',
'value_labels': label,
'label': label,
}
partners_ids.append(vals)
return json.dumps(partners_ids)
result in form submission:
{"partner": "Martine VENTURA - 03FSUD001", "submit": true}
@zuher83 Why the (test) controller is need?
I suppose the endpoint fetches partner records to load into a Select component? Similar (generic) functionality provided by module: https://apps.odoo.com/apps/modules/16.0/formio_components_api/
@bobslee Yes, I know, this is an easy example for URL, because the forms in my case are integrated into a complex logic and other endpoints than Odoo 🙂
@zuher83 Concerning the form submission JSON. I didn't expect the label, but the ID value.
Also I expect it will take a few hours to analyse and develop this. We offer this as paid service. You can submit a request to discuss on https://www.novacode.nl/contact