From aa5d06762c532536eec60f065b8dc22a845c2dc2 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 20 Jul 2022 10:31:53 +0200 Subject: [PATCH] Bug 32030: Unique - Prevent same agreement for local packages Signed-off-by: Jonathan Field Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- .../ERM/EHoldingsLocalPackagesFormAdd.vue | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesFormAdd.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesFormAdd.vue index 79a2d0fbc6..514b693f55 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesFormAdd.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesFormAdd.vue @@ -114,7 +114,7 @@ import EHoldingsPackageAgreements from "./EHoldingsLocalPackageAgreements.vue" import { useVendorStore } from "../../stores/vendors" import { useAVStore } from "../../stores/authorised_values" -import { setMessage, setError } from "../../messages" +import { setMessage, setError, setWarning } from "../../messages" import { fetchLocalPackage, createPackage, editPackage } from '../../fetch' import { storeToRefs } from "pinia" @@ -165,11 +165,30 @@ export default { this.erm_package = erm_package this.initialized = true }, + checkForm(erm_package) { + let errors = [] + let package_agreements = erm_package.package_agreements + const agreement_ids = package_agreements.map(pa => pa.agreement_id) + const duplicate_agreement_ids = agreement_ids.filter((id, i) => agreement_ids.indexOf(id) !== i) + + if (duplicate_agreement_ids.length) { + errors.push(this.$t("An agreement is used several times")) + } + + errors.forEach(function (e) { + setWarning(e) + }) + return !errors.length + }, onSubmit(e) { e.preventDefault() let erm_package = JSON.parse(JSON.stringify(this.erm_package)) // copy + if (!this.checkForm(erm_package)) { + return false + } + if (erm_package.package_id) { editPackage(erm_package).then(response => { if (response.status == 200) { -- 2.39.5