[IMP] account_payment: hide pay button when paid
Hide the 'Pay Now' button for invoices which transactions total amount equals their total amount. When the total amount of all transactions related to the invoice is equal to or greater than the total amount of said invoice, the 'Pay Now' button should no longer be displayed. task-2527323 closes odoo/odoo#95262 X-original-commit: de81225d39e7951ea9a63e24bab3a0138a6942e3 Signed-off-by: Achraf <abz@odoo.com>
This commit is contained in:
committed by
Achraf (abz)
parent
5d8fcdf492
commit
b5dab9b119
@@ -38,7 +38,7 @@
|
||||
<th>Invoice #</th>
|
||||
<th>Invoice Date</th>
|
||||
<th class='d-none d-md-table-cell'>Due Date</th>
|
||||
<th class="text-center">Status<th/>
|
||||
<th class="text-center">Status</th>
|
||||
<th class="text-right">Amount Due</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -53,7 +53,7 @@
|
||||
</td>
|
||||
<td><span t-field="invoice.invoice_date"/></td>
|
||||
<td class='d-none d-md-table-cell'><span t-field="invoice.invoice_date_due"/></td>
|
||||
<td class="tx_status">
|
||||
<td class="tx_status text-center">
|
||||
<t t-if="invoice.state == 'posted' and invoice.payment_state not in ('in_payment', 'paid', 'reversed')">
|
||||
<span class="badge badge-pill badge-info"><i class="fa fa-fw fa-clock-o" aria-label="Opened" title="Opened" role="img"></i><span class="d-none d-md-inline"> Waiting for Payment</span></span>
|
||||
</t>
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<odoo>
|
||||
<template id="portal_my_invoices_payment" name="Payment on My Invoices" inherit_id="account.portal_my_invoices">
|
||||
<xpath expr="//t[@t-call='portal.portal_table']/thead/tr/th[last()]" position="before">
|
||||
<th><th/>
|
||||
<th></th>
|
||||
</xpath>
|
||||
<xpath expr="//t[@t-foreach='invoices']/tr/td[last()]" position="before">
|
||||
<td class="text-center">
|
||||
<t t-set="tx_ids" t-value="invoice.transaction_ids.filtered(lambda tx: tx.state in ('pending', 'authorized', 'done'))"/>
|
||||
<t t-set="pending_manual_txs" t-value="tx_ids.filtered(lambda tx: tx.state == 'pending' and tx.provider in ('none', 'transfer'))"/>
|
||||
<a t-if="invoice.state == 'posted' and invoice.payment_state in ('not_paid', 'partial') and invoice.amount_total and invoice.move_type == 'out_invoice' and (pending_manual_txs or not tx_ids or invoice.amount_residual)"
|
||||
<a t-if="invoice.state == 'posted' and invoice.payment_state in ('not_paid', 'partial') and invoice.amount_total and invoice.move_type == 'out_invoice' and (pending_manual_txs or not tx_ids or invoice.amount_paid < invoice.amount_total)"
|
||||
t-att-href="invoice.get_portal_url(anchor='portal_pay')" title="Pay Now" aria-label="Pay now" class="btn btn-sm btn-primary" role="button">
|
||||
<i class="fa fa-arrow-circle-right"/><span class='d-none d-md-inline'> Pay Now</span>
|
||||
</a>
|
||||
@@ -67,7 +67,7 @@
|
||||
<t t-set="tx_ids" t-value="invoice.transaction_ids.filtered(lambda tx: tx.state in ('pending', 'authorized', 'done'))"/>
|
||||
<t t-set="pending_manual_txs" t-value="tx_ids.filtered(lambda tx: tx.state == 'pending' and tx.provider in ('none', 'transfer'))"/>
|
||||
<div>
|
||||
<a href="#" t-if="invoice.state == 'posted' and invoice.payment_state in ('not_paid', 'partial') and invoice.amount_total and invoice.move_type == 'out_invoice' and (pending_manual_txs or not tx_ids or invoice.amount_residual)"
|
||||
<a href="#" t-if="invoice.state == 'posted' and invoice.payment_state in ('not_paid', 'partial') and invoice.amount_total and invoice.move_type == 'out_invoice' and (pending_manual_txs or not tx_ids or invoice.amount_paid < invoice.amount_total)"
|
||||
|
||||
class="btn btn-primary btn-block mb-2" data-toggle="modal" data-target="#pay_with">
|
||||
<i class="fa fa-fw fa-arrow-circle-right"/> Pay Now
|
||||
|
||||
@@ -15,6 +15,11 @@ class AccountMove(models.Model):
|
||||
authorized_transaction_ids = fields.Many2many(
|
||||
string="Authorized Transactions", comodel_name='payment.transaction',
|
||||
compute='_compute_authorized_transaction_ids', readonly=True, copy=False)
|
||||
amount_paid = fields.Monetary(
|
||||
string="Amount paid",
|
||||
help="The amount already paid for this invoice.",
|
||||
compute='_compute_amount_paid'
|
||||
)
|
||||
|
||||
@api.depends('transaction_ids')
|
||||
def _compute_authorized_transaction_ids(self):
|
||||
@@ -23,6 +28,17 @@ class AccountMove(models.Model):
|
||||
lambda tx: tx.state == 'authorized'
|
||||
)
|
||||
|
||||
@api.depends('transaction_ids')
|
||||
def _compute_amount_paid(self):
|
||||
""" Sum all the transaction amount for which state is in 'authorized' or 'done'
|
||||
"""
|
||||
for invoice in self:
|
||||
invoice.amount_paid = sum(
|
||||
invoice.transaction_ids.filtered(
|
||||
lambda tx: tx.state in ('authorized', 'done')
|
||||
).mapped('amount')
|
||||
)
|
||||
|
||||
def get_portal_last_transaction(self):
|
||||
self.ensure_one()
|
||||
return self.with_context(active_test=False).transaction_ids._get_last()
|
||||
|
||||
Reference in New Issue
Block a user