From 29b13cbdd6dace7de190a979d1d899e80e5fb853 Mon Sep 17 00:00:00 2001 From: Victor Feyens Date: Thu, 26 Jan 2023 17:36:02 +0000 Subject: [PATCH] [MOV] website_sale: move payment-specific logic to `website_payment` The `website_id` field is defined in the `website_payment` but not used for anything until `website_sale` is installed. This commits moves the `_get_compatible_providers` override filtering providers based on the current website from `website_sale` to `website_payment`, where the `website_id` field is defined. Task-3084364 closes odoo/odoo#111148 Signed-off-by: Antoine Vandevenne (anv) --- .../models/payment_provider.py | 22 ++++++++++++++-- addons/website_sale/models/__init__.py | 1 - .../website_sale/models/payment_provider.py | 25 ------------------- 3 files changed, 20 insertions(+), 28 deletions(-) delete mode 100644 addons/website_sale/models/payment_provider.py diff --git a/addons/website_payment/models/payment_provider.py b/addons/website_payment/models/payment_provider.py index e55f2029256..0c3ecf2df92 100644 --- a/addons/website_payment/models/payment_provider.py +++ b/addons/website_payment/models/payment_provider.py @@ -1,6 +1,6 @@ -# coding: utf-8 +# Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import fields, models +from odoo import api, fields, models from odoo.http import request @@ -13,6 +13,24 @@ class PaymentProvider(models.Model): ondelete="restrict", ) + @api.model + def _get_compatible_providers(self, *args, website_id=None, **kwargs): + """ Override of `payment` to only return providers matching website-specific criteria. + + In addition to the base criteria, the website must either not be set or be the same as the + one provided in the kwargs. + + :param int website_id: The provided website, as a `website` id. + :return: The compatible providers. + :rtype: payment.provider + """ + providers = super()._get_compatible_providers(*args, website_id=website_id, **kwargs) + if website_id: + providers = providers.filtered( + lambda p: not p.website_id or p.website_id.id == website_id + ) + return providers + def get_base_url(self): # Give priority to url_root to handle multi-website cases if request and request.httprequest.url_root: diff --git a/addons/website_sale/models/__init__.py b/addons/website_sale/models/__init__.py index 359b67b2e33..0216bf76928 100644 --- a/addons/website_sale/models/__init__.py +++ b/addons/website_sale/models/__init__.py @@ -5,7 +5,6 @@ from . import account_move from . import crm_team from . import digest from . import ir_http -from . import payment_provider from . import product_attribute from . import product_image from . import product_pricelist diff --git a/addons/website_sale/models/payment_provider.py b/addons/website_sale/models/payment_provider.py deleted file mode 100644 index 9ea9937434f..00000000000 --- a/addons/website_sale/models/payment_provider.py +++ /dev/null @@ -1,25 +0,0 @@ -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from odoo import api, models - - -class PaymentProvider(models.Model): - _inherit = 'payment.provider' - - @api.model - def _get_compatible_providers(self, *args, website_id=None, **kwargs): - """ Override of payment to only return providers matching website-specific criteria. - - In addition to the base criteria, the website must either not be set or be the same as the - one provided in the kwargs. - - :param int website_id: The provided website, as a `website` id - :return: The compatible providers - :rtype: recordset of `payment.provider` - """ - providers = super()._get_compatible_providers(*args, website_id=website_id, **kwargs) - if website_id: - providers = providers.filtered( - lambda p: not p.website_id or p.website_id.id == website_id - ) - return providers