feat: use batch save for invoice items
This commit is contained in:
@@ -112,15 +112,20 @@ export const useInvoicesStore = defineStore('invoices', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveInvoiceItems(invoiceId: number, items: { description: string; quantity: number; unit_price: number }[]): Promise<void> {
|
async function saveInvoiceItems(invoiceId: number, items: { description: string; quantity: number; unit_price: number; time_entry_id?: number }[]): Promise<void> {
|
||||||
for (const item of items) {
|
try {
|
||||||
await createInvoiceItem({
|
await invoke('save_invoice_items_batch', {
|
||||||
invoice_id: invoiceId,
|
invoiceId,
|
||||||
|
items: items.map(item => ({
|
||||||
description: item.description,
|
description: item.description,
|
||||||
quantity: item.quantity,
|
quantity: item.quantity,
|
||||||
rate: item.unit_price,
|
unit_price: item.unit_price,
|
||||||
amount: item.quantity * item.unit_price,
|
time_entry_id: item.time_entry_id || null,
|
||||||
|
})),
|
||||||
})
|
})
|
||||||
|
} catch (error) {
|
||||||
|
handleInvokeError(error, 'Failed to save invoice items')
|
||||||
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user