Refactor cost and price calculations across multiple models to return 0 instead of undefined when no cost or price is provided. This change ensures consistent handling of missing values in Filament, FilamentSku, Invoice, OrderItem, Part, PartSku, and ProductSku models.
This commit is contained in:
parent
f50949a192
commit
247bcc0ee5
@ -186,14 +186,13 @@ export const Filament = {
|
|||||||
columnWidth: 150,
|
columnWidth: 150,
|
||||||
value: (objectData) => {
|
value: (objectData) => {
|
||||||
const cost = objectData?.cost
|
const cost = objectData?.cost
|
||||||
if (!cost) return undefined
|
if (!cost) return 0
|
||||||
if (objectData?.costTaxRate?.rateType == 'percentage') {
|
if (objectData?.costTaxRate?.rateType == 'percentage') {
|
||||||
return (
|
return (
|
||||||
(cost * (1 + objectData?.costTaxRate?.rate / 100)).toFixed(2) ||
|
(cost * (1 + objectData?.costTaxRate?.rate / 100)).toFixed(2) || 0
|
||||||
undefined
|
|
||||||
)
|
)
|
||||||
} else if (objectData?.costTaxRate?.rateType == 'amount') {
|
} else if (objectData?.costTaxRate?.rateType == 'amount') {
|
||||||
return (cost + objectData?.costTaxRate?.rate).toFixed(2) || undefined
|
return (cost + objectData?.costTaxRate?.rate).toFixed(2) || 0
|
||||||
}
|
}
|
||||||
return cost
|
return cost
|
||||||
}
|
}
|
||||||
|
|||||||
@ -201,11 +201,11 @@ export const FilamentSku = {
|
|||||||
if (!objectData?.overrideCost) return undefined
|
if (!objectData?.overrideCost) return undefined
|
||||||
const cost = objectData?.cost
|
const cost = objectData?.cost
|
||||||
const taxRate = objectData?.costTaxRate
|
const taxRate = objectData?.costTaxRate
|
||||||
if (!cost) return undefined
|
if (!cost) return 0
|
||||||
if (taxRate?.rateType == 'percentage') {
|
if (taxRate?.rateType == 'percentage') {
|
||||||
return (cost * (1 + taxRate?.rate / 100)).toFixed(2) || undefined
|
return (cost * (1 + taxRate?.rate / 100)).toFixed(2) || 0
|
||||||
} else if (taxRate?.rateType == 'amount') {
|
} else if (taxRate?.rateType == 'amount') {
|
||||||
return (cost + taxRate?.rate).toFixed(2) || undefined
|
return (cost + taxRate?.rate).toFixed(2) || 0
|
||||||
}
|
}
|
||||||
return cost
|
return cost
|
||||||
},
|
},
|
||||||
|
|||||||
@ -395,20 +395,19 @@ export const Invoice = {
|
|||||||
columnWidth: 200,
|
columnWidth: 200,
|
||||||
value: (objectData) => {
|
value: (objectData) => {
|
||||||
const invoiceAmount = objectData?.invoiceAmount || 0
|
const invoiceAmount = objectData?.invoiceAmount || 0
|
||||||
|
if (!invoiceAmount) return 0
|
||||||
if (objectData?.taxRate?.rateType == 'percentage') {
|
if (objectData?.taxRate?.rateType == 'percentage') {
|
||||||
return (
|
return (
|
||||||
(invoiceAmount * (1 + objectData?.taxRate?.rate / 100)).toFixed(
|
(invoiceAmount * (1 + objectData?.taxRate?.rate / 100)).toFixed(
|
||||||
2
|
2
|
||||||
) || undefined
|
) || 0
|
||||||
)
|
)
|
||||||
} else if (objectData?.taxRate?.rateType == 'amount') {
|
} else if (objectData?.taxRate?.rateType == 'amount') {
|
||||||
return (
|
return (
|
||||||
(invoiceAmount + objectData?.taxRate?.rate).toFixed(2) ||
|
(invoiceAmount + objectData?.taxRate?.rate).toFixed(2) || 0
|
||||||
undefined
|
|
||||||
)
|
)
|
||||||
} else {
|
|
||||||
return invoiceAmount || 0
|
|
||||||
}
|
}
|
||||||
|
return invoiceAmount
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@ -505,20 +504,19 @@ export const Invoice = {
|
|||||||
columnWidth: 200,
|
columnWidth: 200,
|
||||||
value: (objectData) => {
|
value: (objectData) => {
|
||||||
const invoiceAmount = objectData?.invoiceAmount || 0
|
const invoiceAmount = objectData?.invoiceAmount || 0
|
||||||
|
if (!invoiceAmount) return 0
|
||||||
if (objectData?.taxRate?.rateType == 'percentage') {
|
if (objectData?.taxRate?.rateType == 'percentage') {
|
||||||
return (
|
return (
|
||||||
(invoiceAmount * (1 + objectData?.taxRate?.rate / 100)).toFixed(
|
(invoiceAmount * (1 + objectData?.taxRate?.rate / 100)).toFixed(
|
||||||
2
|
2
|
||||||
) || undefined
|
) || 0
|
||||||
)
|
)
|
||||||
} else if (objectData?.taxRate?.rateType == 'amount') {
|
} else if (objectData?.taxRate?.rateType == 'amount') {
|
||||||
return (
|
return (
|
||||||
(invoiceAmount + objectData?.taxRate?.rate).toFixed(2) ||
|
(invoiceAmount + objectData?.taxRate?.rate).toFixed(2) || 0
|
||||||
undefined
|
|
||||||
)
|
)
|
||||||
} else {
|
|
||||||
return invoiceAmount || 0
|
|
||||||
}
|
}
|
||||||
|
return invoiceAmount
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
@ -370,24 +370,20 @@ export const OrderItem = {
|
|||||||
columnWidth: 175,
|
columnWidth: 175,
|
||||||
value: (objectData) => {
|
value: (objectData) => {
|
||||||
const totalAmount = objectData?.itemAmount * objectData?.quantity || 0
|
const totalAmount = objectData?.itemAmount * objectData?.quantity || 0
|
||||||
|
if (!totalAmount) return 0
|
||||||
if (objectData?.taxRate?.rateType == 'percentage') {
|
if (objectData?.taxRate?.rateType == 'percentage') {
|
||||||
if (objectData?.quantity == undefined || objectData?.quantity == 0) {
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
(
|
(
|
||||||
(totalAmount || 0) *
|
totalAmount *
|
||||||
(1 + objectData?.taxRate?.rate / 100)
|
(1 + objectData?.taxRate?.rate / 100)
|
||||||
).toFixed(2) || undefined
|
).toFixed(2) || 0
|
||||||
)
|
)
|
||||||
} else if (objectData?.taxRate?.rateType == 'amount') {
|
} else if (objectData?.taxRate?.rateType == 'amount') {
|
||||||
return (
|
return (
|
||||||
((totalAmount || 0) + objectData?.taxRate?.rate).toFixed(2) ||
|
(totalAmount + objectData?.taxRate?.rate).toFixed(2) || 0
|
||||||
undefined
|
|
||||||
)
|
)
|
||||||
} else {
|
|
||||||
return totalAmount || 0
|
|
||||||
}
|
}
|
||||||
|
return totalAmount
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@ -155,14 +155,13 @@ export const Part = {
|
|||||||
columnWidth: 150,
|
columnWidth: 150,
|
||||||
value: (objectData) => {
|
value: (objectData) => {
|
||||||
const cost = objectData?.cost
|
const cost = objectData?.cost
|
||||||
if (!cost) return undefined
|
if (!cost) return 0
|
||||||
if (objectData?.costTaxRate?.rateType == 'percentage') {
|
if (objectData?.costTaxRate?.rateType == 'percentage') {
|
||||||
return (
|
return (
|
||||||
(cost * (1 + objectData?.costTaxRate?.rate / 100)).toFixed(2) ||
|
(cost * (1 + objectData?.costTaxRate?.rate / 100)).toFixed(2) || 0
|
||||||
undefined
|
|
||||||
)
|
)
|
||||||
} else if (objectData?.costTaxRate?.rateType == 'amount') {
|
} else if (objectData?.costTaxRate?.rateType == 'amount') {
|
||||||
return (cost + objectData?.costTaxRate?.rate).toFixed(2) || undefined
|
return (cost + objectData?.costTaxRate?.rate).toFixed(2) || 0
|
||||||
}
|
}
|
||||||
return cost
|
return cost
|
||||||
}
|
}
|
||||||
@ -241,16 +240,13 @@ export const Part = {
|
|||||||
} else {
|
} else {
|
||||||
price = objectData?.price
|
price = objectData?.price
|
||||||
}
|
}
|
||||||
if (!price) return undefined
|
if (!price) return 0
|
||||||
if (objectData?.priceTaxRate?.rateType == 'percentage') {
|
if (objectData?.priceTaxRate?.rateType == 'percentage') {
|
||||||
return (
|
return (
|
||||||
(price * (1 + objectData?.priceTaxRate?.rate / 100)).toFixed(2) ||
|
(price * (1 + objectData?.priceTaxRate?.rate / 100)).toFixed(2) || 0
|
||||||
undefined
|
|
||||||
)
|
)
|
||||||
} else if (objectData?.priceTaxRate?.rateType == 'amount') {
|
} else if (objectData?.priceTaxRate?.rateType == 'amount') {
|
||||||
return (
|
return (price + objectData?.priceTaxRate?.rate).toFixed(2) || 0
|
||||||
(price + objectData?.priceTaxRate?.rate).toFixed(2) || undefined
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
return price
|
return price
|
||||||
}
|
}
|
||||||
|
|||||||
@ -201,11 +201,11 @@ export const PartSku = {
|
|||||||
if (!objectData?.overrideCost) return undefined
|
if (!objectData?.overrideCost) return undefined
|
||||||
const cost = objectData?.cost
|
const cost = objectData?.cost
|
||||||
const taxRate = objectData?.costTaxRate
|
const taxRate = objectData?.costTaxRate
|
||||||
if (!cost) return undefined
|
if (!cost) return 0
|
||||||
if (taxRate?.rateType == 'percentage') {
|
if (taxRate?.rateType == 'percentage') {
|
||||||
return (cost * (1 + taxRate?.rate / 100)).toFixed(2) || undefined
|
return (cost * (1 + taxRate?.rate / 100)).toFixed(2) || 0
|
||||||
} else if (taxRate?.rateType == 'amount') {
|
} else if (taxRate?.rateType == 'amount') {
|
||||||
return (cost + taxRate?.rate).toFixed(2) || undefined
|
return (cost + taxRate?.rate).toFixed(2) || 0
|
||||||
}
|
}
|
||||||
return cost
|
return cost
|
||||||
},
|
},
|
||||||
@ -276,13 +276,13 @@ export const PartSku = {
|
|||||||
} else {
|
} else {
|
||||||
price = objectData?.price
|
price = objectData?.price
|
||||||
}
|
}
|
||||||
if (price == null) return undefined
|
if (!price) return 0
|
||||||
const taxRate =
|
const taxRate =
|
||||||
objectData?.priceTaxRate ?? objectData?.part?.priceTaxRate
|
objectData?.priceTaxRate ?? objectData?.part?.priceTaxRate
|
||||||
if (taxRate?.rateType == 'percentage') {
|
if (taxRate?.rateType == 'percentage') {
|
||||||
return (price * (1 + taxRate?.rate / 100)).toFixed(2) || undefined
|
return (price * (1 + taxRate?.rate / 100)).toFixed(2) || 0
|
||||||
} else if (taxRate?.rateType == 'amount') {
|
} else if (taxRate?.rateType == 'amount') {
|
||||||
return (price + taxRate?.rate).toFixed(2) || undefined
|
return (price + taxRate?.rate).toFixed(2) || 0
|
||||||
}
|
}
|
||||||
return price
|
return price
|
||||||
},
|
},
|
||||||
|
|||||||
@ -212,11 +212,11 @@ export const ProductSku = {
|
|||||||
if (!objectData?.overrideCost) return undefined
|
if (!objectData?.overrideCost) return undefined
|
||||||
const cost = objectData?.cost
|
const cost = objectData?.cost
|
||||||
const taxRate = objectData?.costTaxRate
|
const taxRate = objectData?.costTaxRate
|
||||||
if (!cost) return undefined
|
if (!cost) return 0
|
||||||
if (taxRate?.rateType == 'percentage') {
|
if (taxRate?.rateType == 'percentage') {
|
||||||
return (cost * (1 + taxRate?.rate / 100)).toFixed(2) || undefined
|
return (cost * (1 + taxRate?.rate / 100)).toFixed(2) || 0
|
||||||
} else if (taxRate?.rateType == 'amount') {
|
} else if (taxRate?.rateType == 'amount') {
|
||||||
return (cost + taxRate?.rate).toFixed(2) || undefined
|
return (cost + taxRate?.rate).toFixed(2) || 0
|
||||||
}
|
}
|
||||||
return cost
|
return cost
|
||||||
},
|
},
|
||||||
@ -289,13 +289,13 @@ export const ProductSku = {
|
|||||||
} else {
|
} else {
|
||||||
price = objectData?.price
|
price = objectData?.price
|
||||||
}
|
}
|
||||||
if (price == null) return undefined
|
if (!price) return 0
|
||||||
const taxRate =
|
const taxRate =
|
||||||
objectData?.priceTaxRate ?? objectData?.product?.priceTaxRate
|
objectData?.priceTaxRate ?? objectData?.product?.priceTaxRate
|
||||||
if (taxRate?.rateType == 'percentage') {
|
if (taxRate?.rateType == 'percentage') {
|
||||||
return (price * (1 + taxRate?.rate / 100)).toFixed(2) || undefined
|
return (price * (1 + taxRate?.rate / 100)).toFixed(2) || 0
|
||||||
} else if (taxRate?.rateType == 'amount') {
|
} else if (taxRate?.rateType == 'amount') {
|
||||||
return (price + taxRate?.rate).toFixed(2) || undefined
|
return (price + taxRate?.rate).toFixed(2) || 0
|
||||||
}
|
}
|
||||||
return price
|
return price
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user