From 95924e85787c4949be6247ad999efc3d726689da Mon Sep 17 00:00:00 2001 From: hengsin Date: Sat, 18 Dec 2021 02:25:40 +0800 Subject: [PATCH] IDEMPIERE-5103 Clear Parent Tax ID if a Tax Rate record is Summary (#1056) --- .../src/org/compiere/model/MTax.java | 6 +- .../org/idempiere/test/model/MTaxTest.java | 63 +++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 org.idempiere.test/src/org/idempiere/test/model/MTaxTest.java diff --git a/org.adempiere.base/src/org/compiere/model/MTax.java b/org.adempiere.base/src/org/compiere/model/MTax.java index 929575a14f..6c4c766d27 100644 --- a/org.adempiere.base/src/org/compiere/model/MTax.java +++ b/org.adempiere.base/src/org/compiere/model/MTax.java @@ -381,7 +381,11 @@ public class MTax extends X_C_Tax implements ImmutablePOSupport if (getTo_Country_ID() > 0 && getC_CountryGroupTo_ID() > 0) { setTo_Country_ID(0); } - + if (isSummary()) { + if (getParent_Tax_ID() > 0) { + setParent_Tax_ID(0); + } + } return super.beforeSave(newRecord); } diff --git a/org.idempiere.test/src/org/idempiere/test/model/MTaxTest.java b/org.idempiere.test/src/org/idempiere/test/model/MTaxTest.java new file mode 100644 index 0000000000..80a31763c2 --- /dev/null +++ b/org.idempiere.test/src/org/idempiere/test/model/MTaxTest.java @@ -0,0 +1,63 @@ +/*********************************************************************** + * 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.idempiere.test.model; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.compiere.model.MTax; +import org.compiere.util.Env; +import org.compiere.util.TimeUtil; +import org.idempiere.test.AbstractTestCase; +import org.junit.jupiter.api.Test; + +/** + * + * @author hengsin + * + */ +public class MTaxTest extends AbstractTestCase { + + private static final int STANDARD_TAX_ID = 104; + private static final int STANDARD_TAX_CATEGORY_ID=107; + + public MTaxTest() { + } + + @Test + public void testClearParentTaxId() { + MTax tax = new MTax(Env.getCtx(), 0, getTrxName()); + tax.setName("testClearParentTaxId"); + tax.setParent_Tax_ID(STANDARD_TAX_ID); + tax.setValidFrom(TimeUtil.getDay(null)); + tax.setIsSummary(false); + tax.setC_TaxCategory_ID(STANDARD_TAX_CATEGORY_ID); + tax.saveEx(); + assertEquals(STANDARD_TAX_ID, tax.getParent_Tax_ID(), "Unexpected parent tax id"); + + tax.setIsSummary(true); + tax.saveEx(); + assertEquals(0, tax.getParent_Tax_ID(), "Unexpected parent tax id"); + } +}