fix product price

This commit is contained in:
2026-06-27 18:06:44 +03:30
parent 9e0cefebf2
commit 0c36917735
3 changed files with 23 additions and 29 deletions
+15 -7
View File
@@ -84,8 +84,20 @@ export function hasProductUnitWeight(product?: ProductUnitSource | null) {
return amount > 0
}
/** ضریب قیمت — محصول بدون وزن قطعه همیشه ۱ */
/** ضریب قیمت — فقط «متغیر» بدون مرجع اتوماتیک: قیمت هر گرم × وزن */
export function productPriceAmountFactor(product?: ProductUnitSource | null) {
if (product?.reading_method) {
return 1
}
if (isCountBasedProduct(product)) {
return 1
}
if (Number(product?.direct_price ?? 0) !== 0) {
return 1
}
if (hasProductUnitWeight(product)) {
const amount = Number(product?.amount ?? 0)
return amount > 0 ? amount : 1
@@ -358,9 +370,7 @@ export function resolveProductTradeBuyUnitPrice(product?: Product | null) {
}
const basePrice = (product.price ?? 0) + (product.cash_fee_buy ?? 0)
return product.direct_price === 0
? basePrice * (product.amount ?? 0)
: basePrice
return basePrice * productPriceAmountFactor(product)
}
export function resolveProductTradeSellUnitPrice(product?: Product | null) {
@@ -369,9 +379,7 @@ export function resolveProductTradeSellUnitPrice(product?: Product | null) {
}
const basePrice = (product.price ?? 0) - (product.cash_fee_sell ?? 0)
return product.direct_price === 0
? basePrice * (product.amount ?? 0)
: basePrice
return basePrice * productPriceAmountFactor(product)
}
function getDefaultTypeDealOptions(context?: ProductDealMethodContext | null, isBuy = true): SelectItem[] {
+1 -3
View File
@@ -116,9 +116,7 @@ export function getProductBuyPrice(product: Product): number {
}
const withFee = base + fee
return product.direct_price === 0
? withFee * productPriceAmountFactor(product)
: withFee
return withFee * productPriceAmountFactor(product)
}
function getProductBaseSellPrice(product: Product): number {
@@ -306,6 +306,7 @@ import {
shouldShowProductDealMethodSelect,
resolveProductTradeBuyUnitPrice,
resolveProductTradeSellUnitPrice,
productPriceAmountFactor,
formatProductWeightAmount,
getProductQuantityUnit,
getProductTotalWeightLabel,
@@ -409,9 +410,7 @@ const buyTotalPrice = computed(() => {
if (!item) return 0
const basePrice = (item.price ?? 0) + (item.cash_fee_buy ?? 0)
return item.direct_price === 0
? basePrice * (item.amount ?? 0)
: basePrice
return basePrice * productPriceAmountFactor(item)
})
const sellTotalPrice = computed(() => {
@@ -420,9 +419,7 @@ const sellTotalPrice = computed(() => {
const basePrice = (item.price ?? 0) - (item.cash_fee_sell ?? 0)
return item.direct_price === 0
? basePrice * (item.amount ?? 0)
: basePrice
return basePrice * productPriceAmountFactor(item)
})
const buyFee = computed(() => ((props?.ProductItem?.amount * (props?.ProductItem?.percent_fee_buy ?? 0) * (props?.ProductItem?.price ?? 0)).toFixed(0)))
const sellFee = computed(() => ((props?.ProductItem?.amount * (props?.ProductItem?.percent_fee_sell ?? 0) * (props?.ProductItem?.sellPrice ?? 0)).toFixed(0)))
@@ -758,12 +755,8 @@ function calculateCash(val: number) {
// form.value.goldVazn = parseFloat((val * (( props?.ProductItem?.price) + (props?.ProductItem?.cash_fee_buy)))/lastPrice.value?.buy).toFixed(2)
if (isBuy.value) {
if (val){
if(props?.ProductItem?.direct_price === 0){
form.value.goldCash = parseFloat(val * props?.ProductItem?.amount * (props?.ProductItem?.price + props?.ProductItem?.cash_fee_buy)).toFixed(0)
}
else {
form.value.goldCash = parseFloat(val * (props?.ProductItem?.price + props?.ProductItem?.cash_fee_buy)).toFixed(0)
}
const unitPrice = (props?.ProductItem?.price ?? 0) + (props?.ProductItem?.cash_fee_buy ?? 0)
form.value.goldCash = parseFloat(String(val * unitPrice * productPriceAmountFactor(props?.ProductItem))).toFixed(0)
}
else {
form.value.goldCash = 0
@@ -772,13 +765,8 @@ function calculateCash(val: number) {
}
else {
if (val){
if(props?.ProductItem?.direct_price === 0){
form.value.goldCash = parseFloat(val * props?.ProductItem?.amount * (props?.ProductItem?.price - props?.ProductItem?.cash_fee_sell)).toFixed(0)
}
else{
form.value.goldCash = parseFloat(val * (props?.ProductItem?.price - props?.ProductItem?.cash_fee_sell)).toFixed(0)
}
const unitPrice = (props?.ProductItem?.price ?? 0) - (props?.ProductItem?.cash_fee_sell ?? 0)
form.value.goldCash = parseFloat(String(val * unitPrice * productPriceAmountFactor(props?.ProductItem))).toFixed(0)
}
else{
form.value.goldCash = 0