You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* see this nice reference about`many2many_tags`field: [https://ludwiktrammer.github.io/odoo/form-widgets-many2many-fields-options-odoo.html](https://ludwiktrammer.github.io/odoo/form-widgets-many2many-fields-options-odoo.html)
59
+
60
+
## Creating the form using web page edition (failure)
61
+
62
+
I tried to create the form to add a contact using the web page edition \+ add a form.
63
+
But this is far too limited. We only can add simple select and checkboxes, it makes the form really cumbersome and not welcoming to users. The number of thing than can be done is really limited and didn’t find any way to extend it
64
+
65
+
## Creating the form using FormBuilder
66
+
67
+
Another tool is installed on the test instance which is called FormBuilder.
68
+
There is absolutely no documentation on this and it’s far from easy to understand how to use it. The best clue are the screenshots on the product presentation page that you can find here: [https://github.com/novacode-nl/odoo-formio/tree/16.0/formio/static/description](https://github.com/novacode-nl/odoo-formio/tree/16.0/formio/static/description)
69
+
70
+
This is not to be confused (as I did) with the web form editor, which looks alike, but is absolutely disconnected from this other product.
71
+
This addon does not have integration to the web page, you instead obtain a very distinctive link to your form. The advantage is that it stores answers as JSON from which you can create new objects through a script.
72
+
I tried my best to build a form but it didn’t work until I realize the problem was in the javascript itself. It was the release used which was wrong.
73
+
In Forms, using the view Configuration / [formiojs versions (github tags)](https://connect-test.openfoodfacts.org/web#cids=1&menu_id=338&action=480&model=formio.version.github.tag&view_type=list), I installed an 4.x version (the [4.15.0-rc.13 version](https://connect-test.openfoodfacts.org/web#id=3&cids=1&menu_id=338&action=479&model=formio.version&view_type=form)). And using this one, the form worked \!
74
+
Note: to add versions you have to go to settings / forms
75
+
76
+
I also looked at the source code to understand how to use the “API” thing, I was hopping to “fill” options for select box using it. **But this is not meant for this \!** It’s the contrary, it’s to eventually change or add values on server side after form validation \!
77
+
The documentation is in the `./formio_data_api/models/formio_form.py``_etl_odoo_data` docstring !
78
+
The way it works is that you can run a python script that fills the “values” dict. This can then be used this way:
79
+
80
+
*`server_api`of a component must mach you api name
81
+
* value of`server_api_value`will be seeked in values
82
+
* if there is a`server_api_value_obj`it will try to find this property (of follow a chain of properties) in the resulting object
83
+
84
+
Finally I decided to go with formio. So I created (in test) a form using the builder.
85
+
I verified that strings are translatable to french, which is great news.
86
+
87
+
To have a json list of languages, I finally go to settings, [manage languages](https://connect-test.openfoodfacts.org/web/#cids=1&menu_id=4&action=56&active_id=63&model=res.lang&view_type=list) and export all to a excel, and the use a function like:
I did the same for countries using Contacts \--\> Configuration \--\> Localization → [countries](https://connect.openfoodfacts.org/web#cids=1&menu_id=111&action=65&model=res.country&view_type=list)
92
+
93
+
## Python Action to create contact and lead
94
+
95
+
Now I have to add the action triggered on form data creation.
96
+
Started here: [https://connect-test.openfoodfacts.org/web?debug=1\#id=3\&cids=1\&menu_id=4\&action=515\&model=base.automation\&view_type=form](https://connect-test.openfoodfacts.org/web?debug=1#id=3&cids=1&menu_id=4&action=515&model=base.automation&view_type=form)
97
+
98
+
A trick is to make the action accessible to the web and use this to trigger a specific test while you try to code it \!
99
+
[Odoo API documentation is useful](https://www.odoo.com/documentation/16.0/developer/reference/backend/orm.html#reference-orm-domains) as well as the [formio object model](https://github.com/novacode-nl/odoo-formio/blob/15.0/formio/models/formio_form.py)
100
+
101
+
To get tags:
102
+
sudo \-u postgres psql crm
103
+
select id, name from`crm_tag`where name ilike 'team %' or name ilike 'volunteer' or name ilike '%ly';
104
+
select id, name from`res_partner_category`where name ilike 'team %' or name ilike 'volunteer' or name ilike '%ly';
105
+
106
+
Editing many2many fields: see [https://odoo-development.readthedocs.io/en/latest/dev/py/x2many.html](https://odoo-development.readthedocs.io/en/latest/dev/py/x2many.html) and [https://www.odoo.com/documentation/15.0/developer/reference/backend/orm.html\#odoo.fields.Command](https://www.odoo.com/documentation/15.0/developer/reference/backend/orm.html#odoo.fields.Command) it’s important to note that you must use a list of Command. eg. data\[“category_id”\]\=\[Command.set(category_ids)\].
107
+

108
+
109
+
## Sending email from a template
110
+
111
+
To send email, it’s not easy to do it in the python code. It’s easier to add an automated action that will send an email, on creation of a lead, if tag.name \= “volunteer” (edit the domain).
112
+
113
+
We then have to add a template
114
+
We go in settings, in dev mode, technical, email templates, and put it applies to lead
115
+
116
+
To insert fields in the html we need to use the template language. In subject it’s {{ }} style.
117
+
118
+

119
+
120
+
## creating an inherited view
121
+
122
+
Instead of modifying the form directly it’s better to create an inherited view that will modify it.
123
+
The odoo documentation is here: [https://www.odoo.com/documentation/15.0/developer/reference/backend/views.html](https://www.odoo.com/documentation/15.0/developer/reference/backend/views.html)
124
+
An [interesting point on Sequence field (aka priority)](https://odooninja.com/blog/tips-4/the-importance-of-correctly-setting-priority-on-inherited-views-34), so I prefer to put a high number in “Sequence).
125
+
126
+
I did it for crm and contact form. Using “Extension view” makes your changes to be applied to the view you inherit from, directly.
127
+
Here is an example:
128
+

129
+
When you use the small bug to edit a view, you can see the inherited views in the “inherited views” tab, which is important if you don’t see the field you expected to see \!
130
+
131
+
## Creating a server action to generate translations
132
+
133
+
There are a lot of translations to create and it can be cumbersome to do.
134
+
I created a server action applied to form build to parse the json and create source translations where needed. (WIP)
0 commit comments