erpnext-queue-client 2.9.2 → 2.9.4
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/erpnext/doctypeSubmittableResourceRequest.js +22 -9
- package/dist/erpnext/doctypeSubmittableResourceRequest.test.d.ts +1 -0
- package/dist/erpnext/doctypeSubmittableResourceRequest.test.js +64 -0
- package/dist/erpnext/doctypes/salesInvoice.d.ts +86 -194
- package/dist/erpnext/model/SalesInvoice.d.ts +107 -465
- package/dist/erpnext/model/SalesInvoice.js +3 -4
- package/package.json +1 -1
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ERPNextDoctypeSubmittableResourceRequest = void 0;
|
|
7
7
|
const zod_1 = __importDefault(require("zod"));
|
|
8
|
+
const logger_1 = require("../utils/logger");
|
|
8
9
|
const doctypeResourceRequest_1 = require("./doctypeResourceRequest");
|
|
9
10
|
const ERPNextDocTypeMeta_1 = require("./model/ERPNextDocTypeMeta");
|
|
10
11
|
class ERPNextDoctypeSubmittableResourceRequest extends doctypeResourceRequest_1.ERPNextDoctypeResourceRequest {
|
|
@@ -15,15 +16,27 @@ class ERPNextDoctypeSubmittableResourceRequest extends doctypeResourceRequest_1.
|
|
|
15
16
|
super(temporalClient, resourceName, mergedModel);
|
|
16
17
|
}
|
|
17
18
|
async cancel({ resourceId, }) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
try {
|
|
20
|
+
return await this.updateById({
|
|
21
|
+
resourceId,
|
|
22
|
+
inputValidationModel: zod_1.default
|
|
23
|
+
.object({ docstatus: ERPNextDocTypeMeta_1.Docstatus })
|
|
24
|
+
.describe("Cancel Input"),
|
|
25
|
+
body: {
|
|
26
|
+
docstatus: 2,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
32
|
+
if (!message.includes("Cannot edit cancelled document"))
|
|
33
|
+
throw err;
|
|
34
|
+
const doc = await this.getById({ resourceId });
|
|
35
|
+
if (doc?.docstatus !== 2)
|
|
36
|
+
throw err;
|
|
37
|
+
logger_1.lg.info(`${this.resourceName} ${resourceId} is already cancelled`);
|
|
38
|
+
return doc;
|
|
39
|
+
}
|
|
27
40
|
}
|
|
28
41
|
async submit({ resourceId, }) {
|
|
29
42
|
return this.updateById({
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const zod_1 = require("zod");
|
|
4
|
+
const doctypeSubmittableResourceRequest_1 = require("./doctypeSubmittableResourceRequest");
|
|
5
|
+
const TestModel = zod_1.z.object({ name: zod_1.z.string() });
|
|
6
|
+
const cancelledDocError = new Error('Error 417: {"exception":"frappe.exceptions.ValidationError: Cannot edit cancelled document","exc_type":"ValidationError"}');
|
|
7
|
+
function createRequest(executeERPNextRequestWorkflow) {
|
|
8
|
+
return new doctypeSubmittableResourceRequest_1.ERPNextDoctypeSubmittableResourceRequest({ executeERPNextRequestWorkflow }, "Purchase Receipt", TestModel);
|
|
9
|
+
}
|
|
10
|
+
describe("cancel", () => {
|
|
11
|
+
test("returns the updated document when the cancel request succeeds", async () => {
|
|
12
|
+
const doc = { name: "PR-1", docstatus: 2 };
|
|
13
|
+
const executeERPNextRequestWorkflow = vi
|
|
14
|
+
.fn()
|
|
15
|
+
.mockResolvedValue({ data: doc });
|
|
16
|
+
const request = createRequest(executeERPNextRequestWorkflow);
|
|
17
|
+
const result = await request.cancel({ resourceId: "PR-1" });
|
|
18
|
+
expect(result).toEqual(doc);
|
|
19
|
+
expect(executeERPNextRequestWorkflow).toHaveBeenCalledTimes(1);
|
|
20
|
+
const options = executeERPNextRequestWorkflow.mock.calls[0]?.[1];
|
|
21
|
+
expect(options.requestMethod).toBe("PUT");
|
|
22
|
+
expect(options.body).toEqual({ docstatus: 2 });
|
|
23
|
+
});
|
|
24
|
+
test("treats an already cancelled document as success", async () => {
|
|
25
|
+
const doc = { name: "PR-1", docstatus: 2 };
|
|
26
|
+
const executeERPNextRequestWorkflow = vi
|
|
27
|
+
.fn()
|
|
28
|
+
.mockRejectedValueOnce(cancelledDocError)
|
|
29
|
+
.mockResolvedValueOnce({ data: doc });
|
|
30
|
+
const request = createRequest(executeERPNextRequestWorkflow);
|
|
31
|
+
const result = await request.cancel({ resourceId: "PR-1" });
|
|
32
|
+
expect(result).toEqual(doc);
|
|
33
|
+
expect(executeERPNextRequestWorkflow).toHaveBeenCalledTimes(2);
|
|
34
|
+
const getOptions = executeERPNextRequestWorkflow.mock.calls[1]?.[1];
|
|
35
|
+
expect(getOptions.requestMethod).toBe("GET");
|
|
36
|
+
expect(getOptions.resourceId).toBe("PR-1");
|
|
37
|
+
});
|
|
38
|
+
test("rethrows when the document is not cancelled after the error", async () => {
|
|
39
|
+
const executeERPNextRequestWorkflow = vi
|
|
40
|
+
.fn()
|
|
41
|
+
.mockRejectedValueOnce(cancelledDocError)
|
|
42
|
+
.mockResolvedValueOnce({ data: { name: "PR-1", docstatus: 1 } });
|
|
43
|
+
const request = createRequest(executeERPNextRequestWorkflow);
|
|
44
|
+
await expect(request.cancel({ resourceId: "PR-1" })).rejects.toThrow("Cannot edit cancelled document");
|
|
45
|
+
expect(executeERPNextRequestWorkflow).toHaveBeenCalledTimes(2);
|
|
46
|
+
});
|
|
47
|
+
test("rethrows when the document no longer exists", async () => {
|
|
48
|
+
const executeERPNextRequestWorkflow = vi
|
|
49
|
+
.fn()
|
|
50
|
+
.mockRejectedValueOnce(cancelledDocError)
|
|
51
|
+
.mockRejectedValueOnce(new Error("Error 404: Not found"));
|
|
52
|
+
const request = createRequest(executeERPNextRequestWorkflow);
|
|
53
|
+
await expect(request.cancel({ resourceId: "PR-1" })).rejects.toThrow("Cannot edit cancelled document");
|
|
54
|
+
expect(executeERPNextRequestWorkflow).toHaveBeenCalledTimes(2);
|
|
55
|
+
});
|
|
56
|
+
test("rethrows unrelated errors without checking the document", async () => {
|
|
57
|
+
const executeERPNextRequestWorkflow = vi
|
|
58
|
+
.fn()
|
|
59
|
+
.mockRejectedValueOnce(new Error("Error 500: Internal Server Error"));
|
|
60
|
+
const request = createRequest(executeERPNextRequestWorkflow);
|
|
61
|
+
await expect(request.cancel({ resourceId: "PR-1" })).rejects.toThrow("Error 500");
|
|
62
|
+
expect(executeERPNextRequestWorkflow).toHaveBeenCalledTimes(1);
|
|
63
|
+
});
|
|
64
|
+
});
|