feat: add rows count (broken), fix: bug with low stock items
This commit is contained in:
@@ -6,6 +6,7 @@ import '../models/bar_tab.dart';
|
||||
import '../models/product.dart';
|
||||
import '../models/tab_item.dart';
|
||||
import '../services/bar_tab_service.dart';
|
||||
import '../services/product_service.dart';
|
||||
import 'inventory_view_model.dart';
|
||||
|
||||
class BarScreenViewModel extends ChangeNotifier {
|
||||
@@ -95,9 +96,7 @@ class BarScreenViewModel extends ChangeNotifier {
|
||||
if (tab == null) return;
|
||||
|
||||
if (product.stockQuantity <= 0) {
|
||||
_errorMessage = 'Product is out of stock.';
|
||||
notifyListeners();
|
||||
return;
|
||||
throw const InsufficientStockException();
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -109,6 +108,8 @@ class BarScreenViewModel extends ChangeNotifier {
|
||||
|
||||
await _reloadTabs();
|
||||
} catch (e, stack) {
|
||||
if (e is InsufficientStockException) rethrow;
|
||||
|
||||
debugPrint('BarScreenViewModel: addProductToSelectedTab error: $e');
|
||||
_errorMessage = 'Could not add product to tab.';
|
||||
notifyListeners();
|
||||
@@ -120,6 +121,20 @@ class BarScreenViewModel extends ChangeNotifier {
|
||||
Future<void> changeItemQuantity(TabItem item, int quantity) async {
|
||||
final difference = quantity - item.quantity;
|
||||
|
||||
if (difference > 0) {
|
||||
Product? product;
|
||||
for (final candidate in inventory.products) {
|
||||
if (candidate.id == item.productId) {
|
||||
product = candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (product != null && product.stockQuantity < difference) {
|
||||
throw const InsufficientStockException();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
await barTabService.updateTabItemQuantity(
|
||||
tabItemId: item.id,
|
||||
@@ -135,6 +150,8 @@ class BarScreenViewModel extends ChangeNotifier {
|
||||
|
||||
await _reloadTabs();
|
||||
} catch (e, stack) {
|
||||
if (e is InsufficientStockException) rethrow;
|
||||
|
||||
debugPrint('BarScreenViewModel: changeItemQuantity error: $e');
|
||||
_errorMessage = 'Could not update item quantity.';
|
||||
notifyListeners();
|
||||
|
||||
Reference in New Issue
Block a user