| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 3 |
|
| 4 |
from odoo import models, fields, api |
| 5 |
|
| 6 |
|
| 7 |
class AccountPayment(models.Model): |
| 8 |
_inherit = 'account.payment' |
| 9 |
|
| 10 |
pos_payment_method_id = fields.Many2one('pos.payment.method', "POS Payment Method") |
| 11 |
force_outstanding_account_id = fields.Many2one("account.account", "Forced Outstanding Account", check_company=True) |
| 12 |
pos_session_id = fields.Many2one('pos.session', "POS Session", index='btree_not_null') |
| 13 |
|
| 14 |
@api.depends("force_outstanding_account_id") |
| 15 |
def _compute_outstanding_account_id(self): |
| 16 |
"""When force_outstanding_account_id is set, we use it as the outstanding_account_id.""" |
| 17 |
super()._compute_outstanding_account_id() |
| 18 |
for payment in self: |
| 19 |
if payment.force_outstanding_account_id: |
| 20 |
payment.outstanding_account_id = payment.force_outstanding_account_id |
| 21 |
|
| 22 |
def _get_payment_method_codes_to_exclude(self): |
| 23 |
res = super()._get_payment_method_codes_to_exclude() |
| 24 |
|
| 25 |
# Sepa Credit Transfer is an outgoing payment method. It requires a partner and bank |
| 26 |
# account. In the context of PoS orders, you can make refunds that are not linked to |
| 27 |
# a specific customer. We ensure that account.payment are not created using the sepa_ct |
| 28 |
# account.payment.method.line. If not, closing the session would not be possible unless |
| 29 |
# having an account.payment.method.line with a smaller sequence than sepa_ct. |
| 30 |
account_sepa = self.env['ir.module.module'].search([('name', '=', 'account_iso20022')]) |
| 31 |
if account_sepa.state == 'installed': |
| 32 |
sepa_ct = self.env.ref('account_iso20022.account_payment_method_sepa_ct', raise_if_not_found=False) |
| 33 |
if sepa_ct and 'pos_payment' in self.env.context and sepa_ct.code not in res: |
| 34 |
res.append(sepa_ct.code) |
| 35 |
return res |