@openmrs/esm-stock-management-app 3.3.2-pre.210 → 3.3.2-pre.232
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/5117.js +1 -1
- package/dist/5117.js.map +1 -1
- package/dist/5838.js +1 -1
- package/dist/5838.js.map +1 -1
- package/dist/8156.js +1 -1
- package/dist/8156.js.map +1 -1
- package/dist/openmrs-esm-stock-management-app.js +2 -2
- package/dist/routes.json +1 -1
- package/package.json +1 -1
- package/src/stock-items/add-stock-item/stock-item-rules/add-stock-rules.component.test.tsx +53 -0
- package/src/stock-items/add-stock-item/stock-item-rules/add-stock-rules.component.tsx +8 -3
- package/src/stock-items/add-stock-item/stock-item-rules/stock-rules.resource.test.ts +57 -0
- package/src/stock-items/add-stock-item/stock-item-rules/stock-rules.resource.ts +16 -4
- package/translations/en.json +2 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
3
|
+
import { render, screen } from '@testing-library/react';
|
|
4
|
+
import { mockWorkspace2Props } from '@mocks';
|
|
5
|
+
|
|
6
|
+
vi.mock('./stock-rules.resource', () => ({ createOrUpdateStockRule: vi.fn() }));
|
|
7
|
+
vi.mock('../../stock-items.resource', () => ({
|
|
8
|
+
useStockItemPackagingUOMs: () => ({ items: { results: [] } }),
|
|
9
|
+
}));
|
|
10
|
+
vi.mock('../../../stock-lookups/stock-lookups.resource', () => ({
|
|
11
|
+
useRoles: () => ({ items: { results: [] } }),
|
|
12
|
+
useStockTagLocations: () => ({ stockLocations: [{ id: 'location-uuid', name: 'Main pharmacy' }] }),
|
|
13
|
+
}));
|
|
14
|
+
vi.mock('../../../utils', () => ({ useHandleMutate: () => vi.fn() }));
|
|
15
|
+
|
|
16
|
+
import StockRulesAddOrUpdate from './add-stock-rules.component';
|
|
17
|
+
|
|
18
|
+
describe('StockRulesAddOrUpdate', () => {
|
|
19
|
+
it('disables location changes while editing a stock rule', () => {
|
|
20
|
+
render(
|
|
21
|
+
<StockRulesAddOrUpdate
|
|
22
|
+
{...mockWorkspace2Props({
|
|
23
|
+
model: {
|
|
24
|
+
uuid: 'rule-uuid',
|
|
25
|
+
stockItemUuid: 'item-uuid',
|
|
26
|
+
name: 'Low stock alert',
|
|
27
|
+
description: '',
|
|
28
|
+
locationUuid: 'location-uuid',
|
|
29
|
+
locationName: 'Main pharmacy',
|
|
30
|
+
enabled: true,
|
|
31
|
+
stockItemPackagingUOMUuid: 'packaging-uom-uuid',
|
|
32
|
+
packagingUomName: 'Box',
|
|
33
|
+
lastEvaluation: new Date('2025-01-01T00:00:00Z'),
|
|
34
|
+
nextEvaluation: new Date('2025-01-02T00:00:00Z'),
|
|
35
|
+
lastActionDate: new Date('2025-01-01T00:00:00Z'),
|
|
36
|
+
permission: {
|
|
37
|
+
canView: true,
|
|
38
|
+
canEdit: true,
|
|
39
|
+
canApprove: false,
|
|
40
|
+
canReceiveItems: false,
|
|
41
|
+
canDisplayReceivedItems: false,
|
|
42
|
+
isRequisitionAndCanIssueStock: false,
|
|
43
|
+
canUpdateBatchInformation: false,
|
|
44
|
+
},
|
|
45
|
+
enableDescendants: false,
|
|
46
|
+
},
|
|
47
|
+
})}
|
|
48
|
+
/>,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
expect(screen.getByRole('combobox', { name: /location/i })).toBeDisabled();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -157,16 +157,20 @@ const StockRulesAddOrUpdate: React.FC<Workspace2DefinitionProps<AddStockRuleProp
|
|
|
157
157
|
() => {
|
|
158
158
|
showSnackbar({
|
|
159
159
|
isLowContrast: true,
|
|
160
|
-
title: t('addedRule', 'Add rule'),
|
|
160
|
+
title: model ? t('editStockRule', 'Edit Stock Rule') : t('addedRule', 'Add rule'),
|
|
161
161
|
kind: 'success',
|
|
162
|
-
subtitle:
|
|
162
|
+
subtitle: model
|
|
163
|
+
? t('stockRuleEditedSuccessfully', 'Stock rule edited successfully')
|
|
164
|
+
: t('stockRuleAddedSuccessfully', 'Stock rule added successfully'),
|
|
163
165
|
});
|
|
164
166
|
handleMutate(`${restBaseUrl}/stockmanagement/stockrule`);
|
|
165
167
|
closeWorkspace();
|
|
166
168
|
},
|
|
167
169
|
(error) => {
|
|
168
170
|
showSnackbar({
|
|
169
|
-
title:
|
|
171
|
+
title: model
|
|
172
|
+
? t('errorEditingRule', 'Error editing a rule')
|
|
173
|
+
: t('errorAddingRule', 'Error adding a rule'),
|
|
170
174
|
kind: 'error',
|
|
171
175
|
isLowContrast: true,
|
|
172
176
|
subtitle: error?.message,
|
|
@@ -190,6 +194,7 @@ const StockRulesAddOrUpdate: React.FC<Workspace2DefinitionProps<AddStockRuleProp
|
|
|
190
194
|
className="select-field"
|
|
191
195
|
labelText={t('location', 'Location')}
|
|
192
196
|
id="location"
|
|
197
|
+
disabled={Boolean(model)}
|
|
193
198
|
value={formModel?.locationUuid ? formModel.locationUuid : ''}
|
|
194
199
|
onChange={onLocationChange}
|
|
195
200
|
>
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { type FetchResponse, openmrsFetch, restBaseUrl } from '@openmrs/esm-framework';
|
|
3
|
+
import { type StockRule } from '../../../core/api/types/stockItem/StockRule';
|
|
4
|
+
import { createOrUpdateStockRule } from './stock-rules.resource';
|
|
5
|
+
|
|
6
|
+
describe('createOrUpdateStockRule', () => {
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
vi.mocked(openmrsFetch).mockResolvedValue({} as FetchResponse);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('sends only updatable properties when editing a stock rule', async () => {
|
|
12
|
+
const rule = {
|
|
13
|
+
uuid: 'rule-uuid',
|
|
14
|
+
stockItemUuid: 'item-uuid',
|
|
15
|
+
name: 'Updated rule',
|
|
16
|
+
description: 'Description',
|
|
17
|
+
locationUuid: 'location-uuid',
|
|
18
|
+
locationName: 'Location',
|
|
19
|
+
quantity: 5,
|
|
20
|
+
stockItemPackagingUOMUuid: 'packaging-uom-uuid',
|
|
21
|
+
packagingUomName: 'Box',
|
|
22
|
+
enabled: true,
|
|
23
|
+
evaluationFrequency: 60,
|
|
24
|
+
lastEvaluation: new Date('2025-01-01T00:00:00Z'),
|
|
25
|
+
nextEvaluation: new Date('2025-01-02T00:00:00Z'),
|
|
26
|
+
lastActionDate: new Date('2025-01-01T00:00:00Z'),
|
|
27
|
+
actionFrequency: 120,
|
|
28
|
+
alertRole: 'Pharmacist',
|
|
29
|
+
mailRole: 'Manager',
|
|
30
|
+
permission: { canView: true, canEdit: true },
|
|
31
|
+
enableDescendants: false,
|
|
32
|
+
dateCreated: new Date('2024-01-01T00:00:00Z'),
|
|
33
|
+
nextActionDate: new Date('2025-01-03T00:00:00Z'),
|
|
34
|
+
} as StockRule;
|
|
35
|
+
|
|
36
|
+
await createOrUpdateStockRule(rule);
|
|
37
|
+
|
|
38
|
+
expect(openmrsFetch).toHaveBeenCalledWith(
|
|
39
|
+
`${restBaseUrl}/stockmanagement/stockrule/rule-uuid`,
|
|
40
|
+
expect.objectContaining({
|
|
41
|
+
method: 'POST',
|
|
42
|
+
body: {
|
|
43
|
+
name: 'Updated rule',
|
|
44
|
+
description: 'Description',
|
|
45
|
+
quantity: 5,
|
|
46
|
+
stockItemPackagingUOMUuid: 'packaging-uom-uuid',
|
|
47
|
+
enabled: true,
|
|
48
|
+
evaluationFrequency: 60,
|
|
49
|
+
actionFrequency: 120,
|
|
50
|
+
alertRole: 'Pharmacist',
|
|
51
|
+
mailRole: 'Manager',
|
|
52
|
+
enableDescendants: false,
|
|
53
|
+
},
|
|
54
|
+
}),
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -55,9 +55,9 @@ export function deleteStockRule(ids: string[]) {
|
|
|
55
55
|
|
|
56
56
|
// Create Or Update Stock Rule
|
|
57
57
|
export function createOrUpdateStockRule(item: StockRule) {
|
|
58
|
-
const
|
|
58
|
+
const isUpdate = item.uuid != null;
|
|
59
59
|
|
|
60
|
-
const apiUrl = `${restBaseUrl}/stockmanagement/stockrule${
|
|
60
|
+
const apiUrl = `${restBaseUrl}/stockmanagement/stockrule${isUpdate ? '/' + item.uuid : ''}`;
|
|
61
61
|
const abortController = new AbortController();
|
|
62
62
|
return openmrsFetch(apiUrl, {
|
|
63
63
|
method: 'POST',
|
|
@@ -65,7 +65,19 @@ export function createOrUpdateStockRule(item: StockRule) {
|
|
|
65
65
|
'Content-Type': 'application/json',
|
|
66
66
|
},
|
|
67
67
|
signal: abortController.signal,
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
body: isUpdate
|
|
69
|
+
? {
|
|
70
|
+
name: item.name,
|
|
71
|
+
description: item.description,
|
|
72
|
+
quantity: item.quantity,
|
|
73
|
+
stockItemPackagingUOMUuid: item.stockItemPackagingUOMUuid,
|
|
74
|
+
enabled: item.enabled,
|
|
75
|
+
evaluationFrequency: item.evaluationFrequency,
|
|
76
|
+
actionFrequency: item.actionFrequency,
|
|
77
|
+
alertRole: item.alertRole,
|
|
78
|
+
mailRole: item.mailRole,
|
|
79
|
+
enableDescendants: item.enableDescendants,
|
|
80
|
+
}
|
|
81
|
+
: { ...item },
|
|
70
82
|
});
|
|
71
83
|
}
|
package/translations/en.json
CHANGED
|
@@ -122,6 +122,7 @@
|
|
|
122
122
|
"errorDeletingRule": "Error deleting a rule",
|
|
123
123
|
"errorDeletingSource": "Error deleting a source",
|
|
124
124
|
"errorDeletingUserScope": "Error deleting a user scope",
|
|
125
|
+
"errorEditingRule": "Error editing a rule",
|
|
125
126
|
"errorEditingStockItem": "Error editing a stock Item",
|
|
126
127
|
"errorFetchingStockSourceTypes": "Error fetching stock source types",
|
|
127
128
|
"errorLoadingStockOperation": "Error loading stock operation",
|
|
@@ -374,6 +375,7 @@
|
|
|
374
375
|
"stockReportsTableHeader": "List of reports requested by users.",
|
|
375
376
|
"stockRuleAddedSuccessfully": "Stock rule added successfully",
|
|
376
377
|
"stockRuleDeletedSuccessfully": "Stock Rule Deleted Successfully",
|
|
378
|
+
"stockRuleEditedSuccessfully": "Stock rule edited successfully",
|
|
377
379
|
"stockRules": "Stock rules",
|
|
378
380
|
"stockSource": "Stock source",
|
|
379
381
|
"stockSourceAddedSuccessfully": "Stock source added successfully",
|