diff --git a/addons/account_payment/__init__.py b/addons/account_payment/__init__.py
index 67dee8c60db..e9917144f69 100644
--- a/addons/account_payment/__init__.py
+++ b/addons/account_payment/__init__.py
@@ -1,2 +1,4 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from . import models
\ No newline at end of file
diff --git a/addons/account_payment/__manifest__.py b/addons/account_payment/__manifest__.py
index e886797b8b2..9f4e4a4ea03 100644
--- a/addons/account_payment/__manifest__.py
+++ b/addons/account_payment/__manifest__.py
@@ -14,6 +14,8 @@ enable payment.
""",
'depends': ['payment', 'account'],
'data': [
+ 'views/account_invoice_views.xml',
+ 'views/payment_views.xml',
'views/account_portal_templates.xml',
],
'installable': True,
diff --git a/addons/account_payment/models/__init__.py b/addons/account_payment/models/__init__.py
new file mode 100644
index 00000000000..8d8e41dece0
--- /dev/null
+++ b/addons/account_payment/models/__init__.py
@@ -0,0 +1,5 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from . import account_invoice
+from . import payment
diff --git a/addons/account_payment/models/account_invoice.py b/addons/account_payment/models/account_invoice.py
new file mode 100644
index 00000000000..12d377a537d
--- /dev/null
+++ b/addons/account_payment/models/account_invoice.py
@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import fields, models, _
+
+
+class AccountInvoice(models.Model):
+ _inherit = 'account.invoice'
+
+ payment_tx_ids = fields.One2many('payment.transaction', 'account_invoice_id', string='Transactions')
+ payment_tx_id = fields.Many2one('payment.transaction', string='Last Transaction', copy=False)
+ payment_acquirer_id = fields.Many2one(
+ 'payment.acquirer', string='Payment Acquirer',
+ related='payment_tx_id.acquirer_id', store=True)
+ payment_tx_count = fields.Integer(string="Number of payment transactions", compute='_compute_payment_tx_count')
+
+ def _compute_payment_tx_count(self):
+ tx_data = self.env['payment.transaction'].read_group(
+ [('account_invoice_id', 'in', self.ids)],
+ ['account_invoice_id'], ['account_invoice_id']
+ )
+ mapped_data = dict([(m['account_invoice_id'][0], m['account_invoice_id_count']) for m in tx_data])
+ for invoice in self:
+ invoice.payment_tx_count = mapped_data.get(invoice.id, 0)
+
+ def action_view_transactions(self):
+ action = {
+ 'name': _('Payment Transactions'),
+ 'type': 'ir.actions.act_window',
+ 'res_model': 'payment.transaction',
+ 'target': 'current',
+ }
+ tx = self.env['payment.transaction'].search([('account_invoice_id', 'in', self.ids)])
+ if len(tx) == 1:
+ action['res_id'] = tx.ids[0]
+ action['view_mode'] = 'form'
+ else:
+ action['view_mode'] = 'tree,form'
+ action['domain'] = [('account_invoice_id', 'in', self.ids)]
+ return action
diff --git a/addons/account_payment/models/payment.py b/addons/account_payment/models/payment.py
new file mode 100644
index 00000000000..7fa7899be93
--- /dev/null
+++ b/addons/account_payment/models/payment.py
@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import fields, models
+
+
+class PaymentTransaction(models.Model):
+ _inherit = 'payment.transaction'
+
+ account_invoice_id = fields.Many2one('account.invoice', string='Invoice')
diff --git a/addons/account_payment/views/account_invoice_views.xml b/addons/account_payment/views/account_invoice_views.xml
new file mode 100644
index 00000000000..0eaf313caba
--- /dev/null
+++ b/addons/account_payment/views/account_invoice_views.xml
@@ -0,0 +1,17 @@
+
+
+
+ account.invoice.view.form.inherit.payment
+ account.invoice
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/addons/account_payment/views/payment_views.xml b/addons/account_payment/views/payment_views.xml
new file mode 100644
index 00000000000..e83f69909fa
--- /dev/null
+++ b/addons/account_payment/views/payment_views.xml
@@ -0,0 +1,13 @@
+
+
+
+ payment.transaction.view.form.inherit.account.payment
+ payment.transaction
+
+
+
+
+
+
+
+
\ No newline at end of file