repzo-sap-absjo 1.0.6 → 1.0.8
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/changelog.md +4 -0
- package/lib/actions/create_invoice.d.ts +13 -19
- package/lib/actions/create_invoice.js +216 -336
- package/lib/actions/create_payment.d.ts +1 -4
- package/lib/actions/create_payment.js +125 -171
- package/lib/actions/create_proforma.d.ts +1 -4
- package/lib/actions/create_proforma.js +165 -268
- package/lib/actions/create_return_invoice.d.ts +1 -4
- package/lib/actions/create_return_invoice.js +177 -295
- package/lib/actions/create_transfer.d.ts +1 -4
- package/lib/actions/create_transfer.js +143 -198
- package/lib/actions/index.js +15 -23
- package/lib/commands/adjust_inventory.d.ts +2 -4
- package/lib/commands/adjust_inventory.js +160 -290
- package/lib/commands/bank.d.ts +2 -4
- package/lib/commands/bank.js +157 -279
- package/lib/commands/basic.js +47 -66
- package/lib/commands/category.d.ts +1 -3
- package/lib/commands/category.js +104 -178
- package/lib/commands/channel.d.ts +1 -3
- package/lib/commands/channel.js +117 -198
- package/lib/commands/client.d.ts +32 -34
- package/lib/commands/client.js +244 -404
- package/lib/commands/client_disabled.d.ts +1 -3
- package/lib/commands/client_disabled.js +94 -163
- package/lib/commands/index.d.ts +11 -15
- package/lib/commands/index.js +60 -60
- package/lib/commands/join.js +66 -192
- package/lib/commands/measureunit.d.ts +14 -19
- package/lib/commands/measureunit.js +191 -289
- package/lib/commands/measureunit_family.d.ts +8 -10
- package/lib/commands/measureunit_family.js +138 -250
- package/lib/commands/payment_term.d.ts +1 -3
- package/lib/commands/payment_term.js +123 -202
- package/lib/commands/price_list.d.ts +15 -15
- package/lib/commands/price_list.js +327 -571
- package/lib/commands/product.d.ts +30 -32
- package/lib/commands/product.js +243 -425
- package/lib/commands/product_disabled.d.ts +1 -3
- package/lib/commands/product_disabled.js +94 -164
- package/lib/commands/rep.js +141 -221
- package/lib/commands/tag.js +109 -174
- package/lib/commands/tax.js +112 -177
- package/lib/commands/warehouse.d.ts +1 -3
- package/lib/commands/warehouse.js +119 -207
- package/lib/index.d.ts +12 -21
- package/lib/test/actions/create_invoice.js +188 -193
- package/lib/test/actions/create_payment.js +107 -112
- package/lib/test/actions/create_proforma.js +216 -220
- package/lib/test/actions/create_return_invoice.js +200 -205
- package/lib/test/actions/create_transfer.js +115 -120
- package/lib/test/commands/adjust_inventory.js +90 -90
- package/lib/test/commands/bank.js +90 -90
- package/lib/test/commands/basic.js +327 -328
- package/lib/test/commands/category.js +90 -90
- package/lib/test/commands/channel.js +90 -90
- package/lib/test/commands/client.js +353 -355
- package/lib/test/commands/client_disabled.js +90 -90
- package/lib/test/commands/join.js +327 -328
- package/lib/test/commands/measureunit.js +90 -90
- package/lib/test/commands/measureunit_family.js +90 -90
- package/lib/test/commands/payment_term.js +90 -90
- package/lib/test/commands/price_list.js +337 -90
- package/lib/test/commands/product.js +90 -90
- package/lib/test/commands/product_disabled.js +90 -90
- package/lib/test/commands/rep.js +344 -346
- package/lib/test/commands/tag.js +90 -90
- package/lib/test/commands/tax.js +90 -90
- package/lib/test/commands/warehouse.js +90 -90
- package/lib/types.d.ts +60 -83
- package/lib/util.d.ts +19 -70
- package/lib/util.js +144 -170
- package/package.json +1 -1
- package/src/actions/create_invoice.ts +35 -0
- package/src/actions/create_payment.ts +35 -0
- package/src/actions/create_proforma.ts +35 -0
- package/src/actions/create_return_invoice.ts +35 -0
- package/src/actions/create_transfer.ts +34 -0
- package/src/commands/price_list.ts +40 -4
- package/src/test/commands/price_list.ts +263 -13
|
@@ -1,206 +1,151 @@
|
|
|
1
1
|
import Repzo from "repzo";
|
|
2
|
-
import { _create, send_command_to_marketplace } from "../util.js";
|
|
2
|
+
import { _create, send_command_to_marketplace, } from "../util.js";
|
|
3
3
|
import { v4 as uuid } from "uuid";
|
|
4
4
|
export const create_transfer = async (event, options) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const action_sync_id =
|
|
11
|
-
((_b = event === null || event === void 0 ? void 0 : event.headers) ===
|
|
12
|
-
null || _b === void 0
|
|
13
|
-
? void 0
|
|
14
|
-
: _b.action_sync_id) || uuid();
|
|
15
|
-
const actionLog = new Repzo.ActionLogs(repzo, action_sync_id);
|
|
16
|
-
let body;
|
|
17
|
-
try {
|
|
18
|
-
// console.log("create_transfer");
|
|
19
|
-
await actionLog.load(action_sync_id);
|
|
20
|
-
body = event.body;
|
|
5
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
6
|
+
const repzo = new Repzo((_a = options.data) === null || _a === void 0 ? void 0 : _a.repzoApiKey, { env: options.env });
|
|
7
|
+
const action_sync_id = ((_b = event === null || event === void 0 ? void 0 : event.headers) === null || _b === void 0 ? void 0 : _b.action_sync_id) || uuid();
|
|
8
|
+
const actionLog = new Repzo.ActionLogs(repzo, action_sync_id);
|
|
9
|
+
let body;
|
|
21
10
|
try {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
11
|
+
// console.log("create_transfer");
|
|
12
|
+
await actionLog.load(action_sync_id);
|
|
13
|
+
body = event.body;
|
|
14
|
+
try {
|
|
15
|
+
if (body)
|
|
16
|
+
body = JSON.parse(body);
|
|
17
|
+
}
|
|
18
|
+
catch (e) { }
|
|
19
|
+
const repzo_serial_number = (_c = body === null || body === void 0 ? void 0 : body.serial_number) === null || _c === void 0 ? void 0 : _c.formatted;
|
|
20
|
+
try {
|
|
21
|
+
if (body === null || body === void 0 ? void 0 : body._id) {
|
|
22
|
+
body.integration_meta = (body === null || body === void 0 ? void 0 : body.integration_meta) || {};
|
|
23
|
+
body.integration_meta.sync_to_sap_started = true;
|
|
24
|
+
body.integration_meta.sync_to_sap_succeeded =
|
|
25
|
+
body.integration_meta.sync_to_sap_succeeded || false;
|
|
26
|
+
await repzo.transfer.update(body._id, {
|
|
27
|
+
integration_meta: body.integration_meta,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
console.error(e);
|
|
33
|
+
await actionLog
|
|
34
|
+
.addDetail(`Failed updating integration_meta of Transfer: ${repzo_serial_number}`)
|
|
35
|
+
.commit();
|
|
36
|
+
}
|
|
37
|
+
await actionLog
|
|
38
|
+
.addDetail(`Transfer - ${repzo_serial_number} => ${body === null || body === void 0 ? void 0 : body.sync_id}`)
|
|
39
|
+
.addDetail(`Repzo => SAP: Started Create Transfer - ${repzo_serial_number}`)
|
|
40
|
+
.commit();
|
|
41
|
+
const SAP_HOST_URL = (_d = options.data) === null || _d === void 0 ? void 0 : _d.sapHostUrl;
|
|
42
|
+
if (!SAP_HOST_URL)
|
|
43
|
+
throw `SAP Host Url is missing and Required: ${SAP_HOST_URL}`;
|
|
44
|
+
const repzo_transfer = body;
|
|
45
|
+
// Get Repzo Rep
|
|
46
|
+
let repzo_rep;
|
|
47
|
+
if (repzo_transfer.creator.type == "rep") {
|
|
48
|
+
repzo_rep = await repzo.rep.get((_e = repzo_transfer === null || repzo_transfer === void 0 ? void 0 : repzo_transfer.creator) === null || _e === void 0 ? void 0 : _e._id);
|
|
49
|
+
if (!repzo_rep)
|
|
50
|
+
throw `Rep with _id: ${repzo_transfer.creator._id} not found in Repzo`;
|
|
51
|
+
}
|
|
52
|
+
// Get Repzo Products with its own Populated MeasureUnit
|
|
53
|
+
const repzo_product_ids = {};
|
|
54
|
+
(_f = repzo_transfer.variants) === null || _f === void 0 ? void 0 : _f.forEach((item) => {
|
|
55
|
+
if (item === null || item === void 0 ? void 0 : item.product_id) {
|
|
56
|
+
repzo_product_ids[item.product_id.toString()] = true;
|
|
57
|
+
}
|
|
66
58
|
});
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
]
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
//@ts-ignore
|
|
145
|
-
ToWarehouse:
|
|
146
|
-
(_l = repzo_transfer.to) === null || _l === void 0 ? void 0 : _l.code,
|
|
147
|
-
});
|
|
59
|
+
const repzo_products = await repzo.patchAction.create({
|
|
60
|
+
slug: "product",
|
|
61
|
+
readQuery: [
|
|
62
|
+
{
|
|
63
|
+
key: "_id",
|
|
64
|
+
value: Object.keys(repzo_product_ids),
|
|
65
|
+
operator: "in",
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
}, { per_page: 50000, populatedKeys: ["measureunit"] });
|
|
69
|
+
// Prepare Transfer Items
|
|
70
|
+
const variants = [];
|
|
71
|
+
for (let i = 0; i < ((_g = repzo_transfer.variants) === null || _g === void 0 ? void 0 : _g.length); i++) {
|
|
72
|
+
const repzo_transfer_item = repzo_transfer.variants[i];
|
|
73
|
+
const repzo_product = (_h = repzo_products === null || repzo_products === void 0 ? void 0 : repzo_products.data) === null || _h === void 0 ? void 0 : _h.find(
|
|
74
|
+
//@ts-ignore
|
|
75
|
+
(p) => { var _a; return p._id.toString() == ((_a = repzo_transfer_item.product_id) === null || _a === void 0 ? void 0 : _a.toString()); });
|
|
76
|
+
if (!repzo_product) {
|
|
77
|
+
// console.log(
|
|
78
|
+
// `Product with _id: ${repzo_transfer_item.product_id} was not found In Repzo`,
|
|
79
|
+
// );
|
|
80
|
+
throw new Error(`Product with _id: ${repzo_transfer_item.product_id} was not found in Repzo`);
|
|
81
|
+
}
|
|
82
|
+
const repzo_measure_unit = repzo_product.sv_measureUnit;
|
|
83
|
+
if (!(repzo_measure_unit === null || repzo_measure_unit === void 0 ? void 0 : repzo_measure_unit._id)) {
|
|
84
|
+
// console.log(
|
|
85
|
+
// `Measureunit with _id: ${repzo_product.sv_measureUnit?.toString()} was not found`,
|
|
86
|
+
// );
|
|
87
|
+
throw new Error(`Measureunit with _id: ${(_j = repzo_product.sv_measureUnit) === null || _j === void 0 ? void 0 : _j.toString()} was not found`);
|
|
88
|
+
}
|
|
89
|
+
variants.push({
|
|
90
|
+
//@ts-ignore
|
|
91
|
+
ItemCode: repzo_transfer_item.variant_name,
|
|
92
|
+
Quantity: repzo_transfer_item.qty / Number(repzo_measure_unit.factor),
|
|
93
|
+
//@ts-ignore
|
|
94
|
+
FromWarehouse: (_k = repzo_transfer.from) === null || _k === void 0 ? void 0 : _k.code,
|
|
95
|
+
//@ts-ignore
|
|
96
|
+
ToWarehouse: (_l = repzo_transfer.to) === null || _l === void 0 ? void 0 : _l.code,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
const sap_transfer = {
|
|
100
|
+
StockTransferID: body.serial_number.formatted,
|
|
101
|
+
SalesPersonCode: repzo_rep
|
|
102
|
+
? repzo_rep.integration_id
|
|
103
|
+
: (_m = options.data) === null || _m === void 0 ? void 0 : _m.SalesPersonCode,
|
|
104
|
+
FromWarehouse: body.from.code,
|
|
105
|
+
ToWarehouse: body.to.code,
|
|
106
|
+
RepzoStockTransferLines: variants,
|
|
107
|
+
};
|
|
108
|
+
// console.dir(sap_transfer, { depth: null });
|
|
109
|
+
await actionLog
|
|
110
|
+
.addDetail(`Repzo => SAP: Transfer - ${repzo_serial_number}`, sap_transfer)
|
|
111
|
+
.commit();
|
|
112
|
+
const result = await _create(SAP_HOST_URL, "/AddStockTransfer", sap_transfer);
|
|
113
|
+
// console.log(result);
|
|
114
|
+
try {
|
|
115
|
+
if (body === null || body === void 0 ? void 0 : body._id) {
|
|
116
|
+
body.integration_meta = (body === null || body === void 0 ? void 0 : body.integration_meta) || {};
|
|
117
|
+
body.integration_meta.sync_to_sap_succeeded = true;
|
|
118
|
+
await repzo.transfer.update(body._id, {
|
|
119
|
+
integration_meta: body.integration_meta,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch (e) {
|
|
124
|
+
console.error(e);
|
|
125
|
+
await actionLog
|
|
126
|
+
.addDetail(`Failed updating integration_meta of Transfer: ${repzo_serial_number}`)
|
|
127
|
+
.commit();
|
|
128
|
+
}
|
|
129
|
+
await actionLog
|
|
130
|
+
.addDetail(`SAP Responded with `, result)
|
|
131
|
+
.addDetail(`Repzo => SAP: Transfer - ${repzo_serial_number}`)
|
|
132
|
+
.setStatus("success")
|
|
133
|
+
.setBody(body)
|
|
134
|
+
.commit();
|
|
135
|
+
return result;
|
|
148
136
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
.addDetail(
|
|
163
|
-
`Repzo => SAP: Transfer - ${repzo_serial_number}`,
|
|
164
|
-
sap_transfer
|
|
165
|
-
)
|
|
166
|
-
.commit();
|
|
167
|
-
const result = await _create(
|
|
168
|
-
SAP_HOST_URL,
|
|
169
|
-
"/AddStockTransfer",
|
|
170
|
-
sap_transfer
|
|
171
|
-
);
|
|
172
|
-
// console.log(result);
|
|
173
|
-
await actionLog
|
|
174
|
-
.addDetail(`SAP Responded with `, result)
|
|
175
|
-
.addDetail(`Repzo => SAP: Transfer - ${repzo_serial_number}`)
|
|
176
|
-
.setStatus("success")
|
|
177
|
-
.setBody(body)
|
|
178
|
-
.commit();
|
|
179
|
-
return result;
|
|
180
|
-
} catch (e) {
|
|
181
|
-
//@ts-ignore
|
|
182
|
-
console.error((e === null || e === void 0 ? void 0 : e.response) || e);
|
|
183
|
-
await actionLog.setStatus("fail", e).setBody(body).commit();
|
|
184
|
-
if (
|
|
185
|
-
(_p =
|
|
186
|
-
(_o =
|
|
187
|
-
options === null || options === void 0 ? void 0 : options.data) ===
|
|
188
|
-
null || _o === void 0
|
|
189
|
-
? void 0
|
|
190
|
-
: _o.transfers) === null || _p === void 0
|
|
191
|
-
? void 0
|
|
192
|
-
: _p.adjustInventoryInFailedTransfer
|
|
193
|
-
) {
|
|
194
|
-
send_command_to_marketplace({
|
|
195
|
-
command: "adjust_inventory",
|
|
196
|
-
app_id: options.app_id,
|
|
197
|
-
env: options.env,
|
|
198
|
-
repzoApiKey:
|
|
199
|
-
(_q = options.data) === null || _q === void 0
|
|
200
|
-
? void 0
|
|
201
|
-
: _q.repzoApiKey,
|
|
202
|
-
});
|
|
137
|
+
catch (e) {
|
|
138
|
+
//@ts-ignore
|
|
139
|
+
console.error((e === null || e === void 0 ? void 0 : e.response) || e);
|
|
140
|
+
await actionLog.setStatus("fail", e).setBody(body).commit();
|
|
141
|
+
if ((_p = (_o = options === null || options === void 0 ? void 0 : options.data) === null || _o === void 0 ? void 0 : _o.transfers) === null || _p === void 0 ? void 0 : _p.adjustInventoryInFailedTransfer) {
|
|
142
|
+
send_command_to_marketplace({
|
|
143
|
+
command: "adjust_inventory",
|
|
144
|
+
app_id: options.app_id,
|
|
145
|
+
env: options.env,
|
|
146
|
+
repzoApiKey: (_q = options.data) === null || _q === void 0 ? void 0 : _q.repzoApiKey,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
throw e;
|
|
203
150
|
}
|
|
204
|
-
throw e;
|
|
205
|
-
}
|
|
206
151
|
};
|
package/lib/actions/index.js
CHANGED
|
@@ -4,28 +4,20 @@ import { create_proforma } from "./create_proforma.js";
|
|
|
4
4
|
import { create_payment } from "./create_payment.js";
|
|
5
5
|
import { create_transfer } from "./create_transfer.js";
|
|
6
6
|
export const actions = async (event, options) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return await create_transfer(event, options);
|
|
23
|
-
default:
|
|
24
|
-
throw `Route: ${
|
|
25
|
-
(_b = event.queryStringParameters) === null || _b === void 0
|
|
26
|
-
? void 0
|
|
27
|
-
: _b.action
|
|
28
|
-
} not found`;
|
|
29
|
-
}
|
|
7
|
+
var _a, _b;
|
|
8
|
+
switch ((_a = event.queryStringParameters) === null || _a === void 0 ? void 0 : _a.action) {
|
|
9
|
+
case "create_invoice":
|
|
10
|
+
return await create_invoice(event, options);
|
|
11
|
+
case "create_return_invoice":
|
|
12
|
+
return await create_return_invoice(event, options);
|
|
13
|
+
case "create_proforma":
|
|
14
|
+
return await create_proforma(event, options);
|
|
15
|
+
case "create_payment":
|
|
16
|
+
return await create_payment(event, options);
|
|
17
|
+
case "create_transfer":
|
|
18
|
+
return await create_transfer(event, options);
|
|
19
|
+
default:
|
|
20
|
+
throw `Route: ${(_b = event.queryStringParameters) === null || _b === void 0 ? void 0 : _b.action} not found`;
|
|
21
|
+
}
|
|
30
22
|
};
|
|
31
23
|
export const actionsList = [];
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { CommandEvent, Result } from "../types";
|
|
2
|
-
export declare const adjust_inventory: (commandEvent: CommandEvent) => Promise<
|
|
3
|
-
Result & {
|
|
2
|
+
export declare const adjust_inventory: (commandEvent: CommandEvent) => Promise<Result & {
|
|
4
3
|
items_failed: number;
|
|
5
|
-
|
|
6
|
-
>;
|
|
4
|
+
}>;
|