Support cloning

This commit is contained in:
unknown 2018-08-06 22:29:38 +03:00
parent f10f3d30fe
commit 5d54c5e9b7
4 changed files with 18 additions and 1 deletions

View File

@ -65,6 +65,10 @@ abstract class ProductEntity extends Object
} }
ProductEntity._(); ProductEntity._();
ProductEntity get clone => rebuild((b) => b
..id = --ProductEntity.counter
);
@override @override
EntityType get entityType { EntityType get entityType {
return EntityType.product; return EntityType.product;

View File

@ -1,4 +1,5 @@
import 'package:invoiceninja_flutter/data/models/entities.dart'; import 'package:invoiceninja_flutter/data/models/entities.dart';
import 'package:invoiceninja_flutter/data/models/models.dart';
import 'package:invoiceninja_flutter/ui/app/forms/custom_field.dart'; import 'package:invoiceninja_flutter/ui/app/forms/custom_field.dart';
import 'package:invoiceninja_flutter/ui/app/invoice/tax_rate_dropdown.dart'; import 'package:invoiceninja_flutter/ui/app/invoice/tax_rate_dropdown.dart';
import 'package:invoiceninja_flutter/utils/formatting.dart'; import 'package:invoiceninja_flutter/utils/formatting.dart';
@ -127,6 +128,13 @@ class _ProductEditState extends State<ProductEdit> {
: ActionMenuButton( : ActionMenuButton(
entity: viewModel.product, entity: viewModel.product,
onSelected: viewModel.onActionSelected, onSelected: viewModel.onActionSelected,
customActions: [
ActionMenuChoice(
label: localization.clone,
icon: Icons.control_point_duplicate,
action: EntityAction.clone,
),
],
) )
], ],
), ),

View File

@ -106,11 +106,14 @@ class ProductEditVM {
store.dispatch(RestoreProductRequest(completer, product.id)); store.dispatch(RestoreProductRequest(completer, product.id));
message = AppLocalization.of(context).successfullyRestoredProduct; message = AppLocalization.of(context).successfullyRestoredProduct;
break; break;
case EntityAction.clone:
store.dispatch(UpdateProduct(product.clone));
break;
} }
return completer.future.then((_) { return completer.future.then((_) {
if ([EntityAction.archive, EntityAction.delete].contains(action)) { if ([EntityAction.archive, EntityAction.delete].contains(action)) {
Navigator.of(context).pop(message); Navigator.of(context).pop(message);
} else { } else if (message.isNotEmpty) {
Scaffold.of(context).showSnackBar(SnackBar( Scaffold.of(context).showSnackBar(SnackBar(
content: SnackBarRow( content: SnackBarRow(
message: message, message: message,

View File

@ -177,6 +177,7 @@ class AppLocalization {
'blank_contact': 'Blank Contact', 'blank_contact': 'Blank Contact',
'activity': 'Activity', 'activity': 'Activity',
'no_records_found': 'No records found', 'no_records_found': 'No records found',
'clone': 'Clone',
'payment': 'Payment', 'payment': 'Payment',
'payments': 'Payments', 'payments': 'Payments',
@ -409,6 +410,7 @@ class AppLocalization {
String get blankContact => _localizedValues[locale.languageCode]['blank_contact']; String get blankContact => _localizedValues[locale.languageCode]['blank_contact'];
String get activity => _localizedValues[locale.languageCode]['activity']; String get activity => _localizedValues[locale.languageCode]['activity'];
String get noRecordsFound => _localizedValues[locale.languageCode]['no_records_found']; String get noRecordsFound => _localizedValues[locale.languageCode]['no_records_found'];
String get clone => _localizedValues[locale.languageCode]['clone'];
String get payment => _localizedValues[locale.languageCode]['payment']; String get payment => _localizedValues[locale.languageCode]['payment'];
String get payments => _localizedValues[locale.languageCode]['payments']; String get payments => _localizedValues[locale.languageCode]['payments'];