print order add item
This commit is contained in:
@@ -161,6 +161,17 @@ class Order with _$Order {
|
||||
paymentCount: 1,
|
||||
splitType: 'Single',
|
||||
);
|
||||
|
||||
// For Add Item Order
|
||||
factory Order.fromLastOrder(Order order, List<ProductQuantity> products) =>
|
||||
order.copyWith(
|
||||
orderItems: products
|
||||
.map((e) => OrderItem.fromProductQuantity(e))
|
||||
.toList(),
|
||||
totalAmount: products
|
||||
.map((e) => e.product.price.toInt() * e.quantity)
|
||||
.reduce((value, element) => value + element),
|
||||
);
|
||||
}
|
||||
|
||||
@freezed
|
||||
@@ -202,4 +213,25 @@ class OrderItem with _$OrderItem {
|
||||
printerType: '',
|
||||
paidQuantity: 0,
|
||||
);
|
||||
|
||||
factory OrderItem.fromProductQuantity(ProductQuantity productQuantity) =>
|
||||
OrderItem(
|
||||
id: '',
|
||||
orderId: '',
|
||||
productId: productQuantity.product.id,
|
||||
productName: productQuantity.product.name,
|
||||
productVariantId: productQuantity.variant?.id ?? '',
|
||||
productVariantName: productQuantity.variant?.name ?? '',
|
||||
quantity: productQuantity.quantity,
|
||||
unitPrice: productQuantity.product.price.toInt(),
|
||||
totalPrice: (productQuantity.product.price * productQuantity.quantity)
|
||||
.toInt(),
|
||||
modifiers: [],
|
||||
notes: productQuantity.notes,
|
||||
status: 'pending',
|
||||
createdAt: DateTime.now(),
|
||||
updatedAt: DateTime.now(),
|
||||
printerType: productQuantity.product.printerType,
|
||||
paidQuantity: 0,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
import '../../common/api/api_failure.dart';
|
||||
import '../../common/types/split_type.dart';
|
||||
import '../product/product.dart';
|
||||
|
||||
part 'order.freezed.dart';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user