diff --git a/migration/iD10/oracle/202203211620_IDEMPIERE-5083.sql b/migration/iD10/oracle/202203211620_IDEMPIERE-5083.sql new file mode 100644 index 0000000000..a9919e9638 --- /dev/null +++ b/migration/iD10/oracle/202203211620_IDEMPIERE-5083.sql @@ -0,0 +1,10 @@ +-- IDEMPIERE-5083 add FREIGHTCOSTRULE_CustomerAccount +SELECT register_migration_script('202203211620_IDEMPIERE-5083.sql') FROM dual; + +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- Mar 21, 2022, 4:20:33 PM MYT +INSERT INTO AD_Ref_List (AD_Ref_List_ID,Name,Description,AD_Reference_ID,Value,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,EntityType,AD_Ref_List_UU) VALUES (200528,'Customer Account','Charge to receiver/customer shipper account',153,'U',0,0,'Y',TO_TIMESTAMP('2022-03-21 16:20:32','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2022-03-21 16:20:32','YYYY-MM-DD HH24:MI:SS'),100,'D','7ed34a5f-ffe5-499e-afd0-f074cca9d1f6') +; + diff --git a/migration/iD10/postgresql/202203211620_IDEMPIERE-5083.sql b/migration/iD10/postgresql/202203211620_IDEMPIERE-5083.sql new file mode 100644 index 0000000000..2c54826152 --- /dev/null +++ b/migration/iD10/postgresql/202203211620_IDEMPIERE-5083.sql @@ -0,0 +1,7 @@ +-- IDEMPIERE-5083 add FREIGHTCOSTRULE_CustomerAccount +SELECT register_migration_script('202203211620_IDEMPIERE-5083.sql') FROM dual; + +-- Mar 21, 2022, 4:20:33 PM MYT +INSERT INTO AD_Ref_List (AD_Ref_List_ID,Name,Description,AD_Reference_ID,Value,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,EntityType,AD_Ref_List_UU) VALUES (200528,'Customer Account','Charge to receiver/customer shipper account',153,'U',0,0,'Y',TO_TIMESTAMP('2022-03-21 16:20:32','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2022-03-21 16:20:32','YYYY-MM-DD HH24:MI:SS'),100,'D','7ed34a5f-ffe5-499e-afd0-f074cca9d1f6') +; + diff --git a/org.adempiere.base.callout/src/org/adempiere/base/callout/InOutFreightCostRule.java b/org.adempiere.base.callout/src/org/adempiere/base/callout/InOutFreightCostRule.java new file mode 100644 index 0000000000..e65c8f1aa8 --- /dev/null +++ b/org.adempiere.base.callout/src/org/adempiere/base/callout/InOutFreightCostRule.java @@ -0,0 +1,74 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.callout; + +import java.util.Properties; + +import org.adempiere.base.IColumnCallout; +import org.adempiere.base.annotation.Callout; +import org.adempiere.util.ShippingUtil; +import org.compiere.model.GridField; +import org.compiere.model.GridTab; +import org.compiere.model.I_M_InOut; +import org.compiere.model.MInOut; +import org.compiere.util.Env; + +/** + * @author hengsin + * + */ +@Callout(tableName = I_M_InOut.Table_Name, columnName = I_M_InOut.COLUMNNAME_FreightCostRule) +public class InOutFreightCostRule implements IColumnCallout { + + /** + * default constructor + */ + public InOutFreightCostRule() { + } + + @Override + public String start(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value, Object oldValue) { + String FreightCostRule = (String) mTab.getValue(MInOut.COLUMNNAME_FreightCostRule); + + if (FreightCostRule == null) + { + mTab.setValue(MInOut.COLUMNNAME_ShipperAccount, null); + return ""; + } + + if (FreightCostRule.equals(MInOut.FREIGHTCOSTRULE_CustomerAccount)) + { + int M_Shipper_ID = Env.getContextAsInt(ctx, WindowNo, MInOut.COLUMNNAME_M_Shipper_ID); + int C_BPartner_ID = Env.getContextAsInt(ctx, WindowNo, MInOut.COLUMNNAME_C_BPartner_ID); + int C_BPartner_Location_ID = Env.getContextAsInt(ctx, WindowNo, MInOut.COLUMNNAME_C_BPartner_Location_ID); + int AD_Org_ID = Env.getContextAsInt(ctx, WindowNo, MInOut.COLUMNNAME_AD_Org_ID); + String shipperAccount = ShippingUtil.getBPShipperAccount(M_Shipper_ID, C_BPartner_ID, C_BPartner_Location_ID, AD_Org_ID, null); + mTab.setValue(MInOut.COLUMNNAME_ShipperAccount, shipperAccount); + mTab.setValue(MInOut.COLUMNNAME_FreightCharges, MInOut.FREIGHTCHARGES_Collect); + } + + return ""; + } +} diff --git a/org.adempiere.base/src/org/adempiere/util/ShippingUtil.java b/org.adempiere.base/src/org/adempiere/util/ShippingUtil.java index db10637efd..1f88875385 100644 --- a/org.adempiere.base/src/org/adempiere/util/ShippingUtil.java +++ b/org.adempiere.base/src/org/adempiere/util/ShippingUtil.java @@ -5,6 +5,12 @@ import org.compiere.util.DB; public class ShippingUtil { + /** + * + * @param shipper_id + * @param org_id + * @return ShipperAccount + */ public static String getSenderShipperAccount(int shipper_id, int org_id) { StringBuilder sb = new StringBuilder(); @@ -14,9 +20,15 @@ public class ShippingUtil sb.append("AND sa.IsActive = 'Y' "); sb.append("AND sa.C_BPartner_ID = s.C_BPartner_ID "); sb.append("AND sa.AD_Org_ID= ? "); - return DB.getSQLValueString(null, sb.toString(), shipper_id, org_id); + return DB.getSQLValueStringEx(null, sb.toString(), shipper_id, org_id); } + /** + * + * @param shipper_id + * @param org_id + * @return DutiesShipperAccount (if any) + */ public static String getSenderDutiesShipperAccount(int shipper_id, int org_id) { StringBuilder sb = new StringBuilder(); @@ -26,12 +38,21 @@ public class ShippingUtil sb.append("AND sa.IsActive = 'Y' "); sb.append("AND sa.C_BPartner_ID = s.C_BPartner_ID "); sb.append("AND sa.AD_Org_ID= ? "); - return DB.getSQLValueString(null, sb.toString(), shipper_id, org_id); + return DB.getSQLValueStringEx(null, sb.toString(), shipper_id, org_id); } + /** + * + * @param shipper_id M_Shipper_ID + * @param c_bpartner_id + * @param ad_org_id + * @param inout_id + * @param order_id + * @return C_BPartner_Location_ID + */ public static int findRecipientAccountLocationId(int shipper_id, int c_bpartner_id, int ad_org_id, int inout_id, int order_id) { - int accountLocationId= DB.getSQLValue(null, + int accountLocationId= DB.getSQLValueEx(null, "SELECT C_BPartner_Location_ID " + " FROM C_BP_ShippingAcct " + " WHERE C_BPartner_ID = ? " @@ -41,7 +62,7 @@ public class ShippingUtil if (accountLocationId <= 0) { // Try without organization - accountLocationId = DB.getSQLValue(null, + accountLocationId = DB.getSQLValueEx(null, "SELECT bps.C_BPartner_Location_ID" + " FROM C_BP_ShippingAcct bps, C_BPartner_Location bpl, C_Location l " + " WHERE bps.C_BPartner_ID = ? " @@ -55,7 +76,7 @@ public class ShippingUtil { if (inout_id > 0) { - accountLocationId = DB.getSQLValue(null, + accountLocationId = DB.getSQLValueEx(null, "SELECT bpl.C_BPartner_Location_ID" + " FROM M_InOut io, C_Order o, C_BPartner_Location bpl, C_Location l " + " WHERE io.M_InOut_ID = ? " @@ -64,7 +85,7 @@ public class ShippingUtil + " AND bpl.C_Location_ID = l.C_Location_ID " + " AND l.Postal IS NOT NULL ", inout_id); if (accountLocationId <= 0) { - accountLocationId = DB.getSQLValue(null, + accountLocationId = DB.getSQLValueEx(null, "SELECT bpl.C_BPartner_Location_ID" + " FROM M_InOut io, C_Invoice i, C_BPartner_Location bpl, C_Location l " + " WHERE io.M_InOut_ID = ? " @@ -76,7 +97,7 @@ public class ShippingUtil } else { - accountLocationId = DB.getSQLValue(null, + accountLocationId = DB.getSQLValueEx(null, "SELECT bpl.C_BPartner_Location_ID" + " FROM C_Order o, C_BPartner_Location bpl, C_Location l " + " WHERE o.C_Order_ID = ?" @@ -87,4 +108,27 @@ public class ShippingUtil } return accountLocationId; } + + /** + * + * @param shipper_id + * @param c_bpartner_id + * @param c_bpartner_location_id + * @param org_id + * @param trxName + * @return shipper account number (if any) + */ + public static String getBPShipperAccount(int shipper_id, int c_bpartner_id, int c_bpartner_location_id, int org_id, String trxName) + { + StringBuilder sb = new StringBuilder(); + sb.append("SELECT sa.ShipperAccount "); + sb.append("FROM C_BP_ShippingAcct sa "); + sb.append("WHERE sa.M_ShippingProcessor_ID IN (SELECT DISTINCT M_ShippingProcessor_ID FROM M_Shipper WHERE M_Shipper_ID = ?) "); + sb.append("AND sa.IsActive = 'Y' "); + sb.append("AND sa.C_BPartner_ID = ? "); + sb.append("AND (sa.C_BPartner_Location_ID IS NULL OR sa.C_BPartner_Location_ID = ?) "); + sb.append("AND sa.AD_Org_ID IN (0, ?) "); + sb.append("ORDER BY C_BPartner_Location_ID, AD_Org_ID "); + return DB.getSQLValueStringEx(trxName, sb.toString(), shipper_id, c_bpartner_id, c_bpartner_location_id, org_id); + } } \ No newline at end of file diff --git a/org.adempiere.base/src/org/compiere/model/I_C_BPartner.java b/org.adempiere.base/src/org/compiere/model/I_C_BPartner.java index 858541bb2d..b7d2843dec 100644 --- a/org.adempiere.base/src/org/compiere/model/I_C_BPartner.java +++ b/org.adempiere.base/src/org/compiere/model/I_C_BPartner.java @@ -22,7 +22,7 @@ import org.compiere.util.KeyNamePair; /** Generated Interface for C_BPartner * @author iDempiere (generated) - * @version Release 9 + * @version Release 10 */ public interface I_C_BPartner { @@ -70,8 +70,8 @@ public interface I_C_BPartner /** Column name AD_Client_ID */ public static final String COLUMNNAME_AD_Client_ID = "AD_Client_ID"; - /** Get Client. - * Client/Tenant for this installation. + /** Get Tenant. + * Tenant for this installation. */ public int getAD_Client_ID(); @@ -105,12 +105,12 @@ public interface I_C_BPartner public static final String COLUMNNAME_AD_Org_ID = "AD_Org_ID"; /** Set Organization. - * Organizational entity within client + * Organizational entity within tenant */ public void setAD_Org_ID (int AD_Org_ID); /** Get Organization. - * Organizational entity within client + * Organizational entity within tenant */ public int getAD_Org_ID(); diff --git a/org.adempiere.base/src/org/compiere/model/I_C_Order.java b/org.adempiere.base/src/org/compiere/model/I_C_Order.java index 94a38b3b17..cce42d3022 100644 --- a/org.adempiere.base/src/org/compiere/model/I_C_Order.java +++ b/org.adempiere.base/src/org/compiere/model/I_C_Order.java @@ -22,7 +22,7 @@ import org.compiere.util.KeyNamePair; /** Generated Interface for C_Order * @author iDempiere (generated) - * @version Release 9 + * @version Release 10 */ public interface I_C_Order { @@ -44,8 +44,8 @@ public interface I_C_Order /** Column name AD_Client_ID */ public static final String COLUMNNAME_AD_Client_ID = "AD_Client_ID"; - /** Get Client. - * Client/Tenant for this installation. + /** Get Tenant. + * Tenant for this installation. */ public int getAD_Client_ID(); @@ -53,12 +53,12 @@ public interface I_C_Order public static final String COLUMNNAME_AD_Org_ID = "AD_Org_ID"; /** Set Organization. - * Organizational entity within client + * Organizational entity within tenant */ public void setAD_Org_ID (int AD_Org_ID); /** Get Organization. - * Organizational entity within client + * Organizational entity within tenant */ public int getAD_Org_ID(); diff --git a/org.adempiere.base/src/org/compiere/model/I_M_InOut.java b/org.adempiere.base/src/org/compiere/model/I_M_InOut.java index 7c31627958..fbcc8f9dae 100644 --- a/org.adempiere.base/src/org/compiere/model/I_M_InOut.java +++ b/org.adempiere.base/src/org/compiere/model/I_M_InOut.java @@ -22,7 +22,7 @@ import org.compiere.util.KeyNamePair; /** Generated Interface for M_InOut * @author iDempiere (generated) - * @version Release 9 + * @version Release 10 */ public interface I_M_InOut { @@ -44,8 +44,8 @@ public interface I_M_InOut /** Column name AD_Client_ID */ public static final String COLUMNNAME_AD_Client_ID = "AD_Client_ID"; - /** Get Client. - * Client/Tenant for this installation. + /** Get Tenant. + * Tenant for this installation. */ public int getAD_Client_ID(); @@ -53,12 +53,12 @@ public interface I_M_InOut public static final String COLUMNNAME_AD_Org_ID = "AD_Org_ID"; /** Set Organization. - * Organizational entity within client + * Organizational entity within tenant */ public void setAD_Org_ID (int AD_Org_ID); /** Get Organization. - * Organizational entity within client + * Organizational entity within tenant */ public int getAD_Org_ID(); diff --git a/org.adempiere.base/src/org/compiere/model/I_M_Movement.java b/org.adempiere.base/src/org/compiere/model/I_M_Movement.java index df778b7709..3e543f5b00 100644 --- a/org.adempiere.base/src/org/compiere/model/I_M_Movement.java +++ b/org.adempiere.base/src/org/compiere/model/I_M_Movement.java @@ -22,7 +22,7 @@ import org.compiere.util.KeyNamePair; /** Generated Interface for M_Movement * @author iDempiere (generated) - * @version Release 9 + * @version Release 10 */ public interface I_M_Movement { @@ -44,8 +44,8 @@ public interface I_M_Movement /** Column name AD_Client_ID */ public static final String COLUMNNAME_AD_Client_ID = "AD_Client_ID"; - /** Get Client. - * Client/Tenant for this installation. + /** Get Tenant. + * Tenant for this installation. */ public int getAD_Client_ID(); @@ -53,12 +53,12 @@ public interface I_M_Movement public static final String COLUMNNAME_AD_Org_ID = "AD_Org_ID"; /** Set Organization. - * Organizational entity within client + * Organizational entity within tenant */ public void setAD_Org_ID (int AD_Org_ID); /** Get Organization. - * Organizational entity within client + * Organizational entity within tenant */ public int getAD_Org_ID(); diff --git a/org.adempiere.base/src/org/compiere/model/I_RV_BPartner.java b/org.adempiere.base/src/org/compiere/model/I_RV_BPartner.java index a2f0112a07..fbdf05fb4d 100644 --- a/org.adempiere.base/src/org/compiere/model/I_RV_BPartner.java +++ b/org.adempiere.base/src/org/compiere/model/I_RV_BPartner.java @@ -22,7 +22,7 @@ import org.compiere.util.KeyNamePair; /** Generated Interface for RV_BPartner * @author iDempiere (generated) - * @version Release 9 + * @version Release 10 */ public interface I_RV_BPartner { @@ -70,8 +70,8 @@ public interface I_RV_BPartner /** Column name AD_Client_ID */ public static final String COLUMNNAME_AD_Client_ID = "AD_Client_ID"; - /** Get Client. - * Client/Tenant for this installation. + /** Get Tenant. + * Tenant for this installation. */ public int getAD_Client_ID(); @@ -157,12 +157,12 @@ public interface I_RV_BPartner public static final String COLUMNNAME_AD_Org_ID = "AD_Org_ID"; /** Set Organization. - * Organizational entity within client + * Organizational entity within tenant */ public void setAD_Org_ID (int AD_Org_ID); /** Get Organization. - * Organizational entity within client + * Organizational entity within tenant */ public int getAD_Org_ID(); diff --git a/org.adempiere.base/src/org/compiere/model/MInOut.java b/org.adempiere.base/src/org/compiere/model/MInOut.java index 4f695d303e..5fad93eb06 100644 --- a/org.adempiere.base/src/org/compiere/model/MInOut.java +++ b/org.adempiere.base/src/org/compiere/model/MInOut.java @@ -35,6 +35,7 @@ import org.adempiere.exceptions.NegativeInventoryDisallowedException; import org.adempiere.exceptions.PeriodClosedException; import org.adempiere.util.IReservationTracer; import org.adempiere.util.IReservationTracerFactory; +import org.adempiere.util.ShippingUtil; import org.compiere.print.MPrintFormat; import org.compiere.print.ReportEngine; import org.compiere.process.DocAction; @@ -47,6 +48,7 @@ import org.compiere.util.DB; import org.compiere.util.Env; import org.compiere.util.Msg; import org.compiere.util.TimeUtil; +import org.compiere.util.Util; /** * Shipment Model @@ -1068,6 +1070,21 @@ public class MInOut extends X_M_InOut implements DocAction, IDocsPostProcess setC_DocType_ID(docType.getC_DocTypeShipment_ID()); } + if (newRecord && isSOTrx()) + { + if (MInOut.FREIGHTCOSTRULE_CustomerAccount.equals(getFreightCostRule())) + { + if (Util.isEmpty(getShipperAccount())) + { + String shipperAccount = ShippingUtil.getBPShipperAccount(getM_Shipper_ID(), getC_BPartner_ID(), getC_BPartner_Location_ID(), getAD_Org_ID(), get_TrxName()); + setShipperAccount(shipperAccount); + } + + if (Util.isEmpty(getFreightCharges())) + setFreightCharges(MInOut.FREIGHTCHARGES_Collect); + } + } + return true; } // beforeSave diff --git a/org.adempiere.base/src/org/compiere/model/X_C_BPartner.java b/org.adempiere.base/src/org/compiere/model/X_C_BPartner.java index d4629fcf0b..76a0f70e1d 100644 --- a/org.adempiere.base/src/org/compiere/model/X_C_BPartner.java +++ b/org.adempiere.base/src/org/compiere/model/X_C_BPartner.java @@ -26,7 +26,7 @@ import org.compiere.util.KeyNamePair; /** Generated Model for C_BPartner * @author iDempiere (generated) - * @version Release 9 - $Id$ */ + * @version Release 10 - $Id$ */ @org.adempiere.base.Model(table="C_BPartner") public class X_C_BPartner extends PO implements I_C_BPartner, I_Persistent { @@ -34,7 +34,7 @@ public class X_C_BPartner extends PO implements I_C_BPartner, I_Persistent /** * */ - private static final long serialVersionUID = 20220116L; + private static final long serialVersionUID = 20220321L; /** Standard Constructor */ public X_C_BPartner (Properties ctx, int C_BPartner_ID, String trxName) @@ -634,6 +634,8 @@ public class X_C_BPartner extends PO implements I_C_BPartner, I_Persistent public static final String FREIGHTCOSTRULE_FreightIncluded = "I"; /** Line = L */ public static final String FREIGHTCOSTRULE_Line = "L"; + /** Customer Account = U */ + public static final String FREIGHTCOSTRULE_CustomerAccount = "U"; /** Set Freight Cost Rule. @param FreightCostRule Method for charging Freight */ diff --git a/org.adempiere.base/src/org/compiere/model/X_C_Order.java b/org.adempiere.base/src/org/compiere/model/X_C_Order.java index 35b1ca1980..e64121f71b 100644 --- a/org.adempiere.base/src/org/compiere/model/X_C_Order.java +++ b/org.adempiere.base/src/org/compiere/model/X_C_Order.java @@ -26,7 +26,7 @@ import org.compiere.util.KeyNamePair; /** Generated Model for C_Order * @author iDempiere (generated) - * @version Release 9 - $Id$ */ + * @version Release 10 - $Id$ */ @org.adempiere.base.Model(table="C_Order") public class X_C_Order extends PO implements I_C_Order, I_Persistent { @@ -34,7 +34,7 @@ public class X_C_Order extends PO implements I_C_Order, I_Persistent /** * */ - private static final long serialVersionUID = 20220116L; + private static final long serialVersionUID = 20220321L; /** Standard Constructor */ public X_C_Order (Properties ctx, int C_Order_ID, String trxName) @@ -1282,6 +1282,8 @@ public class X_C_Order extends PO implements I_C_Order, I_Persistent public static final String FREIGHTCOSTRULE_FreightIncluded = "I"; /** Line = L */ public static final String FREIGHTCOSTRULE_Line = "L"; + /** Customer Account = U */ + public static final String FREIGHTCOSTRULE_CustomerAccount = "U"; /** Set Freight Cost Rule. @param FreightCostRule Method for charging Freight */ diff --git a/org.adempiere.base/src/org/compiere/model/X_M_InOut.java b/org.adempiere.base/src/org/compiere/model/X_M_InOut.java index 04b7348948..3c5fadacc2 100644 --- a/org.adempiere.base/src/org/compiere/model/X_M_InOut.java +++ b/org.adempiere.base/src/org/compiere/model/X_M_InOut.java @@ -26,7 +26,7 @@ import org.compiere.util.KeyNamePair; /** Generated Model for M_InOut * @author iDempiere (generated) - * @version Release 9 - $Id$ */ + * @version Release 10 - $Id$ */ @org.adempiere.base.Model(table="M_InOut") public class X_M_InOut extends PO implements I_M_InOut, I_Persistent { @@ -34,7 +34,7 @@ public class X_M_InOut extends PO implements I_M_InOut, I_Persistent /** * */ - private static final long serialVersionUID = 20220116L; + private static final long serialVersionUID = 20220321L; /** Standard Constructor */ public X_M_InOut (Properties ctx, int M_InOut_ID, String trxName) @@ -958,6 +958,8 @@ public class X_M_InOut extends PO implements I_M_InOut, I_Persistent public static final String FREIGHTCOSTRULE_FreightIncluded = "I"; /** Line = L */ public static final String FREIGHTCOSTRULE_Line = "L"; + /** Customer Account = U */ + public static final String FREIGHTCOSTRULE_CustomerAccount = "U"; /** Set Freight Cost Rule. @param FreightCostRule Method for charging Freight */ diff --git a/org.adempiere.base/src/org/compiere/model/X_M_Movement.java b/org.adempiere.base/src/org/compiere/model/X_M_Movement.java index 224e702b31..bd04dc0796 100644 --- a/org.adempiere.base/src/org/compiere/model/X_M_Movement.java +++ b/org.adempiere.base/src/org/compiere/model/X_M_Movement.java @@ -26,7 +26,7 @@ import org.compiere.util.KeyNamePair; /** Generated Model for M_Movement * @author iDempiere (generated) - * @version Release 9 - $Id$ */ + * @version Release 10 - $Id$ */ @org.adempiere.base.Model(table="M_Movement") public class X_M_Movement extends PO implements I_M_Movement, I_Persistent { @@ -34,7 +34,7 @@ public class X_M_Movement extends PO implements I_M_Movement, I_Persistent /** * */ - private static final long serialVersionUID = 20220116L; + private static final long serialVersionUID = 20220321L; /** Standard Constructor */ public X_M_Movement (Properties ctx, int M_Movement_ID, String trxName) @@ -666,6 +666,8 @@ public class X_M_Movement extends PO implements I_M_Movement, I_Persistent public static final String FREIGHTCOSTRULE_FreightIncluded = "I"; /** Line = L */ public static final String FREIGHTCOSTRULE_Line = "L"; + /** Customer Account = U */ + public static final String FREIGHTCOSTRULE_CustomerAccount = "U"; /** Set Freight Cost Rule. @param FreightCostRule Method for charging Freight */ diff --git a/org.adempiere.base/src/org/compiere/model/X_RV_BPartner.java b/org.adempiere.base/src/org/compiere/model/X_RV_BPartner.java index b6ff49b1f3..abec37aa4d 100644 --- a/org.adempiere.base/src/org/compiere/model/X_RV_BPartner.java +++ b/org.adempiere.base/src/org/compiere/model/X_RV_BPartner.java @@ -25,7 +25,7 @@ import org.compiere.util.Env; /** Generated Model for RV_BPartner * @author iDempiere (generated) - * @version Release 9 - $Id$ */ + * @version Release 10 - $Id$ */ @org.adempiere.base.Model(table="RV_BPartner") public class X_RV_BPartner extends PO implements I_RV_BPartner, I_Persistent { @@ -33,7 +33,7 @@ public class X_RV_BPartner extends PO implements I_RV_BPartner, I_Persistent /** * */ - private static final long serialVersionUID = 20220116L; + private static final long serialVersionUID = 20220321L; /** Standard Constructor */ public X_RV_BPartner (Properties ctx, int RV_BPartner_ID, String trxName) @@ -1950,6 +1950,8 @@ public class X_RV_BPartner extends PO implements I_RV_BPartner, I_Persistent public static final String FREIGHTCOSTRULE_FreightIncluded = "I"; /** Line = L */ public static final String FREIGHTCOSTRULE_Line = "L"; + /** Customer Account = U */ + public static final String FREIGHTCOSTRULE_CustomerAccount = "U"; /** Set Freight Cost Rule. @param FreightCostRule Method for charging Freight */ diff --git a/org.idempiere.test/src/org/idempiere/test/base/InOutTest.java b/org.idempiere.test/src/org/idempiere/test/base/InOutTest.java index 08e2670967..ac4f84a2aa 100644 --- a/org.idempiere.test/src/org/idempiere/test/base/InOutTest.java +++ b/org.idempiere.test/src/org/idempiere/test/base/InOutTest.java @@ -50,13 +50,18 @@ import org.compiere.model.MProduct; import org.compiere.model.MProductPrice; import org.compiere.model.MRMA; import org.compiere.model.MRMALine; +import org.compiere.model.MShipper; +import org.compiere.model.MShippingProcessor; import org.compiere.model.MWarehouse; import org.compiere.model.PO; import org.compiere.model.Query; +import org.compiere.model.X_C_BP_ShippingAcct; +import org.compiere.model.X_M_ShippingProcessorCfg; import org.compiere.process.DocAction; import org.compiere.process.DocumentEngine; import org.compiere.process.ProcessInfo; import org.compiere.util.Env; +import org.compiere.util.TimeUtil; import org.compiere.wf.MWorkflow; import org.idempiere.test.AbstractTestCase; import org.junit.jupiter.api.Test; @@ -66,6 +71,8 @@ import org.junit.jupiter.api.Test; */ public class InOutTest extends AbstractTestCase { + private final static int BP_JOE_BLOCK_ID = 118; + public InOutTest() { } @@ -458,4 +465,60 @@ public class InOutTest extends AbstractTestCase { po.load(getTrxName()); assertTrue(po.get_ValueAsBoolean("Posted")); } + + @Test + public void testFreightCostRuleCustomerAccount() { + MOrder order = new MOrder(Env.getCtx(), 0, getTrxName()); + order.setBPartner(MBPartner.get(Env.getCtx(), BP_JOE_BLOCK_ID)); + order.setC_DocTypeTarget_ID(MOrder.DocSubTypeSO_Standard); + order.setDeliveryRule(MOrder.DELIVERYRULE_CompleteOrder); + order.setDocStatus(DocAction.STATUS_Drafted); + order.setDocAction(DocAction.ACTION_Complete); + Timestamp today = TimeUtil.getDay(System.currentTimeMillis()); + order.setDateOrdered(today); + order.setDatePromised(today); + order.saveEx(); + + X_M_ShippingProcessorCfg cfg = new X_M_ShippingProcessorCfg(Env.getCtx(), 0, getTrxName()); + cfg.setHostAddress("0.0.0.0"); + cfg.setName("Test Shipping Processor Config"); + cfg.setHostPort(0); + cfg.saveEx(); + + MShippingProcessor processor = new MShippingProcessor(Env.getCtx(), 0, getTrxName()); + processor.setM_ShippingProcessorCfg_ID(cfg.get_ID()); + processor.setUserID("-"); + processor.setConnectionPassword("-"); + processor.setName("Test Shipping Processor"); + processor.saveEx(); + + MShipper shipper = new MShipper(Env.getCtx(), 0, getTrxName()); + shipper.setName("Test Shipper"); + shipper.setM_ShipperCfg_ID(cfg.get_ID()); + shipper.setM_ShippingProcessor_ID(processor.get_ID()); + shipper.saveEx(); + + final String shipperAccount = "testFreightCostRuleCustomerAccount"; + + MBPartner bp = new MBPartner(Env.getCtx(), BP_JOE_BLOCK_ID, getTrxName()); + X_C_BP_ShippingAcct acct = new X_C_BP_ShippingAcct(Env.getCtx(), 0, getTrxName()); + acct.setC_BPartner_ID(bp.getC_BPartner_ID()); + acct.setShipperAccount(shipperAccount); + acct.setM_ShippingProcessor_ID(processor.get_ID()); + acct.saveEx(); + + MInOut inout = new MInOut(Env.getCtx(), 0, getTrxName()); + inout.setBPartner(bp); + inout.setIsSOTrx(true); + inout.setC_Order_ID(order.getC_Order_ID()); + inout.setM_Warehouse_ID(getM_Warehouse_ID()); + inout.setC_DocType_ID(); + inout.setDeliveryViaRule(MInOut.DELIVERYVIARULE_Shipper); + inout.setM_Shipper_ID(shipper.get_ID()); + inout.setFreightCostRule(MInOut.FREIGHTCOSTRULE_CustomerAccount); + inout.saveEx(); + + assertEquals(shipperAccount, inout.getShipperAccount(), "Unexpected shipper account"); + assertEquals(MInOut.FREIGHTCHARGES_Collect, inout.getFreightCharges(), "Unexpected freight charges rule"); + } }