diff options
| author | Thibault Delavallée <tde@odoo.com> | 2017-09-01 16:41:54 +0200 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2017-09-06 10:49:03 +0200 |
| commit | 699aa47b00a1a64315dbb2107b33977b9a90d67f (patch) | |
| tree | 2df2c1f220354e911b7a2edbf32331383e329fba /addons | |
| parent | e6120eb7d6a8ef0fc0f88b3ccd001b722bee73d3 (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')
| -rw-r--r-- | addons/account_payment/__init__.py | 2 | ||||
| -rw-r--r-- | addons/account_payment/__manifest__.py | 2 | ||||
| -rw-r--r-- | addons/account_payment/models/__init__.py | 5 | ||||
| -rw-r--r-- | addons/account_payment/models/account_invoice.py | 40 | ||||
| -rw-r--r-- | addons/account_payment/models/payment.py | 10 | ||||
| -rw-r--r-- | addons/account_payment/views/account_invoice_views.xml | 17 | ||||
| -rw-r--r-- | addons/account_payment/views/payment_views.xml | 13 |
7 files changed, 89 insertions, 0 deletions
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 @@ +<?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>
\ 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 @@ +<?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>
\ No newline at end of file |
