diff --git a/setup/website_form_partner_specific_user_account/odoo/addons/website_form_partner_specific_user_account b/setup/website_form_partner_specific_user_account/odoo/addons/website_form_partner_specific_user_account new file mode 120000 index 0000000000..32d4cc41ca --- /dev/null +++ b/setup/website_form_partner_specific_user_account/odoo/addons/website_form_partner_specific_user_account @@ -0,0 +1 @@ +../../../../website_form_partner_specific_user_account \ No newline at end of file diff --git a/setup/website_form_partner_specific_user_account/setup.py b/setup/website_form_partner_specific_user_account/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/website_form_partner_specific_user_account/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/website_form_partner_specific_user_account/README.rst b/website_form_partner_specific_user_account/README.rst new file mode 100644 index 0000000000..ad5809da75 --- /dev/null +++ b/website_form_partner_specific_user_account/README.rst @@ -0,0 +1,125 @@ +========================================== +Website Form Partner Specific User Account +========================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:2e500aa333d78504c4193278e7dcc9109518c14d7bb60052e41f51baa0777d78 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fwebsite-lightgray.png?logo=github + :target: https://github.com/OCA/website/tree/15.0/website_form_partner_specific_user_account + :alt: OCA/website +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/website-15-0/website-15-0-website_form_partner_specific_user_account + :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/website&target_branch=15.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module is intended for use when the “Specific User Account” setting +is enabled on a website. + +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. + +**Table of contents** + +.. 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 +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Quartile + +Contributors +------------ + +- ``Quartile ``\ \_\_: + + - Aung Ko Ko Lin + - Yoshi Tashiro + +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-yostashiro| image:: https://github.com/yostashiro.png?size=40px + :target: https://github.com/yostashiro + :alt: yostashiro +.. |maintainer-aungkokolin1997| image:: https://github.com/aungkokolin1997.png?size=40px + :target: https://github.com/aungkokolin1997 + :alt: aungkokolin1997 + +Current `maintainers `__: + +|maintainer-yostashiro| |maintainer-aungkokolin1997| + +This module is part of the `OCA/website `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/website_form_partner_specific_user_account/__init__.py b/website_form_partner_specific_user_account/__init__.py new file mode 100644 index 0000000000..91c5580fed --- /dev/null +++ b/website_form_partner_specific_user_account/__init__.py @@ -0,0 +1,2 @@ +from . import controllers +from . import models diff --git a/website_form_partner_specific_user_account/__manifest__.py b/website_form_partner_specific_user_account/__manifest__.py new file mode 100644 index 0000000000..4b6dacc392 --- /dev/null +++ b/website_form_partner_specific_user_account/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2025 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "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, +} diff --git a/website_form_partner_specific_user_account/controllers/__init__.py b/website_form_partner_specific_user_account/controllers/__init__.py new file mode 100644 index 0000000000..12a7e529b6 --- /dev/null +++ b/website_form_partner_specific_user_account/controllers/__init__.py @@ -0,0 +1 @@ +from . import main diff --git a/website_form_partner_specific_user_account/controllers/main.py b/website_form_partner_specific_user_account/controllers/main.py new file mode 100644 index 0000000000..3c92a04575 --- /dev/null +++ b/website_form_partner_specific_user_account/controllers/main.py @@ -0,0 +1,49 @@ +# Copyright 2025 Quartile (https://www.quartile.co) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.addons.website.controllers.form import WebsiteForm + + +class WebsiteForm(WebsiteForm): + def insert_record(self, request, model, values, custom, meta=None): + website = request.website + if not website.specific_user_account: + return super().insert_record(request, model, values, custom, meta) + partner_id = values.get("partner_id") + if not partner_id: + return super().insert_record(request, model, values, custom, meta) + Partner = request.env["res.partner"].sudo() + partner = Partner.browse(partner_id) + 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") + ) + # Intended for newly created partners, but applies to any partner without website_id + if not partner.website_id: + partner.website_id = website.id + # Intended for newly created partners, but applies to any partner without company_id + if not partner.company_id and website.restrict_partner_to_company: + partner.company_id = website.company_id.id + if email and partner.website_id != website: + 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 and values.get("partner_name"): + vals = { + "email": email, + "name": values.get("partner_name"), + "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: + values["partner_id"] = website_partner.id + return super().insert_record(request, model, values, custom, meta) diff --git a/website_form_partner_specific_user_account/models/__init__.py b/website_form_partner_specific_user_account/models/__init__.py new file mode 100644 index 0000000000..bd190fa80b --- /dev/null +++ b/website_form_partner_specific_user_account/models/__init__.py @@ -0,0 +1 @@ +from . import website diff --git a/website_form_partner_specific_user_account/models/website.py b/website_form_partner_specific_user_account/models/website.py new file mode 100644 index 0000000000..f7b45dfd7b --- /dev/null +++ b/website_form_partner_specific_user_account/models/website.py @@ -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." + ) diff --git a/website_form_partner_specific_user_account/readme/CONFIGURE.md b/website_form_partner_specific_user_account/readme/CONFIGURE.md new file mode 100644 index 0000000000..6877b4dd87 --- /dev/null +++ b/website_form_partner_specific_user_account/readme/CONFIGURE.md @@ -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. diff --git a/website_form_partner_specific_user_account/readme/CONTRIBUTORS.md b/website_form_partner_specific_user_account/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..5c1d25fa27 --- /dev/null +++ b/website_form_partner_specific_user_account/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +* `Quartile `__: + + * Aung Ko Ko Lin + * Yoshi Tashiro diff --git a/website_form_partner_specific_user_account/readme/DESCRIPTION.md b/website_form_partner_specific_user_account/readme/DESCRIPTION.md new file mode 100644 index 0000000000..78d2727f87 --- /dev/null +++ b/website_form_partner_specific_user_account/readme/DESCRIPTION.md @@ -0,0 +1,12 @@ +This module is intended for use when the “Specific User Account” setting is enabled +on a website. + +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. diff --git a/website_form_partner_specific_user_account/readme/ROADMAP.md b/website_form_partner_specific_user_account/readme/ROADMAP.md new file mode 100644 index 0000000000..d6e80e1007 --- /dev/null +++ b/website_form_partner_specific_user_account/readme/ROADMAP.md @@ -0,0 +1,6 @@ +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. diff --git a/website_form_partner_specific_user_account/static/description/index.html b/website_form_partner_specific_user_account/static/description/index.html new file mode 100644 index 0000000000..33e2f0855f --- /dev/null +++ b/website_form_partner_specific_user_account/static/description/index.html @@ -0,0 +1,462 @@ + + + + + +Website Form Partner Specific User Account + + + +
+

