[FIX] website_sale_payment_terms: fix errors in the payment process

* clear order terms if user rejects agreement
* set payment transaction amount to amount_due_today
* fix bad view inheritance spec
* fix default selected term when partner_term is not in website_terms
* do not render payment bypass form if amount_total is 0

H5924
This commit is contained in:
Cedric Collins
2021-10-25 13:41:51 -05:00
parent 7d758539c0
commit b79f9487b9
6 changed files with 119 additions and 11 deletions

View File

@@ -1,4 +1,6 @@
from odoo import models, _
import logging
_logger = logging.getLogger(__name__)
class PaymentTransaction(models.Model):
@@ -15,7 +17,30 @@ class PaymentTransaction(models.Model):
self._log_payment_transaction_sent()
return self.acquirer_id.with_context(submit_class='btn btn-primary', submit_txt=submit_txt or _('Pay Now')).sudo().render(
self.reference,
order.amount_total_deposit or order.amount_total,
order.amount_due_today,
order.pricelist_id.currency_id.id,
values=values,
)
# Override to confirm payments totaling the amount_due_today
def _check_amount_and_confirm_order(self):
self.ensure_one()
for order in self.sale_order_ids.filtered(lambda so: so.state in ('draft', 'sent')):
amount = order.amount_due_today
if order.currency_id.compare_amounts(self.amount, amount) == 0:
order.with_context(send_email=True).action_confirm()
else:
_logger.warning(
'<%s> transaction AMOUNT MISMATCH for order %s (ID %s): expected %r, got %r',
self.acquirer_id.provider, order.name, order.id,
amount, self.amount,
)
order.message_post(
subject=_("Amount Mismatch (%s)") % self.acquirer_id.provider,
body=_(
"The order was not confirmed despite response from the acquirer (%s): order total is %r but acquirer replied with %r.") % (
self.acquirer_id.provider,
amount,
self.amount,
)
)