Skip to content

Commit 03f201a

Browse files
[ADD] website_form_partner_specific_user_account
1 parent 83fcd63 commit 03f201a

17 files changed

Lines changed: 820 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../website_form_partner_specific_user_account
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import setuptools
2+
3+
setuptools.setup(
4+
setup_requires=['setuptools-odoo'],
5+
odoo_addon=True,
6+
)
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
==========================================
2+
Website Form Partner Specific User Account
3+
==========================================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:2e500aa333d78504c4193278e7dcc9109518c14d7bb60052e41f51baa0777d78
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fwebsite-lightgray.png?logo=github
20+
:target: https://github.com/OCA/website/tree/15.0/website_form_partner_specific_user_account
21+
:alt: OCA/website
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/website-15-0/website-15-0-website_form_partner_specific_user_account
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/website&target_branch=15.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module is intended for use when the “Specific User Account” setting
32+
is enabled on a website.
33+
34+
It assigns the current website to partners used by website forms and
35+
ensures partner lookup and assignment are restricted to that website.
36+
37+
In standard Odoo, partner resolution from website forms does not
38+
consider the current website. When “Specific User Account” is enabled,
39+
this may result in a partner from another website being assigned if the
40+
same email address exists across multiple websites.
41+
42+
This module addresses this issue.
43+
44+
**Table of contents**
45+
46+
.. contents::
47+
:local:
48+
49+
Configuration
50+
=============
51+
52+
To enable company-based partner isolation for website forms:
53+
54+
- Go to Website → Configuration → Websites.
55+
- Open the website you want to configure.
56+
- Enable Restrict Partner to Company.
57+
58+
- When enabled, partner lookup and creation from website forms will
59+
be limited to the website’s company.
60+
- Only partners belonging to that company will be matched, and any
61+
newly created partners will be assigned to the same company.
62+
63+
Known issues / Roadmap
64+
======================
65+
66+
Partner email is currently inferred from multiple possible form fields
67+
(email_from, partner_email, email).
68+
69+
Note: The module assigns the current website to partners missing
70+
``website_id``, affecting not only newly created partners from website
71+
forms but also existing partners when they are used in a website form.
72+
73+
Bug Tracker
74+
===========
75+
76+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/website/issues>`_.
77+
In case of trouble, please check there if your issue has already been reported.
78+
If you spotted it first, help us to smash it by providing a detailed and welcomed
79+
`feedback <https://github.com/OCA/website/issues/new?body=module:%20website_form_partner_specific_user_account%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
80+
81+
Do not contact contributors directly about support or help with technical issues.
82+
83+
Credits
84+
=======
85+
86+
Authors
87+
-------
88+
89+
* Quartile
90+
91+
Contributors
92+
------------
93+
94+
- ``Quartile <https://www.quartile.co>``\ \_\_:
95+
96+
- Aung Ko Ko Lin
97+
- Yoshi Tashiro
98+
99+
Maintainers
100+
-----------
101+
102+
This module is maintained by the OCA.
103+
104+
.. image:: https://odoo-community.org/logo.png
105+
:alt: Odoo Community Association
106+
:target: https://odoo-community.org
107+
108+
OCA, or the Odoo Community Association, is a nonprofit organization whose
109+
mission is to support the collaborative development of Odoo features and
110+
promote its widespread use.
111+
112+
.. |maintainer-yostashiro| image:: https://github.com/yostashiro.png?size=40px
113+
:target: https://github.com/yostashiro
114+
:alt: yostashiro
115+
.. |maintainer-aungkokolin1997| image:: https://github.com/aungkokolin1997.png?size=40px
116+
:target: https://github.com/aungkokolin1997
117+
:alt: aungkokolin1997
118+
119+
Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:
120+
121+
|maintainer-yostashiro| |maintainer-aungkokolin1997|
122+
123+
This module is part of the `OCA/website <https://github.com/OCA/website/tree/15.0/website_form_partner_specific_user_account>`_ project on GitHub.
124+
125+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import controllers
2+
from . import models
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2025 Quartile (https://www.quartile.co)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
{
5+
"name": "Website Form Partner Specific User Account",
6+
"summary": (
7+
"Restrict website form partner lookup to the current website "
8+
"when Specific User Account is enabled"
9+
),
10+
"version": "15.0.1.0.0",
11+
"category": "Website",
12+
"license": "AGPL-3",
13+
"author": "Quartile, Odoo Community Association (OCA)",
14+
"website": "https://github.com/OCA/website",
15+
"depends": ["website"],
16+
"data": ["views/website_views.xml"],
17+
"maintainers": ["yostashiro", "aungkokolin1997"],
18+
"installable": True,
19+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import main
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright 2025 Quartile (https://www.quartile.co)
2+
# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo.addons.website.controllers.form import WebsiteForm
5+
6+
7+
class WebsiteForm(WebsiteForm):
8+
def insert_record(self, request, model, values, custom, meta=None):
9+
website = request.website
10+
if not website.specific_user_account:
11+
return super().insert_record(request, model, values, custom, meta)
12+
partner_id = values.get("partner_id")
13+
if not partner_id:
14+
return super().insert_record(request, model, values, custom, meta)
15+
Partner = request.env["res.partner"].sudo()
16+
partner = Partner.browse(partner_id)
17+
if not partner:
18+
return super().insert_record(request, model, values, custom, meta)
19+
email = (
20+
values.get("email_from")
21+
or values.get("partner_email")
22+
or values.get("email")
23+
)
24+
# Intended for newly created partners, but applies to any partner without website_id
25+
if not partner.website_id:
26+
partner.website_id = website.id
27+
# Intended for newly created partners, but applies to any partner without company_id
28+
if not partner.company_id and website.restrict_partner_to_company:
29+
partner.company_id = website.company_id.id
30+
if email and partner.website_id != website:
31+
domain = [
32+
("email", "=", email),
33+
("website_id", "=", website.id),
34+
]
35+
if website.restrict_partner_to_company:
36+
domain.append(("company_id", "=", website.company_id.id))
37+
website_partner = Partner.search(domain, limit=1)
38+
if not website_partner and values.get("partner_name"):
39+
vals = {
40+
"email": email,
41+
"name": values.get("partner_name"),
42+
"website_id": website.id,
43+
}
44+
if website.restrict_partner_to_company:
45+
vals["company_id"] = website.company_id.id
46+
website_partner = Partner.create(vals)
47+
if website_partner:
48+
values["partner_id"] = website_partner.id
49+
return super().insert_record(request, model, values, custom, meta)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import website
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2025 Quartile (https://www.quartile.co)
2+
# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import fields, models
5+
6+
7+
class Website(models.Model):
8+
_inherit = "website"
9+
10+
restrict_partner_to_company = fields.Boolean(
11+
help="When enabled, partner lookup and creation from website forms "
12+
"are restricted to the website's company."
13+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
To enable company-based partner isolation for website forms:
2+
3+
- Go to Website → Configuration → Websites.
4+
- Open the website you want to configure.
5+
- Enable Restrict Partner to Company.
6+
- When enabled, partner lookup and creation from website forms will be limited to the website’s company.
7+
- Only partners belonging to that company will be matched, and any newly created partners will be assigned to the same company.

0 commit comments

Comments
 (0)