[FIX] account_payment: fix portal pay button

Steps to reproduce:
- Install Accounting
- Activate a payment provider (e.g. Stripe)
- Configure payment provider with "Capture Amount Manually" option activated
- Invoice Online Payment in Accounting settings
- Create an invoice
- Go to invoice portal preview
- Pay it via "Pay Now" button
- Go back to invoice portal preview
=> The "Pay Now" button is still there (not expected)

- Uninstall "account_payment_invoice_online_payment_patch" module
- Go back to invoice portal preview
=> The "Pay Now" button does not appear anymore (expected)

Cause:
"account_payment_invoice_online_payment_patch" module has been created to
allow to disable invoice online payment without uninstalling "account_payment"
module.

However, it overrides 2 different "t-if" conditions:

1) (invoice.amount_residual or not tx_ids) and
   invoice.state == 'posted' and
   invoice.payment_state in ('not_paid', 'partial') and
   invoice.amount_total

2) 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)

with the same condition "invoice._has_to_be_paid()" that corresponds to:
   (self.amount_residual or not transactions) and
   self.state == 'posted' and
   self.payment_state in ('not_paid', 'partial') and
   self.amount_total and
   self.move_type == 'out_invoice'

One part of the second "t-if" condition is removed by the override:
(pending_manual_txs or not tx_ids or invoice.amount_paid < invoice.amount_total)

The second condition is used and is overridden 2 times.

Solution:
Add (pending_manual_txs or not tx_ids or invoice.amount_paid < invoice.amount_total)
in the "_has_to_be_paid" method.

opw-3378400

closes odoo/odoo#147316

X-original-commit: df110bb524f780433cdaf64e482329989e9d513b
Signed-off-by: Anh Thao Pham (pta) <pta@odoo.com>
This commit is contained in:
Anh Thao Pham (pta)
2023-12-22 16:14:54 +00:00
parent 06d6000ae9
commit a8dfb18dfa
@@ -42,8 +42,8 @@ class AccountMove(models.Model):
def _has_to_be_paid(self):
self.ensure_one()
transactions = self.transaction_ids.filtered(lambda tx: tx.state in ('authorized', 'done'))
pending_transactions = self.transaction_ids.filtered(
transactions = self.transaction_ids.filtered(lambda tx: tx.state in ('pending', 'authorized', 'done'))
pending_transactions = transactions.filtered(
lambda tx: tx.state == 'pending' and tx.provider_code not in ('none', 'custom'))
enabled_feature = str2bool(
self.env['ir.config_parameter'].sudo().get_param(
@@ -53,14 +53,13 @@ class AccountMove(models.Model):
return enabled_feature and bool(
(
self.amount_residual
# FIXME someplace we check amount_residual and some other amount_paid < amount_total
# what is the correct heuristic to check ?
or not (transactions or pending_transactions)
or not transactions
)
and self.state == 'posted'
and self.payment_state in ('not_paid', 'partial')
and self.amount_total
and self.move_type == 'out_invoice'
and (pending_transactions or not transactions or self.amount_paid < self.amount_total)
)
def get_portal_last_transaction(self):