|
@ -0,0 +1,41 @@ |
|
|
|
|
|
import logging |
|
|
|
|
|
from odoo import models, fields, api, _ |
|
|
|
|
|
|
|
|
|
|
|
_logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PaymentProvider(models.Model): |
|
|
|
|
|
_inherit = "payment.provider" |
|
|
|
|
|
|
|
|
|
|
|
forbidden_category_ids = fields.Many2many( |
|
|
|
|
|
comodel_name="product.category", |
|
|
|
|
|
column1="provider_id", |
|
|
|
|
|
column2="category_id", |
|
|
|
|
|
relation="forbidden_category_provider_rel", |
|
|
|
|
|
string="Forbidden categories", |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
@api.model |
|
|
|
|
|
def _get_compatible_providers( |
|
|
|
|
|
self, *args, sale_order_id=None, website_id=None, **kwargs |
|
|
|
|
|
): |
|
|
|
|
|
"""Override of payment to exclude forbidden providers set ont order products categories. |
|
|
|
|
|
|
|
|
|
|
|
:param int sale_order_id: The sale order to be paid, if any, as a `sale.order` id |
|
|
|
|
|
:param int website_id: The provided website, as a `website` id |
|
|
|
|
|
:return: The compatible providers |
|
|
|
|
|
:rtype: recordset of `payment.provider` |
|
|
|
|
|
""" |
|
|
|
|
|
compatible_providers = super()._get_compatible_providers( |
|
|
|
|
|
*args, sale_order_id=sale_order_id, website_id=website_id, **kwargs |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
# Get order if set int the args |
|
|
|
|
|
order = self.env["sale.order"].browse(sale_order_id).exists() |
|
|
|
|
|
# If order exists, remove forbidden providers from the list |
|
|
|
|
|
if order: |
|
|
|
|
|
compatible_providers -= order.order_line.mapped( |
|
|
|
|
|
"product_id.categ_id.forbidden_provider_ids" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
return compatible_providers |