diff --git a/payment_partner/README.rst b/payment_partner/README.rst new file mode 100644 index 000000000000..b52532282bb0 --- /dev/null +++ b/payment_partner/README.rst @@ -0,0 +1,88 @@ +=============== +Payment Partner +=============== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:ffdcc5c57f3da52d2c758f47ad34396913d88fb9fd831d4ba491b1f7a2b3101d + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Faccount--payment-lightgray.png?logo=github + :target: https://github.com/OCA/account-payment/tree/16.0/payment_partner + :alt: OCA/account-payment +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-payment-16-0/account-payment-16-0-payment_partner + :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/account-payment&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to filter payment providers by partner. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +1. Access the Payment Providers page +2. Unset the is global selector +3. Access the partners and select the specific non global payment + providers + +After this, we will be able to select this provider for the partner. + +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 +------- + +* Dixmit + +Contributors +------------ + +- `Dixmit `__: + + - Enric Tobella + +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. + +This module is part of the `OCA/account-payment `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/payment_partner/__init__.py b/payment_partner/__init__.py new file mode 100644 index 000000000000..0650744f6bc6 --- /dev/null +++ b/payment_partner/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/payment_partner/__manifest__.py b/payment_partner/__manifest__.py new file mode 100644 index 000000000000..4051f63d1d41 --- /dev/null +++ b/payment_partner/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2024 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Payment Partner", + "summary": """Filter Payments by Partner""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "Dixmit,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/account-payment", + "depends": ["payment"], + "data": [ + "views/payment_provider.xml", + ], + "demo": [], +} diff --git a/payment_partner/models/__init__.py b/payment_partner/models/__init__.py new file mode 100644 index 000000000000..7070c03b0059 --- /dev/null +++ b/payment_partner/models/__init__.py @@ -0,0 +1 @@ +from . import payment_provider diff --git a/payment_partner/models/payment_provider.py b/payment_partner/models/payment_provider.py new file mode 100644 index 000000000000..fb1baa27520a --- /dev/null +++ b/payment_partner/models/payment_provider.py @@ -0,0 +1,18 @@ +# Copyright 2024 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class PaymentProvider(models.Model): + _inherit = "payment.provider" + + filter_mode = fields.Selection([('global', 'Global'), ('include', 'Include'), ('exclude', 'Exclude')], default='global') + partner_ids = fields.Many2many("res.partner") + + @api.model + def _get_compatible_providers(self, company_id, partner_id, *args, **kwargs): + result = super()._get_compatible_providers( + company_id, partner_id, *args, **kwargs + ) + return result.filtered(lambda r: not r.filter_mode or r.filter_mode == "global" or (r.filter_mode == "include" and partner_id in r.partner_ids.ids) or (r.filter_mode == "exclude" and partner_id not in r.partner_ids.ids)) diff --git a/payment_partner/readme/CONTRIBUTORS.md b/payment_partner/readme/CONTRIBUTORS.md new file mode 100644 index 000000000000..20d686ba8376 --- /dev/null +++ b/payment_partner/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [Dixmit](https://www.dixmit.com): + - Enric Tobella diff --git a/payment_partner/readme/DESCRIPTION.md b/payment_partner/readme/DESCRIPTION.md new file mode 100644 index 000000000000..ddc593374aa0 --- /dev/null +++ b/payment_partner/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module allows to filter payment providers by partner. diff --git a/payment_partner/readme/USAGE.md b/payment_partner/readme/USAGE.md new file mode 100644 index 000000000000..71638da4c21b --- /dev/null +++ b/payment_partner/readme/USAGE.md @@ -0,0 +1,5 @@ +1. Access the Payment Providers page +2. Unset the is global selector +3. Access the partners and select the specific non global payment providers + +After this, we will be able to select this provider for the partner. diff --git a/payment_partner/static/description/icon.png b/payment_partner/static/description/icon.png new file mode 100644 index 000000000000..3a0328b516c4 Binary files /dev/null and b/payment_partner/static/description/icon.png differ diff --git a/payment_partner/static/description/index.html b/payment_partner/static/description/index.html new file mode 100644 index 000000000000..fdb2d2d11921 --- /dev/null +++ b/payment_partner/static/description/index.html @@ -0,0 +1,437 @@ + + + + + +Payment Partner + + + +
+