Website Form Partner Specific User Account

+ + +

Beta License: AGPL-3 OCA/website Translate me on Weblate Try me on Runboat

+

This module is intended for use when the “Specific User Account” setting +is enabled on a website.

+

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.

+

Table of contents

+ +
+

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

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Quartile
  • +
+
+
+

Contributors

+
    +
  • Quartile <https://www.quartile.co>__:
      +
    • Aung Ko Ko Lin
    • +
    • Yoshi Tashiro
    • +
    +
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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.

+

Current maintainers:

+

yostashiro aungkokolin1997

+

This module is part of the OCA/website project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/website_form_partner_specific_user_account/tests/__init__.py b/website_form_partner_specific_user_account/tests/__init__.py new file mode 100644 index 0000000000..5f56592c45 --- /dev/null +++ b/website_form_partner_specific_user_account/tests/__init__.py @@ -0,0 +1 @@ +from . import test_website_form_partner_specific_user_account diff --git a/website_form_partner_specific_user_account/tests/test_website_form_partner_specific_user_account.py b/website_form_partner_specific_user_account/tests/test_website_form_partner_specific_user_account.py new file mode 100644 index 0000000000..01bdb2faf3 --- /dev/null +++ b/website_form_partner_specific_user_account/tests/test_website_form_partner_specific_user_account.py @@ -0,0 +1,131 @@ +# Copyright 2025 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from types import SimpleNamespace +from unittest.mock import patch + +from odoo.tests.common import TransactionCase + +from odoo.addons.website_form_partner_specific_user_account.controllers.main import ( + WebsiteForm, +) + + +class TestWebsiteFormSimple(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.company_1 = cls.env["res.company"].create({"name": "Company 1"}) + cls.company_2 = cls.env["res.company"].create({"name": "Company 2"}) + cls.website_1 = cls.env["website"].create( + { + "name": "Website 1", + "specific_user_account": True, + "restrict_partner_to_company": True, + "company_id": cls.company_1.id, + } + ) + cls.website_2 = cls.env["website"].create( + { + "name": "Website 2", + "specific_user_account": True, + "restrict_partner_to_company": False, + "company_id": cls.company_2.id, + } + ) + + def mock_insert_record(self, request, model, values, custom, meta=None): + return values + + def _req(self, website): + return SimpleNamespace(env=self.env, website=website) + + @patch( + "odoo.addons.website.controllers.form.WebsiteForm.insert_record", + new=mock_insert_record, + ) + def test_partner_website_and_company_when_restricted(self): + partner = self.env["res.partner"].create( + { + "name": "Partner", + "email": "test1@example.com", + } + ) + WebsiteForm().insert_record( + self._req(self.website_1), + "res.partner", + { + "partner_id": partner.id, + "email_from": partner.email, + }, + {}, + ) + self.assertEqual(partner.website_id, self.website_1) + self.assertEqual(partner.company_id, self.company_1) + + @patch( + "odoo.addons.website.controllers.form.WebsiteForm.insert_record", + new=mock_insert_record, + ) + def test_website_partner_with_existing_website(self): + original = self.env["res.partner"].create( + { + "name": "Original", + "email": "test2@example.com", + "website_id": self.website_1.id, + } + ) + WebsiteForm().insert_record( + self._req(self.website_2), + "res.partner", + { + "partner_id": original.id, + "email_from": original.email, + "partner_name": "Website 2 Partner", + }, + {}, + ) + website_partner = self.env["res.partner"].search( + [ + ("email", "=", original.email), + ("website_id", "=", self.website_2.id), + ], + limit=1, + ) + + self.assertTrue(website_partner) + self.assertNotEqual(website_partner, original) + self.assertFalse(website_partner.company_id) + + @patch( + "odoo.addons.website.controllers.form.WebsiteForm.insert_record", + new=mock_insert_record, + ) + def test_website_partner_with_company_when_restricted(self): + self.website_2.restrict_partner_to_company = True + original = self.env["res.partner"].create( + { + "name": "Original", + "email": "test3@example.com", + "website_id": self.website_1.id, + } + ) + WebsiteForm().insert_record( + self._req(self.website_2), + "res.partner", + { + "partner_id": original.id, + "email_from": original.email, + "partner_name": "Restricted Partner", + }, + {}, + ) + website_partner = self.env["res.partner"].search( + [ + ("email", "=", original.email), + ("website_id", "=", self.website_2.id), + ("company_id", "=", self.website_2.company_id.id), + ], + limit=1, + ) + self.assertTrue(website_partner) diff --git a/website_form_partner_specific_user_account/views/website_views.xml b/website_form_partner_specific_user_account/views/website_views.xml new file mode 100644 index 0000000000..6a809a4c78 --- /dev/null +++ b/website_form_partner_specific_user_account/views/website_views.xml @@ -0,0 +1,13 @@ + + + + website.view.inherit + website + + + + + + + +