Prevent invoicing multiple tasks for different clients
This commit is contained in:
parent
30f4c461c9
commit
c6f49e1f1a
|
|
@ -18,6 +18,7 @@ import 'package:invoiceninja_flutter/redux/document/document_actions.dart';
|
|||
import 'package:invoiceninja_flutter/redux/project/project_selectors.dart';
|
||||
import 'package:invoiceninja_flutter/ui/app/entities/entity_actions_dialog.dart';
|
||||
import 'package:invoiceninja_flutter/utils/completers.dart';
|
||||
import 'package:invoiceninja_flutter/utils/dialogs.dart';
|
||||
import 'package:invoiceninja_flutter/utils/localization.dart';
|
||||
|
||||
class ViewProjectList implements PersistUI {
|
||||
|
|
@ -272,6 +273,23 @@ void handleProjectAction(
|
|||
..clientId = project.clientId));
|
||||
break;
|
||||
case EntityAction.invoiceProject:
|
||||
String lastClientId = '';
|
||||
bool hasMultipleClients = false;
|
||||
projects.forEach((project) {
|
||||
final clientId = (project as ProjectEntity).clientId ?? '';
|
||||
if (clientId.isNotEmpty) {
|
||||
if (lastClientId.isNotEmpty && lastClientId != clientId) {
|
||||
hasMultipleClients = true;
|
||||
}
|
||||
lastClientId = clientId;
|
||||
}
|
||||
});
|
||||
if (hasMultipleClients) {
|
||||
showErrorDialog(
|
||||
context: context, message: localization.multipleClientError);
|
||||
return;
|
||||
}
|
||||
|
||||
final items = <InvoiceItemEntity>[];
|
||||
projects.forEach((project) {
|
||||
items.addAll(
|
||||
|
|
|
|||
|
|
@ -383,6 +383,23 @@ void handleTaskAction(
|
|||
break;
|
||||
case EntityAction.invoiceTask:
|
||||
case EntityAction.addToInvoice:
|
||||
String lastClientId = '';
|
||||
bool hasMultipleClients = false;
|
||||
tasks.forEach((task) {
|
||||
final clientId = (task as TaskEntity).clientId ?? '';
|
||||
if (clientId.isNotEmpty) {
|
||||
if (lastClientId.isNotEmpty && lastClientId != clientId) {
|
||||
hasMultipleClients = true;
|
||||
}
|
||||
lastClientId = clientId;
|
||||
}
|
||||
});
|
||||
if (hasMultipleClients) {
|
||||
showErrorDialog(
|
||||
context: context, message: localization.multipleClientError);
|
||||
return;
|
||||
}
|
||||
|
||||
tasks.sort((taskA, taskB) {
|
||||
final taskAEntity = taskA as TaskEntity;
|
||||
final taskBEntity = taskB as TaskEntity;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ mixin LocalizationsProvider on LocaleCodeAware {
|
|||
static final Map<String, Map<String, String>> _localizedValues = {
|
||||
'en': {
|
||||
// STARTER: lang key - do not remove comment
|
||||
'multiple_client_error': 'Error: records belong to more than one client',
|
||||
'register_label': 'Create your account in seconds',
|
||||
'login_label': 'Login to an existing account',
|
||||
'add_to_invoice': 'Add To Invoice',
|
||||
|
|
@ -69669,6 +69670,11 @@ mixin LocalizationsProvider on LocaleCodeAware {
|
|||
_localizedValues[localeCode]['login_label'] ??
|
||||
_localizedValues[localeCode]['login_label'];
|
||||
|
||||
|
||||
String get multipleClientError =>
|
||||
_localizedValues[localeCode]['multiple_client_error'] ??
|
||||
_localizedValues[localeCode]['multiple_client_error'];
|
||||
|
||||
// STARTER: lang field - do not remove comment
|
||||
|
||||
String lookup(String key) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue