Improved product creation.
Some checks are pending
farmcontrol/farmcontrol-ui/pipeline/head Build started...

This commit is contained in:
Tom Butcher 2026-06-19 21:49:53 +01:00
parent 53dce0e024
commit 696b457978
2 changed files with 30 additions and 20 deletions

View File

@ -25,7 +25,13 @@ const NewProduct = ({ onOk, defaultValues }) => {
visibleProperties={{
priceMode: false,
margin: false,
amount: false
amount: false,
priceTaxRate: false,
cost: false,
costTaxRate: false,
costWithTax: false,
price: false,
priceWithTax: false
}}
/>
)
@ -44,7 +50,13 @@ const NewProduct = ({ onOk, defaultValues }) => {
visibleProperties={{
priceMode: true,
margin: true,
amount: true
amount: true,
priceTaxRate: true,
cost: true,
costTaxRate: true,
costWithTax: true,
price: true,
priceWithTax: true
}}
/>
)
@ -73,6 +85,7 @@ const NewProduct = ({ onOk, defaultValues }) => {
bordered={false}
visibleProperties={{
_id: false,
_reference: false,
createdAt: false,
updatedAt: false
}}

View File

@ -178,7 +178,7 @@ export const Product = {
{
name: 'cost',
label: 'Cost',
required: false,
required: true,
type: 'number',
prefix: '£',
min: 0,
@ -188,7 +188,7 @@ export const Product = {
{
name: 'costWithTax',
label: 'Cost w/ Tax',
required: false,
required: true,
readOnly: true,
type: 'number',
prefix: '£',
@ -197,14 +197,13 @@ export const Product = {
columnWidth: 150,
value: (objectData) => {
const cost = objectData?.cost
if (!cost) return undefined
if (!cost) return 0
if (objectData?.costTaxRate?.rateType == 'percentage') {
return (
(cost * (1 + objectData?.costTaxRate?.rate / 100)).toFixed(2) ||
undefined
(cost * (1 + objectData?.costTaxRate?.rate / 100)).toFixed(2) || 0
)
} else if (objectData?.costTaxRate?.rateType == 'amount') {
return (cost + objectData?.costTaxRate?.rate).toFixed(2) || undefined
return (cost + objectData?.costTaxRate?.rate).toFixed(2) || 0
}
return cost
}
@ -212,7 +211,7 @@ export const Product = {
{
name: 'costTaxRate',
label: 'Cost Tax Rate',
required: false,
required: true,
type: 'object',
objectType: 'taxRate',
showHyperlink: true,
@ -221,14 +220,14 @@ export const Product = {
{
name: 'priceMode',
label: 'Price Mode',
required: false,
required: true,
type: 'priceMode',
columnWidth: 150
},
{
name: 'price',
label: 'Price',
required: false,
required: true,
type: 'number',
prefix: '£',
min: 0,
@ -243,8 +242,7 @@ export const Product = {
objectData?.cost != null
) {
return (
(objectData.cost * (1 + objectData.margin / 100)).toFixed(2) ||
undefined
(objectData.cost * (1 + objectData.margin / 100)).toFixed(2) || 0
)
}
return objectData?.price
@ -253,7 +251,7 @@ export const Product = {
{
name: 'margin',
label: 'Margin',
required: false,
required: true,
type: 'number',
disabled: (objectData) => objectData?.priceMode == 'amount',
suffix: '%',
@ -265,7 +263,7 @@ export const Product = {
{
name: 'priceWithTax',
label: 'Price w/ Tax',
required: false,
required: true,
readOnly: true,
type: 'number',
prefix: '£',
@ -283,14 +281,13 @@ export const Product = {
} else {
price = objectData?.price
}
if (!price) return undefined
if (!price) return 0
if (objectData?.priceTaxRate?.rateType == 'percentage') {
return (
(price * (1 + objectData?.priceTaxRate?.rate / 100)).toFixed(2) ||
undefined
(price * (1 + objectData?.priceTaxRate?.rate / 100)).toFixed(2) || 0
)
} else if (objectData?.priceTaxRate?.rateType == 'amount') {
return (price + objectData?.priceTaxRate?.rate).toFixed(2) || undefined
return (price + objectData?.priceTaxRate?.rate).toFixed(2) || 0
}
return price
}
@ -298,7 +295,7 @@ export const Product = {
{
name: 'priceTaxRate',
label: 'Price Tax Rate',
required: false,
required: true,
type: 'object',
objectType: 'taxRate',
showHyperlink: true,