import frappe
from frappe import _


class PaymentRequestOverride:
	"""Mixin for Payment Request — wraps send_email to survive wkhtmltopdf failures."""

	def before_submit(self):
		try:
			super().before_submit()
		except OSError as e:
			if "wkhtmltopdf" in str(e) or "pdf" in str(e).lower():
				frappe.log_error(str(e), "KB Payment Request PDF Error")
				frappe.msgprint(
					_("Warning: payment request email could not be sent (PDF generation failed). Proceeding with submit."),
					alert=True,
					indicator="orange",
				)
			else:
				raise
