fix bug 2
This commit is contained in:
@@ -11,4 +11,6 @@ export interface last {
|
||||
sell: number
|
||||
buy: number
|
||||
price_last: number
|
||||
/** آخرین مظنه ذخیرهشده در جدول prices — برای fallback محصول */
|
||||
last_historical?: number
|
||||
}
|
||||
@@ -58,13 +58,19 @@ export type ProductEditorPricePreview =
|
||||
|
||||
function resolveStoredFallbackPrice(
|
||||
storedPrice: number | null | undefined,
|
||||
useLastPriceIfZero: boolean | undefined
|
||||
useLastPriceIfZero: boolean | undefined,
|
||||
lastHistoricalPrice?: number | null
|
||||
): number {
|
||||
if (!useLastPriceIfZero) {
|
||||
return 0
|
||||
}
|
||||
|
||||
return Number(storedPrice) || 0
|
||||
const stored = Number(storedPrice) || 0
|
||||
if (stored > 0) {
|
||||
return stored
|
||||
}
|
||||
|
||||
return Number(lastHistoricalPrice) || 0
|
||||
}
|
||||
|
||||
export function computeProductEditorPricePreview(input: {
|
||||
@@ -78,7 +84,7 @@ export function computeProductEditorPricePreview(input: {
|
||||
methodOption: string
|
||||
meltedPriceOption: MeltedPriceSource
|
||||
pricesData: MethodePrices[]
|
||||
appLastPrice?: (Partial<last> & { price?: number }) | null
|
||||
appLastPrice?: (Partial<last> & { price?: number; last_historical?: number }) | null
|
||||
}): ProductEditorPricePreview {
|
||||
const offsetPercent = Number(input.form.price_offset_percent ?? 0)
|
||||
const melted = isMeltedTradeGroup(input.form.group_type)
|
||||
@@ -100,13 +106,19 @@ export function computeProductEditorPricePreview(input: {
|
||||
source: 'قیمت صفحه اصلی اپ'
|
||||
}
|
||||
}
|
||||
const stored = Number(input.form.price) || 0
|
||||
const fallback = resolveStoredFallbackPrice(
|
||||
input.form.price,
|
||||
input.form.use_last_price_if_zero ?? false
|
||||
input.form.use_last_price_if_zero ?? false,
|
||||
input.appLastPrice?.last_historical
|
||||
)
|
||||
return fallback > 0
|
||||
? { status: 'ready', amount: fallback, source: 'آخرین قیمت ذخیرهشده' }
|
||||
: { status: 'empty', message: 'قیمت provider صفر است' }
|
||||
if (fallback > 0) {
|
||||
const amount = stored > 0
|
||||
? fallback
|
||||
: adjustedProductPrice(fallback, 0, offsetPercent)
|
||||
return { status: 'ready', amount, source: 'آخرین قیمت ذخیرهشده' }
|
||||
}
|
||||
return { status: 'empty', message: 'قیمت provider صفر است' }
|
||||
}
|
||||
|
||||
if (!input.form.reading_method) {
|
||||
@@ -123,7 +135,8 @@ export function computeProductEditorPricePreview(input: {
|
||||
}
|
||||
const fallback = resolveStoredFallbackPrice(
|
||||
input.form.price,
|
||||
input.form.use_last_price_if_zero ?? false
|
||||
input.form.use_last_price_if_zero ?? false,
|
||||
input.appLastPrice?.last_historical
|
||||
)
|
||||
return fallback > 0
|
||||
? { status: 'ready', amount: fallback, source: 'آخرین قیمت ذخیرهشده' }
|
||||
@@ -151,7 +164,8 @@ export function computeProductEditorPricePreview(input: {
|
||||
}
|
||||
const fallback = resolveStoredFallbackPrice(
|
||||
input.form.price,
|
||||
input.form.use_last_price_if_zero ?? false
|
||||
input.form.use_last_price_if_zero ?? false,
|
||||
input.appLastPrice?.last_historical
|
||||
)
|
||||
return fallback > 0
|
||||
? { status: 'ready', amount: fallback, source: 'آخرین قیمت ذخیرهشده' }
|
||||
|
||||
Reference in New Issue
Block a user