Choose template to use when emailing multiple invoices at once #472
This commit is contained in:
parent
98cb0c2596
commit
65b7d1aa49
|
|
@ -55,7 +55,8 @@ class CreditRepository {
|
|||
}
|
||||
|
||||
Future<List<InvoiceEntity>> bulkAction(
|
||||
Credentials credentials, List<String> ids, EntityAction action) async {
|
||||
Credentials credentials, List<String> ids, EntityAction action,
|
||||
{EmailTemplate template}) async {
|
||||
if (ids.length > kMaxEntitiesPerBulkAction && action.applyMaxLimit) {
|
||||
ids = ids.sublist(0, kMaxEntitiesPerBulkAction);
|
||||
}
|
||||
|
|
@ -63,7 +64,11 @@ class CreditRepository {
|
|||
final url =
|
||||
credentials.url + '/credits/bulk?per_page=$kMaxEntitiesPerBulkAction';
|
||||
final dynamic response = await webClient.post(url, credentials.token,
|
||||
data: json.encode({'ids': ids, 'action': action.toApiParam()}));
|
||||
data: json.encode({
|
||||
'ids': ids,
|
||||
'action': action.toApiParam(),
|
||||
if (template != null) 'email_type': 'email_template_$template',
|
||||
}));
|
||||
|
||||
final InvoiceListResponse invoiceResponse =
|
||||
serializers.deserializeWith(InvoiceListResponse.serializer, response);
|
||||
|
|
|
|||
|
|
@ -56,7 +56,8 @@ class InvoiceRepository {
|
|||
}
|
||||
|
||||
Future<List<InvoiceEntity>> bulkAction(
|
||||
Credentials credentials, List<String> ids, EntityAction action) async {
|
||||
Credentials credentials, List<String> ids, EntityAction action,
|
||||
{EmailTemplate template}) async {
|
||||
if (ids.length > kMaxEntitiesPerBulkAction && action.applyMaxLimit) {
|
||||
ids = ids.sublist(0, kMaxEntitiesPerBulkAction);
|
||||
}
|
||||
|
|
@ -64,7 +65,11 @@ class InvoiceRepository {
|
|||
final url =
|
||||
credentials.url + '/invoices/bulk?per_page=$kMaxEntitiesPerBulkAction';
|
||||
final dynamic response = await webClient.post(url, credentials.token,
|
||||
data: json.encode({'ids': ids, 'action': action.toApiParam()}));
|
||||
data: json.encode({
|
||||
'ids': ids,
|
||||
'action': action.toApiParam(),
|
||||
if (template != null) 'email_type': 'email_template_$template',
|
||||
}));
|
||||
|
||||
final InvoiceListResponse invoiceResponse =
|
||||
serializers.deserializeWith(InvoiceListResponse.serializer, response);
|
||||
|
|
|
|||
|
|
@ -50,7 +50,8 @@ class PurchaseOrderRepository {
|
|||
}
|
||||
|
||||
Future<List<InvoiceEntity>> bulkAction(
|
||||
Credentials credentials, List<String> ids, EntityAction action) async {
|
||||
Credentials credentials, List<String> ids, EntityAction action,
|
||||
{EmailTemplate template}) async {
|
||||
if (ids.length > kMaxEntitiesPerBulkAction && action.applyMaxLimit) {
|
||||
ids = ids.sublist(0, kMaxEntitiesPerBulkAction);
|
||||
}
|
||||
|
|
@ -58,7 +59,11 @@ class PurchaseOrderRepository {
|
|||
final url = credentials.url +
|
||||
'/purchase_orders/bulk?per_page=$kMaxEntitiesPerBulkAction';
|
||||
final dynamic response = await webClient.post(url, credentials.token,
|
||||
data: json.encode({'ids': ids, 'action': action.toApiParam()}));
|
||||
data: json.encode({
|
||||
'ids': ids,
|
||||
'action': action.toApiParam(),
|
||||
if (template != null) 'email_type': 'email_template_$template',
|
||||
}));
|
||||
|
||||
print(
|
||||
'## DATA: ${json.encode({'ids': ids, 'action': action.toApiParam()})}');
|
||||
|
|
|
|||
|
|
@ -56,7 +56,8 @@ class QuoteRepository {
|
|||
}
|
||||
|
||||
Future<List<InvoiceEntity>> bulkAction(
|
||||
Credentials credentials, List<String> ids, EntityAction action) async {
|
||||
Credentials credentials, List<String> ids, EntityAction action,
|
||||
{EmailTemplate template}) async {
|
||||
if (ids.length > kMaxEntitiesPerBulkAction && action.applyMaxLimit) {
|
||||
ids = ids.sublist(0, kMaxEntitiesPerBulkAction);
|
||||
}
|
||||
|
|
@ -64,7 +65,11 @@ class QuoteRepository {
|
|||
final url =
|
||||
credentials.url + '/quotes/bulk?per_page=$kMaxEntitiesPerBulkAction';
|
||||
final dynamic response = await webClient.post(url, credentials.token,
|
||||
data: json.encode({'ids': ids, 'action': action.toApiParam()}));
|
||||
data: json.encode({
|
||||
'ids': ids,
|
||||
'action': action.toApiParam(),
|
||||
if (template != null) 'email_type': 'email_template_$template',
|
||||
}));
|
||||
|
||||
final InvoiceListResponse invoiceResponse =
|
||||
serializers.deserializeWith(InvoiceListResponse.serializer, response);
|
||||
|
|
|
|||
|
|
@ -273,10 +273,11 @@ class MarkSentCreditFailure implements StopSaving {
|
|||
}
|
||||
|
||||
class BulkEmailCreditsRequest implements StartSaving {
|
||||
BulkEmailCreditsRequest(this.completer, this.creditIds);
|
||||
BulkEmailCreditsRequest({this.completer, this.creditIds, this.template});
|
||||
|
||||
final Completer completer;
|
||||
final List<String> creditIds;
|
||||
final EmailTemplate template;
|
||||
}
|
||||
|
||||
class BulkEmailCreditsSuccess implements StopSaving, PersistData {
|
||||
|
|
@ -548,12 +549,13 @@ Future handleCreditAction(
|
|||
message: localization.bulkEmailCredits,
|
||||
callback: (_) {
|
||||
store.dispatch(BulkEmailCreditsRequest(
|
||||
snackBarCompleter<Null>(
|
||||
context,
|
||||
creditIds.length == 1
|
||||
? localization.emailedCredit
|
||||
: localization.emailedCredits),
|
||||
creditIds));
|
||||
completer: snackBarCompleter<Null>(
|
||||
context,
|
||||
creditIds.length == 1
|
||||
? localization.emailedCredit
|
||||
: localization.emailedCredits),
|
||||
creditIds: creditIds,
|
||||
));
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -279,10 +279,11 @@ class MarkInvoicesSentFailure implements StopSaving {
|
|||
}
|
||||
|
||||
class BulkEmailInvoicesRequest implements StartSaving {
|
||||
BulkEmailInvoicesRequest(this.completer, this.invoiceIds);
|
||||
BulkEmailInvoicesRequest({this.completer, this.invoiceIds, this.template});
|
||||
|
||||
final Completer completer;
|
||||
final List<String> invoiceIds;
|
||||
final EmailTemplate template;
|
||||
}
|
||||
|
||||
class BulkEmailInvoicesSuccess implements StopSaving, PersistData {
|
||||
|
|
@ -668,12 +669,13 @@ void handleInvoiceAction(BuildContext context, List<BaseEntity> invoices,
|
|||
message: localization.bulkEmailInvoices,
|
||||
callback: (_) {
|
||||
store.dispatch(BulkEmailInvoicesRequest(
|
||||
snackBarCompleter<Null>(
|
||||
context,
|
||||
invoiceIds.length == 1
|
||||
? localization.emailedInvoice
|
||||
: localization.emailedInvoices),
|
||||
invoiceIds));
|
||||
completer: snackBarCompleter<Null>(
|
||||
context,
|
||||
invoiceIds.length == 1
|
||||
? localization.emailedInvoice
|
||||
: localization.emailedInvoices),
|
||||
invoiceIds: invoiceIds,
|
||||
));
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -209,10 +209,12 @@ class SavePurchaseOrderFailure implements StopSaving {
|
|||
}
|
||||
|
||||
class BulkEmailPurchaseOrdersRequest implements StartSaving {
|
||||
BulkEmailPurchaseOrdersRequest(this.completer, this.purchaseOrderIds);
|
||||
BulkEmailPurchaseOrdersRequest(
|
||||
{this.completer, this.purchaseOrderIds, this.template});
|
||||
|
||||
final Completer completer;
|
||||
final List<String> purchaseOrderIds;
|
||||
final EmailTemplate template;
|
||||
}
|
||||
|
||||
class BulkEmailPurchaseOrdersSuccess implements StopSaving, PersistData {
|
||||
|
|
@ -761,12 +763,13 @@ void handlePurchaseOrderAction(BuildContext context,
|
|||
message: localization.bulkEmailPurchaseOrders,
|
||||
callback: (_) {
|
||||
store.dispatch(BulkEmailPurchaseOrdersRequest(
|
||||
snackBarCompleter<Null>(
|
||||
context,
|
||||
purchaseOrderIds.length == 1
|
||||
? localization.emailedPurchaseOrder
|
||||
: localization.emailedPurchaseOrders),
|
||||
purchaseOrderIds));
|
||||
completer: snackBarCompleter<Null>(
|
||||
context,
|
||||
purchaseOrderIds.length == 1
|
||||
? localization.emailedPurchaseOrder
|
||||
: localization.emailedPurchaseOrders),
|
||||
purchaseOrderIds: purchaseOrderIds,
|
||||
));
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -278,10 +278,11 @@ class MarkSentQuoteFailure implements StopSaving {
|
|||
}
|
||||
|
||||
class BulkEmailQuotesRequest implements StartSaving {
|
||||
BulkEmailQuotesRequest(this.completer, this.quoteIds);
|
||||
BulkEmailQuotesRequest({this.completer, this.quoteIds, this.template});
|
||||
|
||||
final Completer completer;
|
||||
final List<String> quoteIds;
|
||||
final EmailTemplate template;
|
||||
}
|
||||
|
||||
class BulkEmailQuotesSuccess implements StopSaving, PersistData {
|
||||
|
|
@ -622,12 +623,12 @@ Future handleQuoteAction(
|
|||
message: localization.bulkEmailQuotes,
|
||||
callback: (_) {
|
||||
store.dispatch(BulkEmailQuotesRequest(
|
||||
snackBarCompleter<Null>(
|
||||
completer: snackBarCompleter<Null>(
|
||||
context,
|
||||
quoteIds.length == 1
|
||||
? localization.emailedQuote
|
||||
: localization.emailedQuotes),
|
||||
quoteIds));
|
||||
quoteIds: quoteIds));
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
Loading…
Reference in New Issue