Refactor Part and Product models to change 'disabled' property to 'readOnly' for margin fields. Implement value calculation for margin based on price and cost when priceMode is 'amount', enhancing data handling and user experience.
All checks were successful
farmcontrol/farmcontrol-ui/pipeline/head This commit looks good

This commit is contained in:
Tom Butcher 2026-06-21 23:30:36 +01:00
parent 156d2a8baf
commit 8fbcc67230
2 changed files with 26 additions and 2 deletions

View File

@ -224,11 +224,23 @@ export const Part = {
label: 'Margin', label: 'Margin',
required: true, required: true,
type: 'number', type: 'number',
disabled: (objectData) => objectData?.priceMode == 'amount', readOnly: (objectData) => objectData?.priceMode == 'amount',
suffix: '%', suffix: '%',
min: 0, min: 0,
max: 100, max: 100,
step: 0.01, step: 0.01,
value: (objectData) => {
const priceMode = objectData?.priceMode
const cost = objectData?.cost
if (priceMode == 'amount') {
const price = objectData?.price
if (price != null && cost != null) {
return Number(((price / cost - 1) * 100).toFixed(2)) || undefined
}
return undefined
}
return objectData?.margin
},
columnWidth: 85 columnWidth: 85
}, },
{ {

View File

@ -254,11 +254,23 @@ export const Product = {
label: 'Margin', label: 'Margin',
required: true, required: true,
type: 'number', type: 'number',
disabled: (objectData) => objectData?.priceMode == 'amount', readOnly: (objectData) => objectData?.priceMode == 'amount',
suffix: '%', suffix: '%',
min: 0, min: 0,
max: 100, max: 100,
step: 0.01, step: 0.01,
value: (objectData) => {
const priceMode = objectData?.priceMode
const cost = objectData?.cost
if (priceMode == 'amount') {
const price = objectData?.price
if (price != null && cost != null) {
return Number(((price / cost - 1) * 100).toFixed(2)) || undefined
}
return undefined
}
return objectData?.margin
},
columnWidth: 85 columnWidth: 85
}, },
{ {