From 3423e02780d3b89ef75666b1794ca388deb581b9 Mon Sep 17 00:00:00 2001 From: PeterTakacs300 <93127072+PeterTakacs300@users.noreply.github.com> Date: Tue, 22 Feb 2022 23:50:48 +0100 Subject: [PATCH] IDEMPIERE-5091 - Before Save Set Default Locator From Product Or Warehouse when creating m_inout programatically (#1043) * IDEMPIERE-5091 - Before Save Set Default Locator From Product Or Warehouse when creating m_inout programatically * IDEMPIERE-5091 - inefficient methods replaced Co-authored-by: Igor Pojzl --- .../src/org/compiere/model/MInOutLine.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/org.adempiere.base/src/org/compiere/model/MInOutLine.java b/org.adempiere.base/src/org/compiere/model/MInOutLine.java index e1262d9d69..7e24c7dfea 100644 --- a/org.adempiere.base/src/org/compiere/model/MInOutLine.java +++ b/org.adempiere.base/src/org/compiere/model/MInOutLine.java @@ -548,7 +548,26 @@ public class MInOutLine extends X_M_InOutLine { if (getM_Locator_ID() <= 0 && getC_Charge_ID() <= 0) { - throw new FillMandatoryException(COLUMNNAME_M_Locator_ID); + // Try to load Default Locator + + MWarehouse warehouse = MWarehouse.get(getM_Warehouse_ID()); + + if(warehouse != null) { + + int m_Locator_ID = getProduct().getM_Locator_ID(); + + if(m_Locator_ID > 0 && MLocator.get(m_Locator_ID).getM_Warehouse_ID() == warehouse.getM_Warehouse_ID()) { + setM_Locator_ID(m_Locator_ID); + } + else { + MLocator defaultLocator = warehouse.getDefaultLocator(); + if(defaultLocator != null) + setM_Locator_ID(defaultLocator.getM_Locator_ID()); + } + } + + if (getM_Locator_ID() <= 0) + throw new FillMandatoryException(COLUMNNAME_M_Locator_ID); } }