体重使用稳定值,移除金额校验
This commit is contained in:
@@ -87,7 +87,7 @@ fun Float?.toSafeFloat(decimalPlaces: Int = 2): Float {
|
|||||||
*/
|
*/
|
||||||
private fun getDecimalPlaces(unitName: String?): Int {
|
private fun getDecimalPlaces(unitName: String?): Int {
|
||||||
val decimalPlaces = when (unitName) {
|
val decimalPlaces = when (unitName) {
|
||||||
"斤", "克", "公斤", "升" -> 2
|
"斤", "公斤", "升" -> 2
|
||||||
else -> 0
|
else -> 0
|
||||||
}
|
}
|
||||||
return decimalPlaces
|
return decimalPlaces
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.sw.inbound.model.response
|
|||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import com.sw.inbound.GlobalData
|
import com.sw.inbound.GlobalData
|
||||||
import com.sw.inbound.ext.toFormattedString
|
import com.sw.inbound.ext.toFormattedString
|
||||||
|
import com.sw.inbound.ext.toSafeString
|
||||||
import com.sw.inbound.model.response.SearchGoodsInfo.Record.UnitVo
|
import com.sw.inbound.model.response.SearchGoodsInfo.Record.UnitVo
|
||||||
import kotlinx.parcelize.Parcelize
|
import kotlinx.parcelize.Parcelize
|
||||||
import java.math.BigDecimal
|
import java.math.BigDecimal
|
||||||
@@ -118,15 +119,11 @@ data class GoodsInfo(
|
|||||||
return recUnitPriceTaxIn?.toFormattedString() ?: ""
|
return recUnitPriceTaxIn?.toFormattedString() ?: ""
|
||||||
}
|
}
|
||||||
|
|
||||||
var receiveCountStr: String
|
val receiveCountStr: String
|
||||||
set(value) {
|
|
||||||
// receiveCount = value.toSafeFloat()
|
|
||||||
receiveCountStr = value
|
|
||||||
}
|
|
||||||
get() {
|
get() {
|
||||||
return when (receiveCount) {
|
return when (receiveCount) {
|
||||||
0f -> ""
|
0f -> ""
|
||||||
else -> receiveCount?.toFormattedString() ?: ""
|
else -> receiveCount?.toSafeString(unitName) ?: ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,8 +33,11 @@ object SensorScaleUtils {
|
|||||||
else -> "未知"
|
else -> "未知"
|
||||||
}
|
}
|
||||||
// Timber.d("readWeight state = ${stateStr}, weight = $value")
|
// Timber.d("readWeight state = ${stateStr}, weight = $value")
|
||||||
|
// 只使用稳定值
|
||||||
|
if (state == SensorScale.STATE_STABLE) {
|
||||||
callback?.invoke(value)
|
callback?.invoke(value)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 读取鉴别率
|
* 读取鉴别率
|
||||||
@@ -66,7 +69,7 @@ object SensorScaleUtils {
|
|||||||
if (open) {
|
if (open) {
|
||||||
if (autoScale) {
|
if (autoScale) {
|
||||||
ThreadUtils.launchOnIo {
|
ThreadUtils.launchOnIo {
|
||||||
delay(2000)
|
delay(1000)
|
||||||
// 打开后需要等待后才能调用,否则会 1001 SDK未初始化
|
// 打开后需要等待后才能调用,否则会 1001 SDK未初始化
|
||||||
mSensorScale?.startContinuousRead()
|
mSensorScale?.startContinuousRead()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -283,7 +283,7 @@ fun UnadjustedView(purchaseOrderList: List<GoodsInfo>, viewModel: ReceiptViewMod
|
|||||||
productList = purchaseOrderList,
|
productList = purchaseOrderList,
|
||||||
checkedItem = checkedItem,
|
checkedItem = checkedItem,
|
||||||
onItemCheckedClick = {
|
onItemCheckedClick = {
|
||||||
viewModel.updateSelectedItem(it)
|
viewModel.updateSelectedItemWithSwitch(it)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -638,11 +638,12 @@ private fun ReceiptProductEditView(
|
|||||||
}
|
}
|
||||||
val expectAmount =
|
val expectAmount =
|
||||||
selectedItem!!.receivedNum!!.times(selectedItem!!.recUnitPriceTaxIn!!)
|
selectedItem!!.receivedNum!!.times(selectedItem!!.recUnitPriceTaxIn!!)
|
||||||
|
.toSafeFloat()
|
||||||
Timber.d("金额判断:期望金额 = $expectAmount, 实际金额 = ${selectedItem!!.recPriceExItem}")
|
Timber.d("金额判断:期望金额 = $expectAmount, 实际金额 = ${selectedItem!!.recPriceExItem}")
|
||||||
if (expectAmount != selectedItem!!.recPriceExItem) {
|
// if (expectAmount != selectedItem!!.recPriceExItem) {
|
||||||
ToastUtils.showToast("数量和金额不符,请检查后再试")
|
// ToastUtils.showToast("数量和金额不符,请检查后再试")
|
||||||
return@clickable
|
// return@clickable
|
||||||
}
|
// }
|
||||||
viewModel.updatePurchaseItem(purchaseOrder = selectedItem!!.copy(isAdjusted = true))
|
viewModel.updatePurchaseItem(purchaseOrder = selectedItem!!.copy(isAdjusted = true))
|
||||||
viewModel.updateSelectedItem(null)
|
viewModel.updateSelectedItem(null)
|
||||||
}, painter = painterResource(R.mipmap.ic_btn_confirm), contentDescription = "确定")
|
}, painter = painterResource(R.mipmap.ic_btn_confirm), contentDescription = "确定")
|
||||||
|
|||||||
@@ -776,12 +776,13 @@ private fun SelfProductEditView(
|
|||||||
ToastUtils.showToast(errInfo)
|
ToastUtils.showToast(errInfo)
|
||||||
return@CustomButton
|
return@CustomButton
|
||||||
}
|
}
|
||||||
val expectAmount = selectedItem!!.goodsCount * selectedItem!!.goodsUnitPrice
|
val expectAmount =
|
||||||
|
(selectedItem!!.goodsCount.times(selectedItem!!.goodsUnitPrice)).toSafeDouble()
|
||||||
Timber.d("金额判断:期望金额 = $expectAmount, 实际金额 = ${selectedItem!!.goodsPrice}")
|
Timber.d("金额判断:期望金额 = $expectAmount, 实际金额 = ${selectedItem!!.goodsPrice}")
|
||||||
if (expectAmount != selectedItem!!.goodsPrice) {
|
// if (expectAmount != selectedItem!!.goodsPrice) {
|
||||||
ToastUtils.showToast("数量和金额不符,请检查后再试")
|
// ToastUtils.showToast("数量和金额不符,请检查后再试")
|
||||||
return@CustomButton
|
// return@CustomButton
|
||||||
}
|
// }
|
||||||
viewModel.addPurchaseItem(selectedItem!!)
|
viewModel.addPurchaseItem(selectedItem!!)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,19 +57,19 @@ fun ReceiptUnadjustedListView(
|
|||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.width(10.dp))
|
Spacer(modifier = Modifier.width(10.dp))
|
||||||
CustomSingleRightText(
|
CustomSingleRightText(
|
||||||
modifier = Modifier.width(100.dp),
|
modifier = Modifier.width(120.dp),
|
||||||
text = "单价(元)",
|
text = "单价(元)",
|
||||||
style = AppTypography.gray96a0aaTextStyle.bold()
|
style = AppTypography.gray96a0aaTextStyle.bold()
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.width(20.dp))
|
Spacer(modifier = Modifier.width(20.dp))
|
||||||
CustomSingleRightText(
|
CustomSingleRightText(
|
||||||
modifier = Modifier.width(100.dp),
|
modifier = Modifier.width(140.dp),
|
||||||
text = "数量",
|
text = "数量",
|
||||||
style = AppTypography.gray96a0aaTextStyle.bold()
|
style = AppTypography.gray96a0aaTextStyle.bold()
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.width(20.dp))
|
Spacer(modifier = Modifier.width(20.dp))
|
||||||
CustomSingleRightText(
|
CustomSingleRightText(
|
||||||
modifier = Modifier.width(110.dp),
|
modifier = Modifier.width(120.dp),
|
||||||
text = "金额(元)",
|
text = "金额(元)",
|
||||||
style = AppTypography.gray96a0aaTextStyle.bold()
|
style = AppTypography.gray96a0aaTextStyle.bold()
|
||||||
)
|
)
|
||||||
@@ -101,19 +101,19 @@ fun ReceiptUnadjustedListView(
|
|||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.width(10.dp))
|
Spacer(modifier = Modifier.width(10.dp))
|
||||||
CustomSingleRightText(
|
CustomSingleRightText(
|
||||||
modifier = Modifier.width(100.dp),
|
modifier = Modifier.width(120.dp),
|
||||||
text = it.recUnitPriceTaxInStr,
|
text = it.recUnitPriceTaxInStr,
|
||||||
style = AppTypography.blackTextStyle
|
style = AppTypography.blackTextStyle
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.width(20.dp))
|
Spacer(modifier = Modifier.width(20.dp))
|
||||||
CustomSingleRightText(
|
CustomSingleRightText(
|
||||||
modifier = Modifier.width(100.dp),
|
modifier = Modifier.width(140.dp),
|
||||||
text = "${it.receiveCountStr}${it.unitNameStr}",
|
text = "${it.receiveCountStr}${it.unitNameStr}",
|
||||||
style = AppTypography.blackTextStyle
|
style = AppTypography.blackTextStyle
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.width(20.dp))
|
Spacer(modifier = Modifier.width(20.dp))
|
||||||
CustomSingleRightText(
|
CustomSingleRightText(
|
||||||
modifier = Modifier.width(110.dp),
|
modifier = Modifier.width(120.dp),
|
||||||
text = it.recPriceExItemStr,
|
text = it.recPriceExItemStr,
|
||||||
style = AppTypography.blackTextStyle
|
style = AppTypography.blackTextStyle
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import kotlinx.coroutines.flow.asStateFlow
|
|||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.stateIn
|
||||||
import kotlinx.coroutines.flow.update
|
import kotlinx.coroutines.flow.update
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@@ -102,6 +103,12 @@ class ReceiptViewModel @Inject constructor(
|
|||||||
_showReceiptDialog.value = showDialog
|
_showReceiptDialog.value = showDialog
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun updateSelectedItemWithSwitch(purchaseOrder: GoodsInfo?) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
updateSelectedItem(purchaseOrder)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新选中的item
|
* 更新选中的item
|
||||||
*/
|
*/
|
||||||
@@ -109,14 +116,16 @@ class ReceiptViewModel @Inject constructor(
|
|||||||
if (purchaseOrder != null) {
|
if (purchaseOrder != null) {
|
||||||
purchaseOrder.receivedNum.takeIf { it != 0f }?.let { receivedNum ->
|
purchaseOrder.receivedNum.takeIf { it != 0f }?.let { receivedNum ->
|
||||||
// 计算金额 单价不为空,并且金额没有手动输入
|
// 计算金额 单价不为空,并且金额没有手动输入
|
||||||
if (purchaseOrder.recUnitPriceTaxIn != null && purchaseOrder.recUnitPriceTaxIn == 0f && !_amountUserInput.value) {
|
// if (purchaseOrder.recUnitPriceTaxIn != null && purchaseOrder.recUnitPriceTaxIn == 0f && !_amountUserInput.value) {
|
||||||
|
if (purchaseOrder.recUnitPriceTaxIn != null && !_amountUserInput.value) {
|
||||||
val result =
|
val result =
|
||||||
receivedNum.times(purchaseOrder.recUnitPriceTaxIn!!)
|
receivedNum.times(purchaseOrder.recUnitPriceTaxIn!!)
|
||||||
purchaseOrder.recPriceExItem = result.toSafeFloat()
|
purchaseOrder.recPriceExItem = result.toSafeFloat()
|
||||||
purchaseOrder.recPriceExItemTemp = result.toFormattedString()
|
purchaseOrder.recPriceExItemTemp = result.toFormattedString()
|
||||||
}
|
}
|
||||||
// 计算单价 金额不为空,并且单价没有手动输入
|
// 计算单价 金额不为空,并且单价没有手动输入
|
||||||
if (purchaseOrder.recPriceExItem != null && purchaseOrder.recPriceExItem == 0f && !_priceUserInput.value) {
|
// if (purchaseOrder.recPriceExItem != null && purchaseOrder.recPriceExItem == 0f && !_priceUserInput.value) {
|
||||||
|
if (purchaseOrder.recPriceExItem != null && !_priceUserInput.value) {
|
||||||
val result =
|
val result =
|
||||||
purchaseOrder.recPriceExItem!!.div(receivedNum)
|
purchaseOrder.recPriceExItem!!.div(receivedNum)
|
||||||
purchaseOrder.recUnitPriceTaxIn = result.toSafeFloat()
|
purchaseOrder.recUnitPriceTaxIn = result.toSafeFloat()
|
||||||
@@ -247,14 +256,22 @@ class ReceiptViewModel @Inject constructor(
|
|||||||
// 计算单价
|
// 计算单价
|
||||||
val finalPrice = if (count == 0.0) {
|
val finalPrice = if (count == 0.0) {
|
||||||
0f
|
0f
|
||||||
} else if (info.recPriceExItem != null && info.recPriceExItem != 0f && !_countUserInput.value && !_priceUserInput.value) {
|
} else if (!_countUserInput.value && !_priceUserInput.value) {
|
||||||
|
if (info.recPriceExItemTemp.isNotEmpty()) {
|
||||||
info.recPriceExItem!!.div(count).toSafeFloat()
|
info.recPriceExItem!!.div(count).toSafeFloat()
|
||||||
|
} else {
|
||||||
|
0f
|
||||||
|
}
|
||||||
} else info.recUnitPriceTaxIn ?: 0f
|
} else info.recUnitPriceTaxIn ?: 0f
|
||||||
// 计算金额
|
// 计算金额
|
||||||
val finalAmount = if (count == 0.0) {
|
val finalAmount = if (count == 0.0) {
|
||||||
0f
|
0f
|
||||||
} else if (info.recUnitPriceTaxIn != null && info.recUnitPriceTaxIn != 0f && !_countUserInput.value && !_amountUserInput.value) {
|
} else if (!_countUserInput.value && !_amountUserInput.value) {
|
||||||
|
if (info.recUnitPriceTaxInTemp.isNotEmpty()) {
|
||||||
count.times(info.recUnitPriceTaxIn!!).toSafeFloat()
|
count.times(info.recUnitPriceTaxIn!!).toSafeFloat()
|
||||||
|
} else {
|
||||||
|
0f
|
||||||
|
}
|
||||||
} else info.recPriceExItem ?: 0f
|
} else info.recPriceExItem ?: 0f
|
||||||
|
|
||||||
_selectedItem.value = info.copy(
|
_selectedItem.value = info.copy(
|
||||||
|
|||||||
@@ -113,16 +113,24 @@ class SelfProcurementViewModel @Inject constructor(
|
|||||||
val finalPrice =
|
val finalPrice =
|
||||||
if (count == 0.0) {
|
if (count == 0.0) {
|
||||||
0.0
|
0.0
|
||||||
} else if (info.goodsPrice != 0.0 && !_countUserInput.value && !_priceUserInput.value) {
|
} else if (!_countUserInput.value && !_priceUserInput.value) {
|
||||||
|
if (info.goodsPriceTemp.isNotEmpty()) {
|
||||||
info.goodsPrice.div(count).toSafeDouble()
|
info.goodsPrice.div(count).toSafeDouble()
|
||||||
|
} else {
|
||||||
|
0.0
|
||||||
|
}
|
||||||
} else info.goodsUnitPrice
|
} else info.goodsUnitPrice
|
||||||
|
|
||||||
// 计算金额 单价不为空,不是数量输入 也不是金额输入
|
// 计算金额 单价不为空,不是数量输入 也不是金额输入
|
||||||
val finalAmount =
|
val finalAmount =
|
||||||
if (count == 0.0) {
|
if (count == 0.0) {
|
||||||
0.0
|
0.0
|
||||||
} else if (info.goodsUnitPrice != 0.0 && !_countUserInput.value && !_amountUserInput.value) {
|
} else if (!_countUserInput.value && !_amountUserInput.value) {
|
||||||
|
if (info.goodsUnitPriceTemp.isNotEmpty()) {
|
||||||
count.times(info.goodsUnitPrice).toSafeDouble()
|
count.times(info.goodsUnitPrice).toSafeDouble()
|
||||||
|
} else {
|
||||||
|
0.0
|
||||||
|
}
|
||||||
} else info.goodsPrice
|
} else info.goodsPrice
|
||||||
Timber.d("startSensorScale finalPrice = $finalPrice, finalAmount = $finalAmount ")
|
Timber.d("startSensorScale finalPrice = $finalPrice, finalAmount = $finalAmount ")
|
||||||
_selectedItem.value = info.copy(
|
_selectedItem.value = info.copy(
|
||||||
@@ -154,7 +162,8 @@ class SelfProcurementViewModel @Inject constructor(
|
|||||||
if (purchaseOrder != null) {
|
if (purchaseOrder != null) {
|
||||||
purchaseOrder.goodsCount.takeIf { it != 0.0 }?.let { receivedNum ->
|
purchaseOrder.goodsCount.takeIf { it != 0.0 }?.let { receivedNum ->
|
||||||
// 计算金额 单价不为空,并且金额没有手动输入
|
// 计算金额 单价不为空,并且金额没有手动输入
|
||||||
if (purchaseOrder.goodsUnitPrice != 0.0 && !_amountUserInput.value) {
|
// if (purchaseOrder.goodsUnitPrice == 0.0 && !_amountUserInput.value) {
|
||||||
|
if (!_amountUserInput.value) {
|
||||||
Timber.d("updateSelectedItem 计算金额")
|
Timber.d("updateSelectedItem 计算金额")
|
||||||
val result =
|
val result =
|
||||||
receivedNum.times(purchaseOrder.goodsUnitPrice)
|
receivedNum.times(purchaseOrder.goodsUnitPrice)
|
||||||
@@ -162,7 +171,8 @@ class SelfProcurementViewModel @Inject constructor(
|
|||||||
purchaseOrder.goodsPriceTemp = result.toFormattedString()
|
purchaseOrder.goodsPriceTemp = result.toFormattedString()
|
||||||
}
|
}
|
||||||
// 计算单价 金额不为空,并且单价没有手动输入
|
// 计算单价 金额不为空,并且单价没有手动输入
|
||||||
if (purchaseOrder.goodsPrice != 0.0 && !_priceUserInput.value) {
|
// if (purchaseOrder.goodsPrice == 0.0 && !_priceUserInput.value) {
|
||||||
|
if (!_priceUserInput.value) {
|
||||||
Timber.d("updateSelectedItem 计算单价")
|
Timber.d("updateSelectedItem 计算单价")
|
||||||
val result =
|
val result =
|
||||||
purchaseOrder.goodsPrice.div(receivedNum)
|
purchaseOrder.goodsPrice.div(receivedNum)
|
||||||
|
|||||||
Reference in New Issue
Block a user