Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
beautifulsoup4
bokeh==3.6.3
mpld3==0.5.10
python-dateutil
123 changes: 123 additions & 0 deletions web_form/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
========
Web Form
========

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:7c2822ca9e83e18563cd7136bc05c2d053eb04b22856f2f8160f937ec20f582d
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github
:target: https://github.com/OCA/web/tree/18.0/web_form
:alt: OCA/web
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/web-18-0/web-18-0-web_form
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows you to create lightweight public forms, accessible to
anyone with a secure link. Submitting the form creates records in the
chosen model (e.g., leads, tickets, applications or any custom model),
with the option to set default input values.

**Table of contents**

.. contents::
:local:

Use Cases / Context
===================

This module can be used to collect data from external users (or partners
without a portal account) via a simple web form, then create records in
any Odoo model using those submitted values. Each form is tied to a
partner-specific secure URL using a one-time rotatable token.

Usage
=====

Flow
----

1. Go to menu : **Web Form -> Forms** and Create new **Web Form**,
selects the target model (e.g., crm.lead, helpdesk.applicant, custom
model…).

2. Configure inputs (labels, types, required/readonly, mapped fields)
and optional computed default values.

3. Send the secure link to a partner (via the mail-template snippet or
any channel).

4. Partner opens the link, form renders with defaults, submits → record
is created in the target model.

5. Partner’s token rotates to invalidate the previous link.

Security
--------

The **Web Form** is accessible to the user in the **Other / Web Form
User** group

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_form%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* ACSONE SA/NV

Contributors
------------

- Samir GUESMI samir.guesmi@acsone.eu (https://www.acsone.eu)
- Souheil BEJAOUI souheil.bejaoui@acsone.eu (https://www.acsone.eu)

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-sbejaoui| image:: https://github.com/sbejaoui.png?size=40px
:target: https://github.com/sbejaoui
:alt: sbejaoui

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-sbejaoui|

This module is part of the `OCA/web <https://github.com/OCA/web/tree/18.0/web_form>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions web_form/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import tools
from . import controllers
from . import models
29 changes: 29 additions & 0 deletions web_form/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2019 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Web Form",
"summary": """
This addon add web forms""",
"version": "18.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV, Odoo Community Association (OCA)",
"category": "web",
"website": "https://github.com/OCA/web",
"depends": [
# Odoo Community
"mail",
"web",
],
"data": [
"security/groups.xml",
"security/web_form_default.xml",
"security/web_form_input.xml",
"security/web_form.xml",
"views/web_form.xml",
"views/templates.xml",
],
"maintainers": ["sbejaoui"],
"external_dependencies": {"python": ["python-dateutil"]},
"installable": True,
}
1 change: 1 addition & 0 deletions web_form/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import web_form
87 changes: 87 additions & 0 deletions web_form/controllers/web_form.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Copyright 2019 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import http
from odoo.http import request


class WebForm(http.Controller):
def _prepare_controller_params(self, form_code, form_token, partner_id):
form = request.env["web.form"].sudo().search([("code", "=", form_code)])
partner = request.env["res.partner"].sudo().search([("id", "=", partner_id)])
if not form or not partner:
return (
form,
partner,
request.render("web_form.form_not_found"),
)
if partner.form_token != form_token:
return (
form,
partner,
request.render("web_form.form_expired"),
)
return form, partner, None

@http.route(
[
"/form",
"/form/<string:form_code>",
"/form/<string:form_code>/<string:form_token>",
],
type="http",
auth="public",
methods=["GET"],
website=True,
)
def form_wrong_url(self, **kwargs):
return request.render("web_form.form_not_found")

@http.route(
"/web_form/<string:form_code>/" "<string:form_token>/<int:partner_id>",
type="http",
auth="public",
methods=["GET"],
website=True,
)
def web_form(self, form_code, form_token, partner_id, **kwargs):
form, partner, render = self._prepare_controller_params(
form_code, form_token, partner_id
)
if render:
return render
try:
form._get_default_values_for_input(partner)
except Exception as e: # pylint: disable=broad-except
form.message_post(body=e.args[0])
return request.render("web_form.form_unknown_issue")
return request.render(
"web_form.web_form",
{
"form": form,
"partner": partner,
"data": form._get_default_values_for_input(partner),
},
)

@http.route(
"/web_form_create/<string:form_code>/" "<string:form_token>/<int:partner_id>",
type="http",
auth="public",
methods=["POST"],
website=True,
)
def web_form_create(self, form_code, form_token, partner_id, **kwargs):
form, partner, render = self._prepare_controller_params(
form_code, form_token, partner_id
)
if render:
return render
try:
with request.cr.savepoint():
result_object = form._create_result_object(partner, kwargs)
form._finalize_create_result_object(result_object, partner)
except Exception as e: # pylint: disable=broad-except
form.message_post(body=e.args[0])
return request.render("web_form.form_unknown_issue")
return request.render("web_form.form_thank_you")
5 changes: 5 additions & 0 deletions web_form/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from . import web_form
from . import web_form_line
from . import res_partner
from . import web_form_input
from . import web_form_default
25 changes: 25 additions & 0 deletions web_form/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2019 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import uuid

from odoo import api, fields, models


class ResPartner(models.Model):
_inherit = "res.partner"

@api.model
def _new_form_token(self):
return uuid.uuid4().hex

form_token = fields.Char(
"Security Token",
default=_new_form_token,
help="Access token to access to the web form",
)

def _set_form_token(self):
self.ensure_one()
self.form_token = uuid.uuid4().hex
return True
Loading