price handling
This commit is contained in:
@@ -7,6 +7,22 @@ function productUsesLastPriceIfZero(product: Product): boolean {
|
||||
return Boolean(product.use_last_price_if_zero)
|
||||
}
|
||||
|
||||
function hasReferenceReadingMethod(product: Product): boolean {
|
||||
return Boolean(product.reading_method)
|
||||
}
|
||||
|
||||
/** قیمت پایه محصولات با reading_method — بدون fallback وقتی تیک «قیمت صفر از مرجع» خاموش است */
|
||||
function getReferenceProductBaseBuyPrice(product: Product): number {
|
||||
const storedUnit = Number(product.price ?? 0)
|
||||
const useLast = productUsesLastPriceIfZero(product)
|
||||
|
||||
if (!useLast) {
|
||||
return storedUnit > 0 ? storedUnit : 0
|
||||
}
|
||||
|
||||
return storedUnit
|
||||
}
|
||||
|
||||
export function resolvePriceOffsetRatio(offsetPercent?: number | null) {
|
||||
const offset = Number(offsetPercent ?? 0)
|
||||
if (!offset) {
|
||||
@@ -74,6 +90,10 @@ export function getProductBaseBuyPrice(product: Product): number {
|
||||
return Number(product.price_profit ?? 0) + Number(product.price ?? 0)
|
||||
}
|
||||
|
||||
if (hasReferenceReadingMethod(product)) {
|
||||
return getReferenceProductBaseBuyPrice(product)
|
||||
}
|
||||
|
||||
return Number(product.price ?? 0)
|
||||
}
|
||||
|
||||
@@ -148,6 +168,14 @@ export function getProductSellPrice(product: Product): number {
|
||||
}
|
||||
|
||||
export function isProductPriceInactive(product: Product): boolean {
|
||||
if (
|
||||
hasReferenceReadingMethod(product)
|
||||
&& !productUsesLastPriceIfZero(product)
|
||||
&& product.reference_provider_active === false
|
||||
) {
|
||||
return true
|
||||
}
|
||||
|
||||
return getProductBaseBuyPrice(product) <= 0
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user