From 699aa47b00a1a64315dbb2107b33977b9a90d67f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 1 Sep 2017 16:41:54 +0200 Subject: [PATCH] [IMP] account_payment: add invoice / transaction link Purpose of this commit is to add a link between invoices and transactions to store payment data like what is already done for sale orders. * add payment_tx_id on account.invoice model that stores the last transaction; also add the acquirer related on the tx; * add a stat button on invoice with links to all transactions linked to that invoice; * add account_invoice_id on payment.transaction model that stores the link to the invoice; * add the inverse one2many from invoice to all its transactions so that we can browse them if necessary; --- addons/account_payment/__init__.py | 2 + addons/account_payment/__manifest__.py | 2 + addons/account_payment/models/__init__.py | 5 +++ .../account_payment/models/account_invoice.py | 40 +++++++++++++++++++ addons/account_payment/models/payment.py | 10 +++++ .../views/account_invoice_views.xml | 17 ++++++++ .../account_payment/views/payment_views.xml | 13 ++++++ 7 files changed, 89 insertions(+) create mode 100644 addons/account_payment/models/__init__.py create mode 100644 addons/account_payment/models/account_invoice.py create mode 100644 addons/account_payment/models/payment.py create mode 100644 addons/account_payment/views/account_invoice_views.xml create mode 100644 addons/account_payment/views/payment_views.xml 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