feat: update item response schema and refactor item creation logic for improved payload structure
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
import ClassDialog from './class-dialog.svelte';
|
||||
import type { Item, LineQuantities, LineFinancials, LineCustoms } from '$lib/api/dashboard/a76/items';
|
||||
import type { Invoice } from '$lib/api/dashboard/a76/invoices';
|
||||
import { companyStore } from '$lib/stores/company.svelte';
|
||||
import { companyStore } from '$lib/stores/company.svelte';
|
||||
|
||||
let {
|
||||
lineItem = $bindable(),
|
||||
@@ -110,10 +110,10 @@
|
||||
(lineItem as any).description.description_english = classItem.description_en;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function handleUnitSelect(unit: any) {
|
||||
lineItem.unit_of_measure = unit.id;
|
||||
lineItem.unit_of_measure = unit.id;
|
||||
// Store unit code for display
|
||||
(lineItem as any).unit_code = unit.code;
|
||||
(lineItem as any).unit_description = unit.description || unit.description_en;
|
||||
|
||||
@@ -501,19 +501,26 @@
|
||||
|
||||
isSavingPreset = true;
|
||||
try {
|
||||
// Each item in builderItems is already a LineItem (no nested lines)
|
||||
const cleanedItems = builderItems.map((item: Item, idx: number) => {
|
||||
// We group everything as items for the template
|
||||
const lines = builderItems.map((item: Item, idx: number) => {
|
||||
return {
|
||||
...cleanLineData(item),
|
||||
line_number: item.line_number || idx + 1,
|
||||
line_number: item.line_number || idx + 1, // Ensure line_number is present
|
||||
id: undefined // Ensure no IDs are saved in the preset
|
||||
};
|
||||
});
|
||||
|
||||
const payloadItems = [
|
||||
{
|
||||
reference_number: builderItems[0]?.reference_number || undefined,
|
||||
lines: lines
|
||||
}
|
||||
] as any;
|
||||
|
||||
await itemPresetsApi.create(activeCompanyId, {
|
||||
name: createPresetName.trim(),
|
||||
description: createPresetDescription.trim() || undefined,
|
||||
items: cleanedItems
|
||||
items: payloadItems
|
||||
});
|
||||
|
||||
createPresetName = '';
|
||||
|
||||
Reference in New Issue
Block a user