[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;
This commit is contained in:
Thibault Delavallée
2017-09-06 10:49:03 +02:00
parent e6120eb7d6
commit 699aa47b00
7 changed files with 89 additions and 0 deletions
+2
View File
@@ -1,2 +1,4 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import models
+2
View File
@@ -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,
@@ -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
@@ -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
+10
View File
@@ -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')
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<odoo>
<record id="account_invoice_view_form_inherit_payment" model="ir.ui.view">
<field name="name">account.invoice.view.form.inherit.payment</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='button_box']" position="inside">
<button name="action_view_transactions" type="object"
class="oe_stat_button" icon="fa-money"
attrs="{'invisible': [('payment_tx_count', '=', 0)]}">
<field name="payment_tx_count" widget="statinfo" string="Transactions"/>
</button>
</xpath>
</field>
</record>
</odoo>
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<odoo>
<record id="payment_transaction_view_form" model="ir.ui.view">
<field name="name">payment.transaction.view.form.inherit.account.payment</field>
<field name="model">payment.transaction</field>
<field name="inherit_id" ref="payment.transaction_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='acquirer_reference']" position="after">
<field name="account_invoice_id"/>
</xpath>
</field>
</record>
</odoo>