diff --git a/src/main/java/com/ffii/fpsms/m18/model/M18BomForShopSaveRequest.kt b/src/main/java/com/ffii/fpsms/m18/model/M18BomForShopSaveRequest.kt index ecadc84..eceebd2 100644 --- a/src/main/java/com/ffii/fpsms/m18/model/M18BomForShopSaveRequest.kt +++ b/src/main/java/com/ffii/fpsms/m18/model/M18BomForShopSaveRequest.kt @@ -79,7 +79,7 @@ data class M18UdfProductSaveValue( val udfIngredients: String? = null, /** Line UOM: [com.ffii.fpsms.modules.master.entity.UomConversion.code] (same unit as [udfqty]). */ val udfBaseUnit: String? = null, - /** M18 vendor id from latest synced PO for the material: local [com.ffii.fpsms.modules.master.entity.Shop.m18Id] or M18 `ven` search (PF BE when BOM is PF). */ + /** M18 vendor id ([StSearchType.VENDOR]) for the BOM business entity: PP → [M18Config.BEID_PP], PF → [M18Config.BEID_PF]. */ val udfSupplier: Long? = null, /** * M18 UOM id for price/purchase unit on the **M18-linked** PO line (`m18DataLog` present): diff --git a/src/main/java/com/ffii/fpsms/m18/service/M18BomForShopService.kt b/src/main/java/com/ffii/fpsms/m18/service/M18BomForShopService.kt index 5227ea2..dbd06d5 100644 --- a/src/main/java/com/ffii/fpsms/m18/service/M18BomForShopService.kt +++ b/src/main/java/com/ffii/fpsms/m18/service/M18BomForShopService.kt @@ -389,7 +389,7 @@ open class M18BomForShopService( /** * Resolves M18 vendor id for BOM material line supplier: * - PF BOMs: M18 search by supplier code + [M18Config.BEID_PF] - * - PP / other: local [Shop.m18Id] by code, then M18 search with [M18Config.BEID_PP] when needed + * - PP BOMs: M18 search by supplier code + [M18Config.BEID_PP] (never local [Shop.m18Id] first — duplicate codes may be PF ids) */ private fun resolveSupplierM18Id( latestPoLine: PurchaseOrderLine?, @@ -406,28 +406,24 @@ open class M18BomForShopService( if (supplierCode == null) { return directM18Id } - if (directM18Id != null && (targetBeId == null || poBeId == targetBeId)) { - return directM18Id - } - - val cacheKey = "$supplierCode|$flowTypeId" - cache[cacheKey]?.let { return it } - val resolved = when (flowTypeId) { - 2 -> m18VendorLookupService.findVendorM18IdByCode(supplierCode, m18Config.BEID_PF) - ?: directM18Id.also { - if (it == null) { - logger.warn("[M18 BOM] PF vendor M18 id not found for supplierCode=$supplierCode") - } - } - 3 -> shopService.findVendorByCode(supplierCode)?.m18Id?.takeIf { it > 0L } - ?: m18VendorLookupService.findVendorM18IdByCode(supplierCode, m18Config.BEID_PP) - ?: directM18Id - else -> shopService.findVendorByCode(supplierCode)?.m18Id?.takeIf { it > 0L } - ?: directM18Id + if (flowTypeId == 2 || flowTypeId == 3) { + val cacheKey = "$supplierCode|$flowTypeId" + cache[cacheKey]?.let { return it } + val beId = if (flowTypeId == 2) m18Config.BEID_PF else m18Config.BEID_PP + val beLabel = if (flowTypeId == 2) "PF" else "PP" + val resolved = + m18VendorLookupService.findVendorM18IdByCode(supplierCode, beId) + ?: directM18Id.takeIf { poBeId != null && poBeId == targetBeId } + if (resolved == null) { + logger.warn("[M18 BOM] $beLabel vendor M18 id not found for supplierCode=$supplierCode") + } + cache[cacheKey] = resolved + return resolved } - cache[cacheKey] = resolved - return resolved + + return shopService.findVendorByCode(supplierCode)?.m18Id?.takeIf { it > 0L } + ?: directM18Id } private fun resolveFlowTypeId(code: String): Int = when {