diff --git a/src/main/java/de/deadlocker8/budgetmaster/templates/TemplateController.java b/src/main/java/de/deadlocker8/budgetmaster/templates/TemplateController.java index a29f6371bde15cf45837290a18f07897a3a7a4f4..617a0a21b93bdff4b957a23bb0753472a0cc2ce6 100644 --- a/src/main/java/de/deadlocker8/budgetmaster/templates/TemplateController.java +++ b/src/main/java/de/deadlocker8/budgetmaster/templates/TemplateController.java @@ -126,8 +126,6 @@ public class TemplateController extends BaseController final Template template = templateOptional.get(); - // set ID to null, otherwise the transaction form is prefilled with the template ID and saving the transaction - // may then override an existing transactions if the ID is also already used in transactions table template.setID(null); templateService.prepareTemplateForNewTransaction(template, true); diff --git a/src/main/resources/templates/transactions/newTransactionNormal.ftl b/src/main/resources/templates/transactions/newTransactionNormal.ftl index 6cbfe5e448b889fd5b3e3e3b893338dcace651f2..57aac21ec12d96b3391726aac2430ac7ce63509d 100644 --- a/src/main/resources/templates/transactions/newTransactionNormal.ftl +++ b/src/main/resources/templates/transactions/newTransactionNormal.ftl @@ -26,7 +26,9 @@ <#import "../helpers/validation.ftl" as validation> <form name="NewTransaction" action="<@s.url '/transactions/newTransaction/normal'/>" method="post" onsubmit="return validateForm()"> <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/> - <input type="hidden" name="ID" value="<#if transaction.getID()??>${transaction.getID()?c}</#if>"> + <!-- only set ID for transactions not templates, otherwise the input is filled with the template ID and saving the transaction + may then override an existing transactions if the ID is also already used in transactions table --> + <input type="hidden" name="ID" value="<#if transaction.class.simpleName == "Transaction" && transaction.getID()??>${transaction.getID()?c}</#if>"> <#-- isPayment switch --> <@newTransactionMacros.isExpenditureSwitch transaction isPayment/> diff --git a/src/main/resources/templates/transactions/newTransactionTransfer.ftl b/src/main/resources/templates/transactions/newTransactionTransfer.ftl index 6ae0409777c35f58c854f6ba545503601e12bffd..66329a093746fa35eff8864e7375acba33d27031 100644 --- a/src/main/resources/templates/transactions/newTransactionTransfer.ftl +++ b/src/main/resources/templates/transactions/newTransactionTransfer.ftl @@ -26,7 +26,9 @@ <#import "../helpers/validation.ftl" as validation> <form name="NewTransaction" action="<@s.url '/transactions/newTransaction/transfer'/>" method="post" onsubmit="return validateForm()"> <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/> - <input type="hidden" name="ID" value="<#if transaction.getID()??>${transaction.getID()?c}</#if>"> + <!-- only set ID for transactions not templates, otherwise the input is filled with the template ID and saving the transaction + may then override an existing transactions if the ID is also already used in transactions table --> + <input type="hidden" name="ID" value="<#if transaction.class.simpleName == "Transaction" && transaction.getID()??>${transaction.getID()?c}</#if>"> <input type="hidden" name="isPayment" value="true"> <#-- name -->