43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import _, api, fields, models
|
|
|
|
|
|
class AccountPayment(models.Model):
|
|
_inherit = 'account.payment'
|
|
|
|
poynt_settlement_line_ids = fields.One2many(
|
|
'poynt.settlement.line',
|
|
'existing_payment_id',
|
|
string="Settlement Lines",
|
|
)
|
|
poynt_settlement_count = fields.Integer(
|
|
string="Settlements",
|
|
compute='_compute_poynt_settlement_count',
|
|
)
|
|
|
|
@api.depends('poynt_settlement_line_ids')
|
|
def _compute_poynt_settlement_count(self):
|
|
for payment in self:
|
|
payment.poynt_settlement_count = len(payment.poynt_settlement_line_ids)
|
|
|
|
def action_view_poynt_settlement(self):
|
|
"""Open the settlement batch linked to this payment."""
|
|
self.ensure_one()
|
|
batch_ids = self.poynt_settlement_line_ids.mapped('batch_id').ids
|
|
if len(batch_ids) == 1:
|
|
return {
|
|
'type': 'ir.actions.act_window',
|
|
'name': _("Settlement Batch"),
|
|
'res_model': 'poynt.settlement.batch',
|
|
'view_mode': 'form',
|
|
'res_id': batch_ids[0],
|
|
}
|
|
return {
|
|
'type': 'ir.actions.act_window',
|
|
'name': _("Settlement Batches"),
|
|
'res_model': 'poynt.settlement.batch',
|
|
'view_mode': 'list,form',
|
|
'domain': [('id', 'in', batch_ids)],
|
|
}
|