feat: Implement fixed sale price functionality for items
- Added a toggle for fixed sale price vs stock value in the item creation form. - Introduced validation to ensure all variants have a price greater than 0 when fixed price mode is selected. - Updated the item model to include a nullable salePrice field, which is used for sales only and does not affect GRN/FIFO/ledger. - Enhanced the GRN page to allow off-PO items and included a refresh button to update the item list without reloading the page. - Updated documentation to reflect changes in item pricing and GRN handling.
This commit is contained in:
@@ -73,3 +73,23 @@ export function validateVariantItemForm(input: {
|
||||
if (!input.hasVariants) errors.variants = "Check at least one variant category and add its values"
|
||||
return errors
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixed-price mode requires every generated variant to carry a sale price > 0
|
||||
* (docs/20 §3.1). Returns a map keyed by variant key → message; empty when valid.
|
||||
* In "stock" mode there is nothing to validate (prices are sent as null).
|
||||
*/
|
||||
export function validateVariantPrices(
|
||||
variantKeys: string[],
|
||||
priceFor: (key: string) => string,
|
||||
): Record<string, string> {
|
||||
const errors: Record<string, string> = {}
|
||||
for (const key of variantKeys) {
|
||||
const raw = priceFor(key).trim()
|
||||
const value = Number(raw)
|
||||
if (raw === "" || Number.isNaN(value) || value <= 0) {
|
||||
errors[key] = "Enter a price greater than 0"
|
||||
}
|
||||
}
|
||||
return errors
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user