fix(documents): normalize units when selecting and loading rows
All checks were successful
Build and Release FEDEO / verify (push) Successful in 49s
Build and Release FEDEO / build-and-release (push) Successful in 5m50s

This commit is contained in:
2026-09-25 11:42:17 +02:00
parent eaa5627062
commit 8f06d06037
2 changed files with 108 additions and 13 deletions

View File

@@ -333,6 +333,13 @@ const normalizeEntityId = (value) => {
}
return typeof value === "object" ? (value.id ?? null) : value
}
const normalizeUnitId = (unit) => {
const value = unit && typeof unit === "object" ? unit.id : unit
if (typeof value !== "number" && typeof value !== "string") return null
const id = Number(value)
return Number.isSafeInteger(id) && id > 0 ? id : null
}
const normalizeCreatedDocumentRow = (row) => {
let normalizedRow = row
@@ -359,6 +366,7 @@ const normalizeCreatedDocumentRow = (row) => {
return {
...normalizedRow,
id: normalizedRow.id || uuidv4(),
unit: normalizeUnitId(normalizedRow.unit),
costCentre: normalizedRow.costCentre || normalizedRow.costcentre || null,
purchasePrice: Number(normalizedRow.purchasePrice || 0),
linkedEntitys: Array.isArray(normalizedRow.linkedEntitys) ? normalizedRow.linkedEntitys : [],
@@ -689,6 +697,7 @@ const setupPage = async () => {
}
itemInfo.value.rows = normalizeCreatedDocumentRows(itemInfo.value.rows)
loaded.value = true
}
@@ -2035,19 +2044,8 @@ const setRowData = async (row, service = {sellingPriceComposed: {}}, product = {
if (row.service) {
console.log(service)
if(service.unit) {
row.unit = service.unit
} else {
let selectedService = services.value.find(i => i.id === row.service)
console.log(selectedService)
if(selectedService.unit?.id) {
row.unit = selectedService.unit.id
} else {
row.unit = selectedService.unit
}
}
row.unit = normalizeUnitId(service?.unit ?? services.value.find(i => i.id === row.service)?.unit)
//row.unit = service.unit ? service.unit : services.value.find(i => i.id === row.service).unit
row.inputPrice = ((service.sellingPriceComposed.total || service.sellingPrice) ? (service.sellingPriceComposed.total || service.sellingPrice) : (services.value.find(i => i.id === row.service).sellingPriceComposed.total || services.value.find(i => i.id === row.service).sellingPrice))
row.description = service.description ? service.description : (services.value.find(i => i.id === row.service) ? services.value.find(i => i.id === row.service).description : "")
row.costCentre = service.costcentre || services.value.find(i => i.id === row.service)?.costcentre || itemInfo.value.costcentre
@@ -2061,7 +2059,7 @@ const setRowData = async (row, service = {sellingPriceComposed: {}}, product = {
if (row.product) {
console.log("Product Detected")
row.unit = product.unit ? product.unit : products.value.find(i => i.id === row.product).unit
row.unit = normalizeUnitId(product?.unit ?? products.value.find(i => i.id === row.product)?.unit)
row.inputPrice = (product.selling_price ? product.selling_price : products.value.find(i => i.id === row.product).selling_price)
row.costCentre = row.costCentre || itemInfo.value.costcentre
//row.price = Number((row.originalPrice * (1 + itemInfo.value.customSurchargePercentage /100)).toFixed(2))