Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* Set initial sorting column for "Related invoice lines" MCL. Refs UIOR-1581.
* Add Order email templates settings with token picker and Handlebars backend-rendered preview. Refs UIOR-1492, UIOR-1493, UIOR-1495.
* Do not show metadata fields in "Version history" for PO and PO Lines. Refs UIOR-1585.
* Preserve the "Create inventory" and "Receiving workflow" fields values according to the form value precedence rules. Refs UIOR-1582.

## [9.0.5](https://github.com/folio-org/ui-orders/tree/v9.0.5) (2026-07-20)
[Full Changelog](https://github.com/folio-org/ui-orders/compare/v9.0.4...v9.0.5)
Expand Down
18 changes: 12 additions & 6 deletions src/common/POLFields/DetailsFields/FieldOrderFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ORDER_FORMATS,
} from '@folio/stripes-acq-components';

import { OPTION_VALUE_WITH_BINDERY_ACTIVE } from '../../../components/POLine/const';
import { POL_FORM_FIELDS } from '../../constants';

const ORDER_FORMAT_OPTIONS = Object.keys(ORDER_FORMATS).map((key) => ({
Expand Down Expand Up @@ -35,8 +36,13 @@ const handleElectronic = (change, settings, formValues, vendor) => {
}
};

const handlePhysical = (change, settings) => {
change(POL_FORM_FIELDS.physicalCreateInventory, settings.physical);
const handlePhysical = (change, settings, formValues) => {
// Bindery's required inventory takes precedence over tenant defaults in both physical formats.
const createInventory = get(formValues, POL_FORM_FIELDS.isBinderyActive)
? OPTION_VALUE_WITH_BINDERY_ACTIVE
: settings.physical;

change(POL_FORM_FIELDS.physicalCreateInventory, createInventory);
};

const handleOther = (change, settings) => {
Expand All @@ -48,17 +54,17 @@ export const formatHandlers = {
change(POL_FORM_FIELDS.physical, undefined);
handleElectronic(change, settings, formValues, vendor);
},
[ORDER_FORMATS.physicalResource]: (change, settings) => {
[ORDER_FORMATS.physicalResource]: (change, settings, formValues, _vendor) => {
change(POL_FORM_FIELDS.eresource, undefined);
handlePhysical(change, settings);
handlePhysical(change, settings, formValues);
},
[ORDER_FORMATS.other]: (change, settings) => {
[ORDER_FORMATS.other]: (change, settings, _formValues, _vendor) => {
change(POL_FORM_FIELDS.eresource, undefined);
handleOther(change, settings);
},
[ORDER_FORMATS.PEMix]: (change, settings, formValues, vendor) => {
handleElectronic(change, settings, formValues, vendor);
handlePhysical(change, settings);
handlePhysical(change, settings, formValues);
},
};

Expand Down
73 changes: 61 additions & 12 deletions src/common/POLFields/DetailsFields/FieldOrderFormat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { Form } from 'react-final-form';

import user from '@folio/jest-config-stripes/testing-library/user-event';
import {
act,
render,
screen,
} from '@folio/jest-config-stripes/testing-library/react';
import { ORDER_FORMATS } from '@folio/stripes-acq-components';
import { INVENTORY_RECORDS_TYPE, ORDER_FORMATS } from '@folio/stripes-acq-components';

import { vendor } from 'fixtures';
import FieldOrderFormat from './FieldOrderFormat';
Expand All @@ -20,17 +21,23 @@ const defaultProps = {
disabled: false,
};

const renderFieldOrderFormat = (props = {}) => render(
<Form
onSubmit={() => jest.fn()}
render={() => (
<FieldOrderFormat
{...defaultProps}
{...props}
/>
)}
/>,
);
// Read the resulting nested values from a real form, not only the selected option.
const renderFieldOrderFormat = (props = {}, initialValues = defaultProps.formValues) => {
let formApi;
const view = render(
<Form
initialValues={initialValues}
onSubmit={jest.fn()}
render={({ form, values }) => {
formApi = form;

return <FieldOrderFormat {...defaultProps} {...props} formValues={values} />;
}}
/>,
);

return { ...view, getValues: () => formApi.getState().values };
};

describe('FieldOrderFormat', () => {
it('should render \'order format\' field', () => {
Expand Down Expand Up @@ -65,4 +72,46 @@ describe('FieldOrderFormat', () => {

expect(options[0].selected).toBeTruthy();
});

describe.each([
['initial physical selection', undefined, ORDER_FORMATS.physicalResource],
['physical to mixed', ORDER_FORMATS.physicalResource, ORDER_FORMATS.PEMix],
['mixed to physical', ORDER_FORMATS.PEMix, ORDER_FORMATS.physicalResource],
])('with Bindery active: %s', (_description, previousFormat, nextFormat) => {
it.each([...Object.values(INVENTORY_RECORDS_TYPE), undefined])(
'should keep all inventory records instead of tenant default %s',
async (physicalDefault) => {
const { getValues } = renderFieldOrderFormat({
createInventorySetting: { physical: physicalDefault, eresource: INVENTORY_RECORDS_TYPE.instance },
}, {
orderFormat: previousFormat,
details: { isBinderyActive: true },
physical: { createInventory: INVENTORY_RECORDS_TYPE.all },
});

await act(async () => user.selectOptions(screen.getByRole('combobox'), nextFormat));

expect(getValues().physical?.createInventory).toBe(INVENTORY_RECORDS_TYPE.all);

if (nextFormat === ORDER_FORMATS.PEMix) {
expect(getValues().eresource.createInventory).toBe(INVENTORY_RECORDS_TYPE.instance);
} else {
expect(getValues().eresource).toBeUndefined();
}
},
);
});

it.each([ORDER_FORMATS.physicalResource, ORDER_FORMATS.PEMix])(
'should use the tenant physical default for %s when Bindery is inactive',
async (nextFormat) => {
const { getValues } = renderFieldOrderFormat({
createInventorySetting: { physical: INVENTORY_RECORDS_TYPE.instance },
}, { details: { isBinderyActive: false } });

await act(async () => user.selectOptions(screen.getByRole('combobox'), nextFormat));

expect(getValues().physical.createInventory).toBe(INVENTORY_RECORDS_TYPE.instance);
},
);
});
Loading
Loading