Skip to content
Merged
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
37 changes: 28 additions & 9 deletions website_form_partner_specific_user_account/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ Website Form Partner Specific User Account

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

This module assigns the current website to partners used by website
forms and ensures partner lookup and assignment are restricted to that
website.
This module is intended for use when the “Specific User Account” setting
is enabled on a website.

In standard Odoo, partner searches triggered from the website may lead
to incorrect assignments. For example, the partner assignment does not
take the website into account and may assign the wrong partner when
“Specific User Account” is enabled, which allows a separate user account
to be created for each website even if they share the same email
address.
It assigns the current website to partners used by website forms and
ensures partner lookup and assignment are restricted to that website.

In standard Odoo, partner resolution from website forms does not
consider the current website. When “Specific User Account” is enabled,
this may result in a partner from another website being assigned if the
same email address exists across multiple websites.

This module addresses this issue.

Expand All @@ -46,12 +46,30 @@ This module addresses this issue.
.. contents::
:local:

Configuration
=============

To enable company-based partner isolation for website forms:

- Go to Website → Configuration → Websites.
- Open the website you want to configure.
- Enable Restrict Partner to Company.

- When enabled, partner lookup and creation from website forms will
be limited to the website’s company.
- Only partners belonging to that company will be matched, and any
newly created partners will be assigned to the same company.

Known issues / Roadmap
======================

Partner email is currently inferred from multiple possible form fields
(email_from, partner_email, email).

Note: The module assigns the current website to partners missing
``website_id``, affecting not only newly created partners from website
forms but also existing partners when they are used in a website form.

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

Expand All @@ -76,6 +94,7 @@ Contributors
- ``Quartile <https://www.quartile.co>``\ \_\_:

- Aung Ko Ko Lin
- Yoshi Tashiro

Maintainers
-----------
Expand Down
1 change: 1 addition & 0 deletions website_form_partner_specific_user_account/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import controllers
from . import models
5 changes: 5 additions & 0 deletions website_form_partner_specific_user_account/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@

{
"name": "Website Form Partner Specific User Account",
"summary": (
"Restrict website form partner lookup to the current website "
"when Specific User Account is enabled"
),
"version": "15.0.1.0.0",
"category": "Website",
"license": "AGPL-3",
"author": "Quartile, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/website",
"depends": ["website"],
"data": ["views/website_views.xml"],
"maintainers": ["yostashiro", "aungkokolin1997"],
"installable": True,
}
54 changes: 35 additions & 19 deletions website_form_partner_specific_user_account/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,48 @@ def insert_record(self, request, model, values, custom, meta=None):
return super().insert_record(request, model, values, custom, meta)
Partner = request.env["res.partner"].sudo()
partner = Partner.browse(partner_id)
if not partner.exists():
if not partner:
return super().insert_record(request, model, values, custom, meta)
email = (
values.get("email_from")
or values.get("partner_email")
or values.get("email")
)
restrict = website.restrict_partner_to_company
website_company = website.company_id
# Conflicts based on what the partner already has
company_conflict = (
restrict
and bool(partner.company_id)
and partner.company_id != website_company
)
website_conflict = bool(partner.website_id) and partner.website_id != website
# If there is any conflict, do not assign missing fields to this partner.
# Instead, look for/create a partner that matches website (+company if restricted).
if email and (website_conflict or company_conflict):
domain = [
("email", "=", email),
("website_id", "=", website.id),
]
if website.restrict_partner_to_company:
domain.append(("company_id", "=", website.company_id.id))
website_partner = Partner.search(domain, limit=1)
if not website_partner:
vals = {
"email": email,
"name": values.get("partner_name", False),
"website_id": website.id,
}
if website.restrict_partner_to_company:
vals["company_id"] = website.company_id.id
website_partner = Partner.create(vals)
if website_partner:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have removed this condition.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I will follow up this.

