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