# -*- coding: utf-8 -*- ############################################################################### # # Cybrosys Technologies Pvt. Ltd. # # Copyright (C) 2025-TODAY Cybrosys Technologies() # Author: Afra K (odoo@cybrosys.com) # # You can modify it under the terms of the GNU AFFERO # GENERAL PUBLIC LICENSE (AGPL v3), Version 3. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. # # You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE # (AGPL v3) along with this program. # If not, see . # ############################################################################### from odoo import _, api, fields, models from odoo.exceptions import UserError class PaymentProvider(models.Model): """ Inherits the payment provider to add the credit payment """ _inherit = 'payment.provider' code = fields.Selection(selection_add=[('credit_pay', 'Credit Payment')], ondelete={'credit_pay': 'set default'}) # === COMPUTE METHODS ===# @api.depends('code') def _compute_view_configuration_fields(self): """ Override of payment to hide the credentials page. :return: None """ super()._compute_view_configuration_fields() self.filtered( lambda p: p.code == 'credit_pay').show_credentials_page = False def _compute_feature_support_fields(self): """ Override of `payment` to enable additional features. """ super()._compute_feature_support_fields() self.filtered(lambda p: p.code == 'credit_pay').update({ 'support_manual_capture': 'partial', 'support_refund': 'partial', 'support_tokenization': True, }) # === CONSTRAINT METHODS ===# @api.constrains('state', 'code') def _check_provider_state(self): if self.filtered(lambda p: p.code == 'credit_pay' and p.state not in ( 'test', 'disabled')): raise UserError(_("Demo providers should never be enabled."))