feat: update item response schema and refactor item creation logic for improved payload structure
This commit is contained in:
@@ -258,7 +258,7 @@ class LineItemUpdate(LineItemBase):
|
||||
)
|
||||
|
||||
|
||||
class LineItemResponse(BaseModel):
|
||||
class LineItemResponse(LineItemBase):
|
||||
"""Schema for single item response"""
|
||||
|
||||
id: int
|
||||
|
||||
@@ -299,13 +299,6 @@ class ItemService:
|
||||
if item_data.fa_data and item_data.fa_data.subitem_number is None:
|
||||
errors.add_required_error(field=f"fa_data.subitem_number")
|
||||
|
||||
# Validar apóstrofes en número de parte
|
||||
if item_data.part_number_id and "'" in str(item_data.part_number_id):
|
||||
errors.add_error(
|
||||
field=f"part_number",
|
||||
message=f"Advertencia: El Número de Parte contiene apóstrofes y serán omitidos",
|
||||
code="WARNING_APOSTROPHE",
|
||||
)
|
||||
|
||||
# Si hay errores, lanzar excepción ANTES de intentar crear
|
||||
errors.raise_if_errors("Error al crear el item")
|
||||
@@ -396,16 +389,6 @@ class ItemService:
|
||||
db_item.line_number,
|
||||
)
|
||||
|
||||
# Validaciones adicionales específicas del negocio
|
||||
|
||||
# Validar apóstrofes en número de parte
|
||||
if item_data.part_number_id and "'" in str(item_data.part_number_id):
|
||||
errors.add_error(
|
||||
field=f"part_number",
|
||||
message=f"Advertencia: El Número de Parte contiene apóstrofes y serán omitidos",
|
||||
solution=None,
|
||||
code="WARNING_APOSTROPHE",
|
||||
)
|
||||
|
||||
# Validar tipo de partida
|
||||
if hasattr(item_data, "item_type") and item_data.item_type:
|
||||
@@ -446,14 +429,6 @@ class ItemService:
|
||||
exclude_unset=True,
|
||||
)
|
||||
|
||||
# Map schema field names to model field names
|
||||
if "part_number_id" in item_dict:
|
||||
item_dict["part_number"] = item_dict.pop("part_number_id")
|
||||
if "component_part_number_id" in item_dict:
|
||||
item_dict["component_part_number"] = item_dict.pop(
|
||||
"component_part_number_id"
|
||||
)
|
||||
|
||||
# Update item fields
|
||||
for key, value in item_dict.items():
|
||||
setattr(db_item, key, value)
|
||||
|
||||
@@ -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