Bug 42605: Preserve acquisition preference string values

Bug 41563 converted AcqCreateItem and UniqueItemFields to booleans when
adding them to Koha.prefs. Both preferences are strings: AcqCreateItem
controls where items are created, while UniqueItemFields contains a
pipe-separated list.

When a basket inherits AcqCreateItem=ordering, the boolean value matches
none of the receiving page branches and existing items are hidden. When
items are created on receiving, the numeric UniqueItemFields value also
fails when the page calls split().

Preserve both string values in Koha.prefs. Add a Cypress regression test
which renders orderreceive.pl and verifies the values exposed to
JavaScript.

Test plan:

Before applying the patch:

1. Set AcqCreateItem to "placing an order" and UniqueItemFields to
   "barcode".
2. Create a basket that inherits the system preference. Add an order with one
   item, close the basket, and start receiving it.
3. Confirm that the Items table has no existing item row and no Receive
   checkbox.
4. Set AcqCreateItem to "receiving an order" and open the same order for
   receiving.
5. Confirm that the Items section is empty: no item-entry fields and no Add
   item button are shown.

Apply the patch.

After applying the patch:

1. Set AcqCreateItem back to "placing an order" and open the order for
   receiving again.
2. Confirm that its existing item is listed and has a Receive checkbox.
3. Set AcqCreateItem to "receiving an order" and open the same order again.
4. Confirm that the Items section contains item-entry fields and an Add item
   button.

Co-Authored-By: Loontik <loontik@nugged.team>
Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Andrii Nugged 2026-08-18 11:47:28 +03:00 committed by Lucas Gass
parent 4a7d08942c
commit 8a68a3cda7
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
2 changed files with 69 additions and 1 deletions

View File

@ -461,7 +461,7 @@
const multiple_orders = "[% multiple_orders | html %]";
const only_one_order = [% only_one_order ? 1 : 0 | html %];
Koha.addPrefs({
AcqCreateItem: [% Koha.Preference('AcqCreateItem') ? 1 : 0 | html %],
AcqCreateItem: "[% Koha.Preference('AcqCreateItem') | html %]",
UniqueItemFields: [% Koha.Preference('UniqueItemFields') ? 1 : 0 | html %],
});
Koha.addPermissions({

View File

@ -0,0 +1,68 @@
describe("Order receive preferences", () => {
beforeEach(() => {
cy.login();
cy.title().should("eq", "Koha staff interface");
cy.task("buildSampleObject", {
object: "vendor",
values: { active: 1 },
})
.then(generatedVendor => {
delete generatedVendor.list_currency;
delete generatedVendor.invoice_currency;
return cy.task("insertObject", {
type: "vendor",
object: generatedVendor,
});
})
.then(vendor => {
cy.wrap(vendor).as("vendor");
return cy.task("buildSampleObject", {
object: "invoice",
values: { vendor_id: vendor.id },
});
})
.then(generatedInvoice => {
return cy.task("insertObject", {
type: "invoice",
object: generatedInvoice,
});
})
.then(invoice => {
cy.wrap(invoice).as("invoice");
});
cy.task("query", {
sql: "SELECT value FROM systempreferences WHERE variable='AcqCreateItem'",
}).then(value => {
cy.wrap(value).as("syspref_AcqCreateItem");
});
cy.task("query", {
sql: "SELECT value FROM systempreferences WHERE variable='UniqueItemFields'",
}).then(value => {
cy.wrap(value).as("syspref_UniqueItemFields");
});
});
afterEach(function () {
cy.task("deleteSampleObjects", [
{ vendor: this.vendor, invoice: this.invoice },
]);
cy.set_syspref("AcqCreateItem", this.syspref_AcqCreateItem);
cy.set_syspref("UniqueItemFields", this.syspref_UniqueItemFields);
});
it("preserves string-valued system preferences", function () {
cy.set_syspref("AcqCreateItem", "ordering");
cy.set_syspref("UniqueItemFields", "barcode|itemcallnumber");
cy.visit(
`/cgi-bin/koha/acqui/orderreceive.pl?invoiceid=${this.invoice.invoice_id}&multiple_orders=999999998,999999999`
);
cy.window().then(win => {
const prefs = (win as any).Koha.prefs;
expect(prefs.AcqCreateItem).to.equal("ordering");
expect(prefs.UniqueItemFields).to.equal("barcode|itemcallnumber");
});
});
});