values["partner_id"] = website_partner.id
partner = website_partner
# Intended for newly created partners, but applies to any partner without website_id
if not partner.website_id:
partner.website_id = website.id
if email and partner.website_id != website:
website_partner = Partner.search(
[
("email", "=", email),
("website_id", "=", website.id),
],
limit=1,
)
if not website_partner and values.get("partner_name"):
website_partner = Partner.create(
{
"email": email,
"name": values.get("partner_name"),
"website_id": website.id,
}
)
if website_partner:
values["partner_id"] = website_partner.id
# Intended for newly created partners, but applies to any partner without company_id
if restrict and not partner.company_id:
partner.company_id = website_company.id
return super().insert_record(request, model, values, custom, meta)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import website
13 changes: 13 additions & 0 deletions website_form_partner_specific_user_account/models/website.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2025 Quartile (https://www.quartile.co)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class Website(models.Model):
_inherit = "website"

restrict_partner_to_company = fields.Boolean(
help="When enabled, partner lookup and creation from website forms "
"are restricted to the website's company."
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
To enable company-based partner isolation for website forms:

- Go to Website → Configuration → Websites.
- Open the website you want to configure.
- Enable Restrict Partner to Company.
- When enabled, partner lookup and creation from website forms will be limited to the website’s company.
- Only partners belonging to that company will be matched, and any newly created partners will be assigned to the same company.
Original file line number Diff line number Diff line change
Expand Up @@ -370,61 +370,80 @@ <h1 class="title">Website Form Partner Specific User Account</h1>
!! source digest: sha256:2e500aa333d78504c4193278e7dcc9109518c14d7bb60052e41f51baa0777d78
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/website/tree/15.0/website_form_partner_specific_user_account"><img alt="OCA/website" src="https://img.shields.io/badge/github-OCA%2Fwebsite-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/website-15-0/website-15-0-website_form_partner_specific_user_account"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/website&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module assigns the current website to partners used by website
forms and ensures partner lookup and assignment are restricted to that
website.</p>
<p>In standard Odoo, partner searches triggered from the website may lead
to incorrect assignments. For example, the partner assignment does not
take the website into account and may assign the wrong partner when
“Specific User Account” is enabled, which allows a separate user account
to be created for each website even if they share the same email
address.</p>
<p>This module is intended for use when the “Specific User Account” setting
is enabled on a website.</p>
<p>It assigns the current website to partners used by website forms and
ensures partner lookup and assignment are restricted to that website.</p>
<p>In standard Odoo, partner resolution from website forms does not
consider the current website. When “Specific User Account” is enabled,
this may result in a partner from another website being assigned if the
same email address exists across multiple websites.</p>
<p>This module addresses this issue.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#known-issues-roadmap" id="toc-entry-1">Known issues / Roadmap</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-2">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-3">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-4">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-5">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-6">Maintainers</a></li>
<li><a class="reference internal" href="#configuration" id="toc-entry-1">Configuration</a></li>
<li><a class="reference internal" href="#known-issues-roadmap" id="toc-entry-2">Known issues / Roadmap</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-3">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-4">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-5">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-6">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-7">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="configuration">
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<p>To enable company-based partner isolation for website forms:</p>
<ul class="simple">
<li>Go to Website → Configuration → Websites.</li>
<li>Open the website you want to configure.</li>
<li>Enable Restrict Partner to Company.<ul>
<li>When enabled, partner lookup and creation from website forms will
be limited to the website’s company.</li>
<li>Only partners belonging to that company will be matched, and any
newly created partners will be assigned to the same company.</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="known-issues-roadmap">
<h1><a class="toc-backref" href="#toc-entry-1">Known issues / Roadmap</a></h1>
<h1><a class="toc-backref" href="#toc-entry-2">Known issues / Roadmap</a></h1>
<p>Partner email is currently inferred from multiple possible form fields
(email_from, partner_email, email).</p>
<p>Note: The module assigns the current website to partners missing
<tt class="docutils literal">website_id</tt>, affecting not only newly created partners from website
forms but also existing partners when they are used in a website form.</p>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/website/issues">GitHub Issues</a>.
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
<a class="reference external" href="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**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1>
<h1><a class="toc-backref" href="#toc-entry-4">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
<ul class="simple">
<li>Quartile</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<ul class="simple">
<li><tt class="docutils literal">Quartile <span class="pre">&lt;https://www.quartile.co&gt;</span></tt>__:<ul>
<li>Aung Ko Ko Lin</li>
<li>Yoshi Tashiro</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_website_form_partner_specific_user_account
Loading