Payment Partner

+ + +

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

+

This module allows to filter payment providers by partner.

+

Table of contents

+ +
+

Usage

+
    +
  1. Access the Payment Providers page
  2. +
  3. Unset the is global selector
  4. +
  5. Access the partners and select the specific non global payment +providers
  6. +
+

After this, we will be able to select this provider for the partner.

+
+
+

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

+
    +
  • Dixmit
  • +
+
+
+

Contributors

+
    +
  • Dixmit:
      +
    • Enric Tobella
    • +
    +
  • +
+
+
+

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.

+

This module is part of the OCA/account-payment project on GitHub.

+

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

+
+
+
+ + diff --git a/payment_partner/tests/__init__.py b/payment_partner/tests/__init__.py new file mode 100644 index 000000000000..8c9f18e5992e --- /dev/null +++ b/payment_partner/tests/__init__.py @@ -0,0 +1 @@ +from . import test_payment_partner diff --git a/payment_partner/tests/test_payment_partner.py b/payment_partner/tests/test_payment_partner.py new file mode 100644 index 000000000000..8363199cd625 --- /dev/null +++ b/payment_partner/tests/test_payment_partner.py @@ -0,0 +1,76 @@ +# Copyright 2024 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestPaymentPartner(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.partner = cls.env["res.partner"].create({"name": "Test Partner"}) + cls.payment_provider_none = cls.env["payment.provider"].create( + { + "name": "Dummy Provider", + "code": "none", + "state": "test", + "is_published": True, + "allow_tokenization": True, + "filter_mode": False, + } + ) + cls.payment_provider_global = cls.env["payment.provider"].create( + { + "name": "Dummy Provider", + "code": "none", + "state": "test", + "is_published": True, + "allow_tokenization": True, + "filter_mode": "global", + } + ) + cls.payment_provider_include = cls.env["payment.provider"].create( + { + "name": "Dummy Provider", + "code": "none", + "state": "test", + "is_published": True, + "allow_tokenization": True, + "filter_mode": "include", + } + ) + cls.payment_provider_exclude = cls.env["payment.provider"].create( + { + "name": "Dummy Provider", + "code": "none", + "state": "test", + "is_published": True, + "allow_tokenization": True, + "filter_mode": "exclude", + } + ) + + def test_partner(self): + providers = self.env["payment.provider"]._get_compatible_providers( + self.env.company.id, self.partner.id, 5 + ) + self.assertNotIn(self.payment_provider_include, providers) + self.assertIn(self.payment_provider_exclude, providers) + self.assertIn(self.payment_provider_global, providers) + self.assertIn(self.payment_provider_none, providers) + self.payment_provider_include.partner_ids = self.partner + providers = self.env["payment.provider"]._get_compatible_providers( + self.env.company.id, self.partner.id, 5 + ) + self.assertIn(self.payment_provider_include, providers) + self.assertIn(self.payment_provider_exclude, providers) + self.assertIn(self.payment_provider_global, providers) + self.assertIn(self.payment_provider_none, providers) + self.payment_provider_exclude.partner_ids = self.partner + providers = self.env["payment.provider"]._get_compatible_providers( + self.env.company.id, self.partner.id, 5 + ) + self.assertIn(self.payment_provider_include, providers) + self.assertNotIn(self.payment_provider_exclude, providers) + self.assertIn(self.payment_provider_global, providers) + self.assertIn(self.payment_provider_none, providers) diff --git a/payment_partner/views/payment_provider.xml b/payment_partner/views/payment_provider.xml new file mode 100644 index 000000000000..6eb6108688dd --- /dev/null +++ b/payment_partner/views/payment_provider.xml @@ -0,0 +1,27 @@ + + + + + + payment.provider + + + + + + + + + + + + + + + + diff --git a/setup/payment_partner/odoo/addons/payment_partner b/setup/payment_partner/odoo/addons/payment_partner new file mode 120000 index 000000000000..2e5db75ff93a --- /dev/null +++ b/setup/payment_partner/odoo/addons/payment_partner @@ -0,0 +1 @@ +../../../../payment_partner \ No newline at end of file diff --git a/setup/payment_partner/setup.py b/setup/payment_partner/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/payment_partner/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)