Refactor Filament, FilamentSku, PartSku, and ProductSku models to improve code readability by restructuring columns, filters, and sorters. Enhance Filament model with a visibility condition for the divider. Clean up formatting for better consistency across models.
All checks were successful
farmcontrol/farmcontrol-ui/pipeline/head This commit looks good

This commit is contained in:
Tom Butcher 2026-03-08 02:07:36 +00:00
parent 2ca29d1ef5
commit 7611d11655
3 changed files with 90 additions and 39 deletions

View File

@ -18,7 +18,8 @@ export const FilamentSku = {
default: true,
row: true,
icon: InfoCircleIcon,
url: (_id) => `/dashboard/management/filamentskus/info?filamentSkuId=${_id}`
url: (_id) =>
`/dashboard/management/filamentskus/info?filamentSkuId=${_id}`
},
{
name: 'reload',
@ -69,9 +70,36 @@ export const FilamentSku = {
}
],
url: (id) => `/dashboard/management/filamentskus/info?filamentSkuId=${id}`,
columns: ['_reference', 'barcode', 'filament', 'name', 'color', 'overrideCost', 'cost', 'createdAt', 'updatedAt'],
filters: ['_id', 'barcode', 'filament', 'filament._id', 'name', 'color', 'cost'],
sorters: ['barcode', 'filament', 'name', 'color', 'cost', 'createdAt', 'updatedAt'],
columns: [
'_reference',
'name',
'filament',
'barcode',
'color',
'overrideCost',
'cost',
'createdAt',
'updatedAt'
],
filters: [
'_id',
'barcode',
'filament',
'filament._id',
'name',
'color',
'cost'
],
sorters: [
'barcode',
'filament',
'name',
'color',
'cost',
'createdAt',
'updatedAt'
],
properties: [
{
name: '_id',
@ -160,9 +188,7 @@ export const FilamentSku = {
const taxRate = objectData?.costTaxRate
if (!cost) return undefined
if (taxRate?.rateType == 'percentage') {
return (
(cost * (1 + taxRate?.rate / 100)).toFixed(2) || undefined
)
return (cost * (1 + taxRate?.rate / 100)).toFixed(2) || undefined
} else if (taxRate?.rateType == 'amount') {
return (cost + taxRate?.rate).toFixed(2) || undefined
}

View File

@ -71,9 +71,10 @@ export const PartSku = {
url: (id) => `/dashboard/management/partskus/info?partSkuId=${id}`,
columns: [
'_reference',
'barcode',
'part',
'name',
'part',
'barcode',
'overrideCost',
'cost',
'overridePrice',
@ -82,7 +83,15 @@ export const PartSku = {
'updatedAt'
],
filters: ['_id', 'barcode', 'part', 'part._id', 'name', 'cost', 'price'],
sorters: ['barcode', 'part', 'name', 'cost', 'price', 'createdAt', 'updatedAt'],
sorters: [
'barcode',
'part',
'name',
'cost',
'price',
'createdAt',
'updatedAt'
],
properties: [
{
name: '_id',
@ -220,9 +229,7 @@ export const PartSku = {
margin !== null &&
cost != null
) {
return (
(cost * (1 + margin / 100)).toFixed(2) || undefined
)
return (cost * (1 + margin / 100)).toFixed(2) || undefined
}
return objectData?.price
}
@ -245,17 +252,14 @@ export const PartSku = {
? objectData?.cost
: objectData?.part?.cost
const margin = objectData?.margin ?? objectData?.part?.margin
if (
priceMode == 'margin' &&
margin != null &&
cost != null
) {
if (priceMode == 'margin' && margin != null && cost != null) {
price = cost * (1 + margin / 100)
} else {
price = objectData?.price
}
if (price == null) return undefined
const taxRate = objectData?.priceTaxRate ?? objectData?.part?.priceTaxRate
const taxRate =
objectData?.priceTaxRate ?? objectData?.part?.priceTaxRate
if (taxRate?.rateType == 'percentage') {
return (price * (1 + taxRate?.rate / 100)).toFixed(2) || undefined
} else if (taxRate?.rateType == 'amount') {

View File

@ -69,9 +69,36 @@ export const ProductSku = {
}
],
url: (id) => `/dashboard/management/productskus/info?productSkuId=${id}`,
columns: ['_reference', 'barcode', 'product', 'name', 'overrideCost', 'cost', 'overridePrice', 'price', 'createdAt', 'updatedAt'],
filters: ['_id', 'barcode', 'product', 'product._id', 'name', 'cost', 'price'],
sorters: ['barcode', 'product', 'name', 'cost', 'price', 'createdAt', 'updatedAt'],
columns: [
'_reference',
'name',
'product',
'barcode',
'overrideCost',
'cost',
'overridePrice',
'price',
'createdAt',
'updatedAt'
],
filters: [
'_id',
'barcode',
'product',
'product._id',
'name',
'cost',
'price'
],
sorters: [
'barcode',
'product',
'name',
'cost',
'price',
'createdAt',
'updatedAt'
],
properties: [
{
name: '_id',
@ -87,6 +114,7 @@ export const ProductSku = {
type: 'dateTime',
readOnly: true
},
{
name: 'name',
label: 'Name',
@ -167,9 +195,7 @@ export const ProductSku = {
const taxRate = objectData?.costTaxRate
if (!cost) return undefined
if (taxRate?.rateType == 'percentage') {
return (
(cost * (1 + taxRate?.rate / 100)).toFixed(2) || undefined
)
return (cost * (1 + taxRate?.rate / 100)).toFixed(2) || undefined
} else if (taxRate?.rateType == 'amount') {
return (cost + taxRate?.rate).toFixed(2) || undefined
}
@ -200,7 +226,8 @@ export const ProductSku = {
objectData?.overridePrice && objectData?.priceMode == 'margin',
value: (objectData) => {
if (!objectData?.overridePrice) return undefined
const priceMode = objectData?.priceMode ?? objectData?.product?.priceMode
const priceMode =
objectData?.priceMode ?? objectData?.product?.priceMode
const cost = objectData?.overrideCost
? objectData?.cost
: objectData?.product?.cost
@ -211,9 +238,7 @@ export const ProductSku = {
margin !== null &&
cost != null
) {
return (
(cost * (1 + margin / 100)).toFixed(2) || undefined
)
return (cost * (1 + margin / 100)).toFixed(2) || undefined
}
return objectData?.price
}
@ -231,26 +256,22 @@ export const ProductSku = {
value: (objectData) => {
if (!objectData?.overridePrice) return undefined
let price
const priceMode = objectData?.priceMode ?? objectData?.product?.priceMode
const priceMode =
objectData?.priceMode ?? objectData?.product?.priceMode
const cost = objectData?.overrideCost
? objectData?.cost
: objectData?.product?.cost
const margin = objectData?.margin ?? objectData?.product?.margin
if (
priceMode == 'margin' &&
margin != null &&
cost != null
) {
if (priceMode == 'margin' && margin != null && cost != null) {
price = cost * (1 + margin / 100)
} else {
price = objectData?.price
}
if (price == null) return undefined
const taxRate = objectData?.priceTaxRate ?? objectData?.product?.priceTaxRate
const taxRate =
objectData?.priceTaxRate ?? objectData?.product?.priceTaxRate
if (taxRate?.rateType == 'percentage') {
return (
(price * (1 + taxRate?.rate / 100)).toFixed(2) || undefined
)
return (price * (1 + taxRate?.rate / 100)).toFixed(2) || undefined
} else if (taxRate?.rateType == 'amount') {
return (price + taxRate?.rate).toFixed(2) || undefined
}