From 9aedf1b648a8ca9de3ef2fd5a8c274188bce17e7 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Tue, 22 Apr 2025 14:08:42 +0100 Subject: [PATCH] Bug 38010: (QA follow-up) Fix issues on vendor edit page This commit addresses the following: - Prevents form submission when hitting enter in the alias field - validation for the discount field - restores delete functionality to interfaces - fixes the broken edit button on the list view Signed-off-by: Michaela Sieber Signed-off-by: Jonathan Druart --- .../vue/components/Vendors/VendorDetails.vue | 8 +++-- .../vue/components/Vendors/VendorFormAdd.vue | 31 +++++++++++++++++-- .../components/Vendors/VendorInterfaces.vue | 2 +- .../js/vue/components/Vendors/VendorList.vue | 2 +- .../Vendors/VendorOrderingInformation.vue | 18 +++++++++++ 5 files changed, 54 insertions(+), 7 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorDetails.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorDetails.vue index c6f8ce0023a..9ae5bc3327d 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorDetails.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorDetails.vue @@ -143,7 +143,11 @@
  • - + {{ $__("Add") }} @@ -201,7 +205,7 @@ export default { }, removeAlias(e) { const aliasIndex = this.vendor.aliases - .map(e => e.alias) + .map(a => a.alias) .indexOf(e.alias); this.vendor.aliases.splice(aliasIndex, 1); }, diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorFormAdd.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorFormAdd.vue index 7f31ea051d7..6ea4c6c007f 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorFormAdd.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorFormAdd.vue @@ -10,7 +10,11 @@ - +
    import ButtonSubmit from "../ButtonSubmit.vue"; -import { setMessage } from "../../messages"; +import { setMessage, setWarning } from "../../messages"; import { APIClient } from "../../fetch/api-client.js"; import VendorDetails from "./VendorDetails.vue"; import VendorContacts from "./VendorContacts.vue"; @@ -66,6 +70,7 @@ export default { interfaces: [], }, initialized: false, + discountValid: true, }; }, beforeRouteEnter(to, from, next) { @@ -89,6 +94,15 @@ export default { vendor.address3 && (physical += vendor.address3 + "\n"); vendor.address4 && (physical += vendor.address4 + "\n"); this.vendor.physical = physical; + + if (!this.vendor.discount) this.vendor.discount = 0.0; + const decimalPlaces = + this.vendor.discount.toString().split(".")[1]?.length || + 0; + if (!decimalPlaces) { + this.vendor.discount = this.vendor.discount.toFixed(1); + } + this.initialized = true; }, error => {} @@ -96,7 +110,7 @@ export default { }, onSubmit(e) { e.preventDefault(); - + const errors = []; const vendor = JSON.parse(JSON.stringify(this.vendor)); const vendorId = vendor.id; @@ -114,6 +128,9 @@ export default { delete vendor.physical; delete vendor.subscriptions_count; + if (!this.discountValid) + errors.push(this.$__("Invalid discount value")); + vendor.contacts = this.checkContactOrInterface( vendor.contacts.map( ({ id, booksellerid, ...requiredProperties }) => @@ -127,6 +144,9 @@ export default { ) ); + setWarning(errors.join("
    ")); + if (errors.length) return false; + const client = APIClient.acquisition; if (vendorId) { client.vendors.update(vendor, vendorId).then( @@ -157,6 +177,11 @@ export default { return acc; }, []); }, + verifyDiscountValue(e) { + this.discountValid = /^[\-]?\d{0,2}(\.\d{0,3})*$/.test( + this.vendor.discount + ); + }, }, components: { ButtonSubmit, diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorInterfaces.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorInterfaces.vue index 40f3ff86606..7bac4ee687e 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorInterfaces.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorInterfaces.vue @@ -127,7 +127,7 @@ />
  • - {{ $__("Delete interface") }} diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorList.vue index 2fc5ec1cd2d..a23208ea877 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorList.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorList.vue @@ -148,7 +148,7 @@ export default { doEdit({ id }, dt, event) { this.$router.push({ name: "VendorFormAddEdit", - params: { vendor_id: id }, + params: { id: id }, }); }, doDelete(vendor, dt, event) { diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorOrderingInformation.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorOrderingInformation.vue index 7c9a8e8fa4b..beb9769bf67 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorOrderingInformation.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorOrderingInformation.vue @@ -192,8 +192,14 @@ id="discount" name="discount" v-model="vendor.discount" + @change="verifyDiscountValue(e)" /> % + + {{ + $__("Please enter a decimal number in the format: 0.0") + }} +
  • @@ -228,6 +234,8 @@ export default { props: { vendor: Object, display: Boolean, + verifyDiscountValue: Function, + discountValid: Boolean, }, setup() { const vendorStore = inject("vendorStore"); @@ -245,6 +253,16 @@ export default { const multiplier = 10 ** decimalPlaces; return Math.round(taxRate * multiplier) / (multiplier / 100); }, + formatDiscount() { + if (!this.vendor.discount) return 0.0; + const decimalPlaces = + this.vendor.discount.toString().split(".")[1]?.length || 0; + if (decimalPlaces) { + return this.vendor.discount; + } else { + return this.vendor.discount.toFixed(1); + } + }, }, }; -- 2.34.1