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

View File

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

View File

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