diff --git a/setup/website_sale_partner_restrict_payment_acquirer/odoo/addons/website_sale_partner_restrict_payment_acquirer b/setup/website_sale_partner_restrict_payment_acquirer/odoo/addons/website_sale_partner_restrict_payment_acquirer new file mode 120000 index 0000000000..1f909d413f --- /dev/null +++ b/setup/website_sale_partner_restrict_payment_acquirer/odoo/addons/website_sale_partner_restrict_payment_acquirer @@ -0,0 +1 @@ +../../../../website_sale_partner_restrict_payment_acquirer \ No newline at end of file diff --git a/setup/website_sale_partner_restrict_payment_acquirer/setup.py b/setup/website_sale_partner_restrict_payment_acquirer/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/website_sale_partner_restrict_payment_acquirer/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/website_sale_partner_restrict_payment_acquirer/README.rst b/website_sale_partner_restrict_payment_acquirer/README.rst new file mode 100644 index 0000000000..361733b1b1 --- /dev/null +++ b/website_sale_partner_restrict_payment_acquirer/README.rst @@ -0,0 +1,102 @@ +============================================== +Website Sale Partner Restrict Payment Acquirer +============================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:cbb26db9d767bb456ca0a66b7c079062cba22baa86c8aa19778022853f820434 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fe--commerce-lightgray.png?logo=github + :target: https://github.com/OCA/e-commerce/tree/15.0/website_sale_partner_restrict_payment_acquirer + :alt: OCA/e-commerce +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/e-commerce-15-0/e-commerce-15-0-website_sale_partner_restrict_payment_acquirer + :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/e-commerce&target_branch=15.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the functionality of `partner_restrict_payment_acquirer` to restrict payment acquirers for a partner during the checkout process in e-commerce. Only the selected acquirers will be available for online payments. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Open the partner form and go to the `Sales & Purchases` tab. Add payment acquirers in the `Allowed Acquirers` field. + +Note: Leaving this field empty will remove restrictions and allow the selection of any acquirer. + +![Partner Form Allowed Acquirers](static/description/partner_form_allowed_acquirers.png) + +When the partner proceeds to checkout in the portal, only the allowed acquirers will be available for payment. + +![Checkout Acquirers](static/description/checkout_acquirers.png) + +For not logged-in users, if you want to restrict their allowed acquirers, you need to edit the `Allowed Acquirers` field for the `Public user` partner (`base.public_user`). + +![Public User](static/description/public_user.png) + +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 +~~~~~~~ + +* APSL-Nagarro + +Contributors +~~~~~~~~~~~~ + +* `APSL-Nagarro `_: + * Patryk Pyczko + +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-ppyczko| image:: https://github.com/ppyczko.png?size=40px + :target: https://github.com/ppyczko + :alt: ppyczko + +Current `maintainer `__: + +|maintainer-ppyczko| + +This module is part of the `OCA/e-commerce `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/website_sale_partner_restrict_payment_acquirer/__init__.py b/website_sale_partner_restrict_payment_acquirer/__init__.py new file mode 100644 index 0000000000..31660d6a96 --- /dev/null +++ b/website_sale_partner_restrict_payment_acquirer/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/website_sale_partner_restrict_payment_acquirer/__manifest__.py b/website_sale_partner_restrict_payment_acquirer/__manifest__.py new file mode 100644 index 0000000000..615a71de67 --- /dev/null +++ b/website_sale_partner_restrict_payment_acquirer/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2025 Patryk Pyczko (APSL-Nagarro) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Website Sale Partner Restrict Payment Acquirer", + "version": "15.0.1.0.0", + "summary": "Restrict payment acquirers for partners during the " + "checkout process on eCommerce.", + "category": "Website", + "website": "https://github.com/OCA/e-commerce", + "author": "APSL-Nagarro, Odoo Community Association (OCA)", + "maintainers": ["ppyczko"], + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": ["partner_restrict_payment_acquirer", "website_sale"], +} diff --git a/website_sale_partner_restrict_payment_acquirer/i18n/ca.po b/website_sale_partner_restrict_payment_acquirer/i18n/ca.po new file mode 100644 index 0000000000..b99a7f923d --- /dev/null +++ b/website_sale_partner_restrict_payment_acquirer/i18n/ca.po @@ -0,0 +1,21 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_sale_partner_restrict_payment_acquirer +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-02-06 16:51+0000\n" +"PO-Revision-Date: 2025-02-06 16:51+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: website_sale_partner_restrict_payment_acquirer +#: model:ir.model,name:website_sale_partner_restrict_payment_acquirer.model_payment_acquirer +msgid "Payment Acquirer" +msgstr "Mètode de pagament" diff --git a/website_sale_partner_restrict_payment_acquirer/i18n/es.po b/website_sale_partner_restrict_payment_acquirer/i18n/es.po new file mode 100644 index 0000000000..9e308c6c79 --- /dev/null +++ b/website_sale_partner_restrict_payment_acquirer/i18n/es.po @@ -0,0 +1,21 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_sale_partner_restrict_payment_acquirer +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-02-06 16:51+0000\n" +"PO-Revision-Date: 2025-02-06 16:51+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: website_sale_partner_restrict_payment_acquirer +#: model:ir.model,name:website_sale_partner_restrict_payment_acquirer.model_payment_acquirer +msgid "Payment Acquirer" +msgstr "Método de Pago" diff --git a/website_sale_partner_restrict_payment_acquirer/i18n/website_sale_partner_restrict_payment_acquirer.pot b/website_sale_partner_restrict_payment_acquirer/i18n/website_sale_partner_restrict_payment_acquirer.pot new file mode 100644 index 0000000000..7b06638c1c --- /dev/null +++ b/website_sale_partner_restrict_payment_acquirer/i18n/website_sale_partner_restrict_payment_acquirer.pot @@ -0,0 +1,21 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_sale_partner_restrict_payment_acquirer +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-02-06 16:51+0000\n" +"PO-Revision-Date: 2025-02-06 16:51+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: website_sale_partner_restrict_payment_acquirer +#: model:ir.model,name:website_sale_partner_restrict_payment_acquirer.model_payment_acquirer +msgid "Payment Acquirer" +msgstr "" diff --git a/website_sale_partner_restrict_payment_acquirer/models/__init__.py b/website_sale_partner_restrict_payment_acquirer/models/__init__.py new file mode 100644 index 0000000000..7c39181705 --- /dev/null +++ b/website_sale_partner_restrict_payment_acquirer/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import payment_acquirer diff --git a/website_sale_partner_restrict_payment_acquirer/models/payment_acquirer.py b/website_sale_partner_restrict_payment_acquirer/models/payment_acquirer.py new file mode 100644 index 0000000000..56110b9424 --- /dev/null +++ b/website_sale_partner_restrict_payment_acquirer/models/payment_acquirer.py @@ -0,0 +1,31 @@ +# Copyright 2025 Patryk Pyczko (APSL-Nagarro) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class PaymentAcquirer(models.Model): + _inherit = "payment.acquirer" + + @api.model + def _get_compatible_acquirers(self, *args, website_id=None, **kwargs): + """ + Override to filter acquirers based on the partner's allowed acquirers. + + This method first fetches acquirers based on general criteria, then + filters them by the partner's allowed acquirers list. + + :param int website_id: The provided website, as a `website` id + :return: The filtered list of compatible acquirers. + :rtype: recordset of `payment.acquirer` + """ + acquirers = super()._get_compatible_acquirers( + *args, website_id=website_id, **kwargs + ) + + allowed_acquirers = self.env.user.partner_id.allowed_acquirer_ids + return ( + acquirers.filtered(lambda acq: acq in allowed_acquirers) + if allowed_acquirers + else acquirers + ) diff --git a/website_sale_partner_restrict_payment_acquirer/readme/CONTRIBUTORS.rst b/website_sale_partner_restrict_payment_acquirer/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..d9d047c2d6 --- /dev/null +++ b/website_sale_partner_restrict_payment_acquirer/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* `APSL-Nagarro `_: + * Patryk Pyczko diff --git a/website_sale_partner_restrict_payment_acquirer/readme/DESCRIPTION.rst b/website_sale_partner_restrict_payment_acquirer/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..8128274163 --- /dev/null +++ b/website_sale_partner_restrict_payment_acquirer/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module extends the functionality of `partner_restrict_payment_acquirer` to restrict payment acquirers for a partner during the checkout process in e-commerce. Only the selected acquirers will be available for online payments. diff --git a/website_sale_partner_restrict_payment_acquirer/readme/USAGE.rst b/website_sale_partner_restrict_payment_acquirer/readme/USAGE.rst new file mode 100644 index 0000000000..88e6b1dfa8 --- /dev/null +++ b/website_sale_partner_restrict_payment_acquirer/readme/USAGE.rst @@ -0,0 +1,13 @@ +Open the partner form and go to the `Sales & Purchases` tab. Add payment acquirers in the `Allowed Acquirers` field. + +Note: Leaving this field empty will remove restrictions and allow the selection of any acquirer. + +![Partner Form Allowed Acquirers](static/description/partner_form_allowed_acquirers.png) + +When the partner proceeds to checkout in the portal, only the allowed acquirers will be available for payment. + +![Checkout Acquirers](static/description/checkout_acquirers.png) + +For not logged-in users, if you want to restrict their allowed acquirers, you need to edit the `Allowed Acquirers` field for the `Public user` partner (`base.public_user`). + +![Public User](static/description/public_user.png) diff --git a/website_sale_partner_restrict_payment_acquirer/static/description/checkout_acquirers.png b/website_sale_partner_restrict_payment_acquirer/static/description/checkout_acquirers.png new file mode 100644 index 0000000000..6adc28f438 Binary files /dev/null and b/website_sale_partner_restrict_payment_acquirer/static/description/checkout_acquirers.png differ diff --git a/website_sale_partner_restrict_payment_acquirer/static/description/icon.png b/website_sale_partner_restrict_payment_acquirer/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/website_sale_partner_restrict_payment_acquirer/static/description/icon.png differ diff --git a/website_sale_partner_restrict_payment_acquirer/static/description/index.html b/website_sale_partner_restrict_payment_acquirer/static/description/index.html new file mode 100644 index 0000000000..1a0fe5b4bf --- /dev/null +++ b/website_sale_partner_restrict_payment_acquirer/static/description/index.html @@ -0,0 +1,437 @@ + + + + + +Website Sale Partner Restrict Payment Acquirer + + + +
+

