fix some bugs
This commit is contained in:
@@ -603,14 +603,54 @@ export function getTradePriceUnitLabel() {
|
||||
return useSettingsStore().metalTypeLabel
|
||||
}
|
||||
|
||||
/** برچسب قیمت حین معامله — معامله مقداری: نام و واحد همان محصول */
|
||||
export type TransactionTradeProductSource = {
|
||||
product?: (ProductUnitSource & { title?: string | null }) | null
|
||||
wallet?: { product?: (ProductUnitSource & { title?: string | null }) | null } | null
|
||||
title?: string | null
|
||||
}
|
||||
|
||||
/** محصول معاملهشده — نه لزوماً همان کیف پول (مثلاً خرید مفتول با کیف کاتد) */
|
||||
export function resolveTransactionTradeProduct(
|
||||
item?: TransactionTradeProductSource | null,
|
||||
): (ProductUnitSource & { title?: string | null }) | null {
|
||||
if (!item) {
|
||||
return null
|
||||
}
|
||||
|
||||
const fromTransaction = item.product
|
||||
if ((fromTransaction?.title ?? '').trim()) {
|
||||
return fromTransaction ?? null
|
||||
}
|
||||
|
||||
const title = (item.title ?? '').trim()
|
||||
const match = title.match(/^(?:خرید|فروش)\s+(.+)$/u)
|
||||
if (match?.[1]?.trim()) {
|
||||
return {
|
||||
...(item.wallet?.product ?? {}),
|
||||
title: match[1].trim(),
|
||||
}
|
||||
}
|
||||
|
||||
return item.wallet?.product ?? null
|
||||
}
|
||||
|
||||
/** برچسب قیمت حین معامله — نام و واحد همان محصول معاملهشده */
|
||||
export function getTransactionTradePriceLabel(product?: (ProductUnitSource & { title?: string | null }) | null) {
|
||||
if (product && usesQuantityTrade(product)) {
|
||||
if (!product) {
|
||||
return `قیمت هر ${getWeightUnit()} ${getTradePriceUnitLabel()}`
|
||||
}
|
||||
|
||||
const title = (product.title ?? '').trim()
|
||||
|
||||
if (usesQuantityTrade(product)) {
|
||||
const unit = getProductQuantityUnit(product)
|
||||
const title = (product.title ?? '').trim()
|
||||
return title ? `قیمت هر ${unit} ${title}` : `قیمت هر ${unit}`
|
||||
}
|
||||
|
||||
if (title) {
|
||||
return `قیمت هر ${getWeightUnit()} ${title}`
|
||||
}
|
||||
|
||||
return `قیمت هر ${getWeightUnit()} ${getTradePriceUnitLabel()}`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user