diff --git a/lib/ui/payment/edit/payment_edit_vm.dart b/lib/ui/payment/edit/payment_edit_vm.dart index d81488a2b..37d2c5a44 100644 --- a/lib/ui/payment/edit/payment_edit_vm.dart +++ b/lib/ui/payment/edit/payment_edit_vm.dart @@ -80,7 +80,7 @@ class PaymentEditVM { onSavePressed: (BuildContext context) { Debouncer.runOnComplete(() { final payment = store.state.paymentUIState.editing!; - final localization = navigatorKey.localization; + final localization = navigatorKey.localization!; final navigator = navigatorKey.currentState; double amount = 0; payment.invoices.forEach((invoice) => amount += invoice.amount); @@ -89,17 +89,27 @@ class PaymentEditVM { showDialog( context: navigatorKey.currentContext!, builder: (BuildContext context) { - return ErrorDialog(localization!.creditPaymentError); + return ErrorDialog(localization.creditPaymentError); + }); + return null; + } else if (!state.company.enableApplyingPayments && + payment.invoices.isEmpty && + payment.credits.isEmpty) { + showDialog( + context: navigatorKey.currentContext!, + builder: (BuildContext context) { + return ErrorDialog(localization.pleaseSelectAnInvoice); }); return null; } + final Completer completer = Completer(); store.dispatch( SavePaymentRequest(completer: completer, payment: payment)); return completer.future.then((savedPayment) { showToast(payment.isNew - ? localization!.createdPayment - : localization!.updatedPayment); + ? localization.createdPayment + : localization.updatedPayment); if (state.prefState.isMobile) { store.dispatch(UpdateCurrentRoute(PaymentViewScreen.route)); if (payment.isNew) {