Website Sale Partner Restrict Payment Acquirer

+ + +

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

+

This module extends the functionality of partner_restrict_payment_acquirer to restrict payment acquirers for a partner during the checkout process in e-commerce. Only the selected acquirers will be available for online payments.

+

Table of contents

+ +
+

Usage

+

Open the partner form and go to the Sales & Purchases tab. Add payment acquirers in the Allowed Acquirers field.

+

Note: Leaving this field empty will remove restrictions and allow the selection of any acquirer.

+

![Partner Form Allowed Acquirers](static/description/partner_form_allowed_acquirers.png)

+

When the partner proceeds to checkout in the portal, only the allowed acquirers will be available for payment.

+

![Checkout Acquirers](static/description/checkout_acquirers.png)

+

For not logged-in users, if you want to restrict their allowed acquirers, you need to edit the Allowed Acquirers field for the Public user partner (base.public_user).

+

![Public User](static/description/public_user.png)

+
+
+

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

+
    +
  • APSL-Nagarro
  • +
+
+
+

Contributors

+ +
+
+

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 maintainer:

+

ppyczko

+

This module is part of the OCA/e-commerce project on GitHub.

+

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

+
+
+
+ + diff --git a/website_sale_partner_restrict_payment_acquirer/static/description/partner_form_allowed_acquirers.png b/website_sale_partner_restrict_payment_acquirer/static/description/partner_form_allowed_acquirers.png new file mode 100644 index 0000000000..35e3fd9d4a Binary files /dev/null and b/website_sale_partner_restrict_payment_acquirer/static/description/partner_form_allowed_acquirers.png differ diff --git a/website_sale_partner_restrict_payment_acquirer/static/description/public_user.png b/website_sale_partner_restrict_payment_acquirer/static/description/public_user.png new file mode 100644 index 0000000000..6fb04b05c6 Binary files /dev/null and b/website_sale_partner_restrict_payment_acquirer/static/description/public_user.png differ diff --git a/website_sale_partner_restrict_payment_acquirer/tests/__init__.py b/website_sale_partner_restrict_payment_acquirer/tests/__init__.py new file mode 100644 index 0000000000..c712587f41 --- /dev/null +++ b/website_sale_partner_restrict_payment_acquirer/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_payment_acquirer diff --git a/website_sale_partner_restrict_payment_acquirer/tests/test_payment_acquirer.py b/website_sale_partner_restrict_payment_acquirer/tests/test_payment_acquirer.py new file mode 100644 index 0000000000..a8acf1a9c8 --- /dev/null +++ b/website_sale_partner_restrict_payment_acquirer/tests/test_payment_acquirer.py @@ -0,0 +1,40 @@ +# Copyright 2025 Patryk Pyczko (APSL-Nagarro) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests import TransactionCase, tagged + + +@tagged("post_install", "-at_install") +class TestPaymentAcquirer(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.res_partner_gemini = cls.env.ref("base.res_partner_3") + cls.acquirer_obj = cls.env["payment.acquirer"] + cls.acquirers_list = cls.acquirer_obj.search( + [("state", "in", ["enabled", "test"])] + ) + cls.wire_transfer = cls.env.ref("payment.payment_acquirer_transfer") + cls.website = cls.env.ref("website.default_website") + cls.company = cls.env.ref("base.main_company") + + def _get_compatible_acquirers(self, partner): + self.env.user.partner_id = partner + return self.acquirer_obj._get_compatible_acquirers( + company_id=self.company.id, + partner_id=partner.id, + website_id=self.website.id, + ) + + def test_get_compatible_acquirers_no_restriction(self): + acquirers = self._get_compatible_acquirers(self.res_partner_gemini) + self.assertEqual(acquirers, self.acquirers_list) + + def test_get_compatible_acquirers_with_partner_restriction_order(self): + self.res_partner_gemini.write( + {"allowed_acquirer_ids": [(4, self.wire_transfer.id)]} + ) + acquirers = self._get_compatible_acquirers( + self.res_partner_gemini, + ) + self.assertEqual(acquirers, self.wire_transfer)