fix order/fulfillment unit
This commit is contained in:
@@ -191,7 +191,7 @@ async function loadFulfillmentSkuList(): Promise<void> {
|
||||
continue;
|
||||
}
|
||||
const originalUnit = getSellableUnitList(item).find(unit => unit.id === item.skuUnitId);
|
||||
const defaultUnit = originalUnit || getSellableUnitList(item)[0];
|
||||
const defaultUnit = getFulfillmentUnitForAvailableQuantity(item, originalUnit || getSellableUnitList(item)[0]);
|
||||
if (defaultUnit?.id) {
|
||||
fulfillmentUnitMap[item.id] = defaultUnit.id;
|
||||
}
|
||||
@@ -217,7 +217,26 @@ function getItemDescription(item: GaoSalesOrderItem): string {
|
||||
}
|
||||
|
||||
function getBaseUnitName(item: GaoSalesOrderItem): string {
|
||||
return item.skuId ? fulfillmentSkuMap[item.skuId]?.unitList?.find(unit => unit.isBase)?.name || "基础单位" : "基础单位";
|
||||
return getBaseUnit(item)?.name || "基础单位";
|
||||
}
|
||||
|
||||
function getBaseUnit(item: GaoSalesOrderItem): ProductSkuUnit | undefined {
|
||||
return getSellableUnitList(item).find(unit => unit.isBase);
|
||||
}
|
||||
|
||||
function shouldDowngradeUnit(item: GaoSalesOrderItem, unit?: ProductSkuUnit): boolean {
|
||||
const sku = item.skuId ? fulfillmentSkuMap[item.skuId] : undefined;
|
||||
if (!unit || unit.isBase || sku?.allowDecimalQuantity !== false) {
|
||||
return false;
|
||||
}
|
||||
return Number(getAvailableBaseQuantity(item)) < Number(unit.baseQuantityPerUnit);
|
||||
}
|
||||
|
||||
function getFulfillmentUnitForAvailableQuantity(item: GaoSalesOrderItem, unit?: ProductSkuUnit): ProductSkuUnit | undefined {
|
||||
if (!shouldDowngradeUnit(item, unit)) {
|
||||
return unit;
|
||||
}
|
||||
return getBaseUnit(item) || unit;
|
||||
}
|
||||
|
||||
function fillAllQuantity(item: GaoSalesOrderItem): void {
|
||||
@@ -242,6 +261,22 @@ function getFulfillmentUnit(item: GaoSalesOrderItem): ProductSkuUnit | undefined
|
||||
return getSellableUnitList(item).find(unit => unit.id === fulfillmentUnitMap[item.id || ""]);
|
||||
}
|
||||
|
||||
function setFulfillmentUnit(item: GaoSalesOrderItem, unit: ProductSkuUnit): void {
|
||||
if (!item.id) {
|
||||
return;
|
||||
}
|
||||
const currentUnit = getFulfillmentUnit(item);
|
||||
const currentQuantity = quantityMap[item.id];
|
||||
if (currentQuantity && currentUnit?.id !== unit.id) {
|
||||
quantityMap[item.id] = convertPackageQuantity(
|
||||
currentQuantity,
|
||||
currentUnit?.baseQuantityPerUnit ?? "1",
|
||||
unit.baseQuantityPerUnit
|
||||
) || "";
|
||||
}
|
||||
fulfillmentUnitMap[item.id] = unit.id!;
|
||||
}
|
||||
|
||||
function openUnitPicker(item: GaoSalesOrderItem): void {
|
||||
if (!item.id) {
|
||||
return;
|
||||
@@ -257,8 +292,11 @@ function openUnitPicker(item: GaoSalesOrderItem): void {
|
||||
|
||||
function confirmUnitPicker(value: Array<string | number>): void {
|
||||
const skuUnitId = String(value[0] || "");
|
||||
if (unitPickerSourceItemId.value && skuUnitId) {
|
||||
fulfillmentUnitMap[unitPickerSourceItemId.value] = skuUnitId;
|
||||
const item = sourceItems.value.find(sourceItem => sourceItem.id === unitPickerSourceItemId.value);
|
||||
const selectedUnit = item ? getSellableUnitList(item).find(unit => unit.id === skuUnitId) : undefined;
|
||||
const fulfillmentUnit = item ? getFulfillmentUnitForAvailableQuantity(item, selectedUnit) : selectedUnit;
|
||||
if (item?.id && fulfillmentUnit?.id) {
|
||||
setFulfillmentUnit(item, fulfillmentUnit);
|
||||
}
|
||||
unitPickerVisible.value = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user