Debian Codegraph @

addons/pos_online_payment/models/pos_config.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 # Part of Odoo. See LICENSE file for full copyright and licensing details.
3
4 from odoo import models, api, _
5 from odoo.exceptions import ValidationError
6
7
8 class PosConfig(models.Model):
9 _inherit = 'pos.config'
10
11 @api.constrains('payment_method_ids')
12 def _check_online_payment_methods(self):
13 """ Checks the journal currency with _get_online_payment_providers(..., error_if_invalid=True)"""
14 for config in self:
15 opm_amount = 0
16 for pm in config.payment_method_ids:
17 if pm.is_online_payment:
18 opm_amount += 1
19 if opm_amount > 1:
20 raise ValidationError(_("A POS config cannot have more than one online payment method."))
21 if not pm._get_online_payment_providers(config.id, error_if_invalid=True):
22 raise ValidationError(_("To use an online payment method in a POS config, it must have at least one published payment provider supporting the currency of that POS config."))
23
24 def _get_cashier_online_payment_method(self):
25 self.ensure_one()
26 return self.payment_method_ids.filtered('is_online_payment')[:1]