summaryrefslogtreecommitdiff
path: root/addons/account_payment/models
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2017-09-01 16:41:54 +0200
committerThibault Delavallée <tde@odoo.com>2017-09-06 10:49:03 +0200
commit699aa47b00a1a64315dbb2107b33977b9a90d67f (patch)
tree2df2c1f220354e911b7a2edbf32331383e329fba /addons/account_payment/models
parente6120eb7d6a8ef0fc0f88b3ccd001b722bee73d3 (diff)
[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;
Diffstat (limited to 'addons/account_payment/models')
-rw-r--r--addons/account_payment/models/__init__.py5
-rw-r--r--addons/account_payment/models/account_invoice.py40
-rw-r--r--addons/account_payment/models/payment.py10
3 files changed, 55 insertions, 0 deletions
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')