repzo-sap-absjo 1.0.8 → 1.0.9
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/lib/actions/create_invoice.d.ts +19 -13
- package/lib/actions/create_invoice.js +363 -214
- package/lib/actions/create_payment.d.ts +4 -1
- package/lib/actions/create_payment.js +200 -125
- package/lib/actions/create_proforma.d.ts +4 -1
- package/lib/actions/create_proforma.js +290 -165
- package/lib/actions/create_return_invoice.d.ts +4 -1
- package/lib/actions/create_return_invoice.js +321 -177
- package/lib/actions/create_transfer.d.ts +4 -1
- package/lib/actions/create_transfer.js +220 -143
- package/lib/actions/index.js +23 -15
- package/lib/commands/adjust_inventory.d.ts +4 -2
- package/lib/commands/adjust_inventory.js +290 -160
- package/lib/commands/bank.d.ts +4 -2
- package/lib/commands/bank.js +279 -157
- package/lib/commands/basic.js +66 -47
- package/lib/commands/category.d.ts +3 -1
- package/lib/commands/category.js +178 -104
- package/lib/commands/channel.d.ts +3 -1
- package/lib/commands/channel.js +198 -117
- package/lib/commands/client.d.ts +34 -32
- package/lib/commands/client.js +404 -244
- package/lib/commands/client_disabled.d.ts +3 -1
- package/lib/commands/client_disabled.js +163 -94
- package/lib/commands/index.d.ts +15 -11
- package/lib/commands/index.js +60 -60
- package/lib/commands/join.js +192 -66
- package/lib/commands/measureunit.d.ts +19 -14
- package/lib/commands/measureunit.js +289 -191
- package/lib/commands/measureunit_family.d.ts +10 -8
- package/lib/commands/measureunit_family.js +250 -138
- package/lib/commands/payment_term.d.ts +3 -1
- package/lib/commands/payment_term.js +202 -123
- package/lib/commands/price_list.d.ts +15 -15
- package/lib/commands/price_list.js +612 -326
- package/lib/commands/product.d.ts +32 -30
- package/lib/commands/product.js +425 -243
- package/lib/commands/product_disabled.d.ts +3 -1
- package/lib/commands/product_disabled.js +164 -94
- package/lib/commands/rep.js +221 -141
- package/lib/commands/tag.js +174 -109
- package/lib/commands/tax.js +177 -112
- package/lib/commands/warehouse.d.ts +3 -1
- package/lib/commands/warehouse.js +207 -119
- package/lib/index.d.ts +21 -12
- package/lib/test/actions/create_invoice.js +193 -188
- package/lib/test/actions/create_payment.js +112 -107
- package/lib/test/actions/create_proforma.js +220 -216
- package/lib/test/actions/create_return_invoice.js +205 -200
- package/lib/test/actions/create_transfer.js +120 -115
- package/lib/test/commands/adjust_inventory.js +90 -90
- package/lib/test/commands/bank.js +90 -90
- package/lib/test/commands/basic.js +328 -327
- package/lib/test/commands/category.js +90 -90
- package/lib/test/commands/channel.js +90 -90
- package/lib/test/commands/client.js +355 -353
- package/lib/test/commands/client_disabled.js +90 -90
- package/lib/test/commands/join.js +328 -327
- 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 -334
- package/lib/test/commands/product.js +90 -90
- package/lib/test/commands/product_disabled.js +90 -90
- package/lib/test/commands/rep.js +346 -344
- 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 +83 -60
- package/lib/util.d.ts +70 -19
- package/lib/util.js +170 -144
- package/package.json +1 -1
- package/src/actions/create_invoice.ts +4 -13
- package/src/actions/create_payment.ts +4 -13
- package/src/actions/create_proforma.ts +28 -40
- package/src/actions/create_return_invoice.ts +4 -16
- package/src/actions/create_transfer.ts +24 -36
|
@@ -1,148 +1,260 @@
|
|
|
1
1
|
import Repzo from "repzo";
|
|
2
2
|
import _ from "lodash";
|
|
3
|
-
import { update_bench_time, set_error
|
|
3
|
+
import { update_bench_time, set_error } from "../util.js";
|
|
4
4
|
import { get_sap_UoMs } from "./measureunit.js";
|
|
5
5
|
export const sync_measureunit_family = async (commandEvent) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
7
|
+
const repzo = new Repzo(
|
|
8
|
+
(_a = commandEvent.app.formData) === null || _a === void 0
|
|
9
|
+
? void 0
|
|
10
|
+
: _a.repzoApiKey,
|
|
11
|
+
{
|
|
12
|
+
env: commandEvent.env,
|
|
13
|
+
}
|
|
14
|
+
);
|
|
15
|
+
const commandLog = new Repzo.CommandLog(
|
|
16
|
+
repzo,
|
|
17
|
+
commandEvent.app,
|
|
18
|
+
commandEvent.command
|
|
19
|
+
);
|
|
20
|
+
try {
|
|
21
|
+
// console.log("sync_measureunit_family");
|
|
22
|
+
const new_bench_time = new Date().toISOString();
|
|
23
|
+
const bench_time_key = "bench_time_measureunit_family";
|
|
24
|
+
await commandLog.load(commandEvent.sync_id);
|
|
25
|
+
await commandLog
|
|
26
|
+
.addDetail("Repzo SAP: Started Syncing Measure Units Family")
|
|
27
|
+
.commit();
|
|
28
|
+
const nameSpace = commandEvent.nameSpace.join("_");
|
|
29
|
+
const result = {
|
|
30
|
+
sap_total: 0,
|
|
31
|
+
repzo_total: 0,
|
|
32
|
+
sap_UoM_total: 0,
|
|
33
|
+
repzo_UoM_total: 0,
|
|
34
|
+
created: 0,
|
|
35
|
+
updated: 0,
|
|
36
|
+
failed: 0,
|
|
37
|
+
};
|
|
38
|
+
const failed_docs_report = [];
|
|
39
|
+
const sap_UoMs = await get_sap_UoMs(
|
|
40
|
+
commandEvent.app.formData.sapHostUrl,
|
|
41
|
+
{}
|
|
42
|
+
);
|
|
43
|
+
result.sap_UoM_total =
|
|
44
|
+
sap_UoMs === null || sap_UoMs === void 0 ? void 0 : sap_UoMs.length;
|
|
45
|
+
await commandLog
|
|
46
|
+
.addDetail(`${result.sap_UoM_total} Unit of Measures in SAP`)
|
|
47
|
+
.commit();
|
|
48
|
+
let repzo_UoMs = await repzo.measureunit.find({
|
|
49
|
+
disabled: false,
|
|
50
|
+
per_page: 50000,
|
|
51
|
+
});
|
|
52
|
+
result.repzo_UoM_total =
|
|
53
|
+
(_b =
|
|
54
|
+
repzo_UoMs === null || repzo_UoMs === void 0
|
|
55
|
+
? void 0
|
|
56
|
+
: repzo_UoMs.data) === null || _b === void 0
|
|
57
|
+
? void 0
|
|
58
|
+
: _b.length;
|
|
59
|
+
await commandLog
|
|
60
|
+
.addDetail(
|
|
61
|
+
`${
|
|
62
|
+
(_c =
|
|
63
|
+
repzo_UoMs === null || repzo_UoMs === void 0
|
|
64
|
+
? void 0
|
|
65
|
+
: repzo_UoMs.data) === null || _c === void 0
|
|
66
|
+
? void 0
|
|
67
|
+
: _c.length
|
|
68
|
+
} Measure Units in Repzo`
|
|
69
|
+
)
|
|
70
|
+
.commit();
|
|
71
|
+
if (
|
|
72
|
+
!((_d =
|
|
73
|
+
repzo_UoMs === null || repzo_UoMs === void 0
|
|
74
|
+
? void 0
|
|
75
|
+
: repzo_UoMs.data) === null || _d === void 0
|
|
76
|
+
? void 0
|
|
77
|
+
: _d.length)
|
|
78
|
+
) {
|
|
79
|
+
throw "measure units are not found or the nameSpace has more than one";
|
|
80
|
+
}
|
|
81
|
+
repzo_UoMs.data =
|
|
82
|
+
(_e = repzo_UoMs.data) === null || _e === void 0
|
|
83
|
+
? void 0
|
|
84
|
+
: _e.filter((UoM) => UoM.integration_meta);
|
|
85
|
+
const repzo_UoMs_family = await repzo.measureunitFamily.find({
|
|
86
|
+
disabled: false,
|
|
87
|
+
per_page: 50000,
|
|
9
88
|
});
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
89
|
+
result.repzo_total =
|
|
90
|
+
(_f =
|
|
91
|
+
repzo_UoMs_family === null || repzo_UoMs_family === void 0
|
|
92
|
+
? void 0
|
|
93
|
+
: repzo_UoMs_family.data) === null || _f === void 0
|
|
94
|
+
? void 0
|
|
95
|
+
: _f.length;
|
|
96
|
+
await commandLog
|
|
97
|
+
.addDetail(
|
|
98
|
+
`${
|
|
99
|
+
(_g =
|
|
100
|
+
repzo_UoMs_family === null || repzo_UoMs_family === void 0
|
|
101
|
+
? void 0
|
|
102
|
+
: repzo_UoMs_family.data) === null || _g === void 0
|
|
103
|
+
? void 0
|
|
104
|
+
: _g.length
|
|
105
|
+
} Measure Units Family in Repzo`
|
|
106
|
+
)
|
|
107
|
+
.commit();
|
|
108
|
+
const sap_unique_family = {};
|
|
109
|
+
for (
|
|
110
|
+
let i = 0;
|
|
111
|
+
i < (sap_UoMs === null || sap_UoMs === void 0 ? void 0 : sap_UoMs.length);
|
|
112
|
+
i++
|
|
113
|
+
) {
|
|
114
|
+
const sap_UoM = sap_UoMs[i];
|
|
115
|
+
const key = sap_UoM.ITEMCODE;
|
|
116
|
+
if (!sap_unique_family[key]) sap_unique_family[key] = {};
|
|
117
|
+
const uom_key = `${nameSpace}_${sap_UoM.UOMGROUPENTRY}_${sap_UoM.ALTUOMID}`;
|
|
118
|
+
sap_unique_family[key][uom_key] = 1;
|
|
119
|
+
}
|
|
120
|
+
result.sap_total =
|
|
121
|
+
(_h = Object.keys(sap_unique_family)) === null || _h === void 0
|
|
122
|
+
? void 0
|
|
123
|
+
: _h.length;
|
|
124
|
+
await commandLog
|
|
125
|
+
.addDetail(`${result.sap_total} Measure Units Family in SAP`)
|
|
126
|
+
.commit();
|
|
127
|
+
for (let key in sap_unique_family) {
|
|
128
|
+
const sap_family = sap_unique_family[key];
|
|
129
|
+
const repzo_family = repzo_UoMs_family.data.find((r_family) => {
|
|
130
|
+
var _a;
|
|
131
|
+
return (
|
|
132
|
+
((_a = r_family.integration_meta) === null || _a === void 0
|
|
133
|
+
? void 0
|
|
134
|
+
: _a.id) == `${nameSpace}_${key}`
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
let measureunits = [];
|
|
138
|
+
Object.keys(sap_family).forEach((unit) => {
|
|
139
|
+
var _a;
|
|
140
|
+
{
|
|
141
|
+
const UoM =
|
|
142
|
+
(_a =
|
|
143
|
+
repzo_UoMs === null || repzo_UoMs === void 0
|
|
144
|
+
? void 0
|
|
145
|
+
: repzo_UoMs.data) === null || _a === void 0
|
|
146
|
+
? void 0
|
|
147
|
+
: _a.find((repzo_uom) => {
|
|
148
|
+
var _a;
|
|
149
|
+
return (
|
|
150
|
+
((_a =
|
|
151
|
+
repzo_uom === null || repzo_uom === void 0
|
|
152
|
+
? void 0
|
|
153
|
+
: repzo_uom.integration_meta) === null || _a === void 0
|
|
154
|
+
? void 0
|
|
155
|
+
: _a.id) == unit
|
|
156
|
+
);
|
|
157
|
+
});
|
|
158
|
+
if (UoM) {
|
|
159
|
+
measureunits.push(UoM._id.toString());
|
|
160
|
+
}
|
|
45
161
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
162
|
+
});
|
|
163
|
+
const body = {
|
|
164
|
+
name: key,
|
|
165
|
+
disabled: false,
|
|
166
|
+
integration_meta: { id: `${nameSpace}_${key}` },
|
|
167
|
+
measureunits: measureunits || [],
|
|
168
|
+
company_namespace: [nameSpace],
|
|
169
|
+
};
|
|
170
|
+
if (!repzo_family) {
|
|
171
|
+
// Create
|
|
172
|
+
try {
|
|
173
|
+
const created_UoM = await repzo.measureunitFamily.create(body);
|
|
174
|
+
result.created++;
|
|
175
|
+
} catch (e) {
|
|
176
|
+
// console.log(
|
|
177
|
+
// "Create Measure Unit Family Failed >> ",
|
|
178
|
+
// e?.response,
|
|
179
|
+
// body
|
|
180
|
+
// );
|
|
181
|
+
failed_docs_report.push({
|
|
182
|
+
method: "create",
|
|
183
|
+
doc: body,
|
|
184
|
+
error_message: set_error(e),
|
|
185
|
+
});
|
|
186
|
+
result.failed++;
|
|
63
187
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
disabled: false,
|
|
84
|
-
integration_meta: { id: `${nameSpace}_${key}` },
|
|
85
|
-
measureunits: measureunits || [],
|
|
86
|
-
company_namespace: [nameSpace],
|
|
87
|
-
};
|
|
88
|
-
if (!repzo_family) {
|
|
89
|
-
// Create
|
|
90
|
-
try {
|
|
91
|
-
const created_UoM = await repzo.measureunitFamily.create(body);
|
|
92
|
-
result.created++;
|
|
93
|
-
}
|
|
94
|
-
catch (e) {
|
|
95
|
-
// console.log(
|
|
96
|
-
// "Create Measure Unit Family Failed >> ",
|
|
97
|
-
// e?.response,
|
|
98
|
-
// body
|
|
99
|
-
// );
|
|
100
|
-
failed_docs_report.push({
|
|
101
|
-
method: "create",
|
|
102
|
-
doc: body,
|
|
103
|
-
error_message: set_error(e),
|
|
104
|
-
});
|
|
105
|
-
result.failed++;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
if (repzo_family.name == body.name &&
|
|
110
|
-
!((_k = _.xor(((_j = repzo_family === null || repzo_family === void 0 ? void 0 : repzo_family.measureunits) === null || _j === void 0 ? void 0 : _j.map((m) => m === null || m === void 0 ? void 0 : m.toString())) || [], (body === null || body === void 0 ? void 0 : body.measureunits) || [])) === null || _k === void 0 ? void 0 : _k.length)) {
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
// Update
|
|
114
|
-
try {
|
|
115
|
-
const updated_UoM = await repzo.measureunitFamily.update(repzo_family._id, body);
|
|
116
|
-
result.updated++;
|
|
117
|
-
}
|
|
118
|
-
catch (e) {
|
|
119
|
-
// console.log(
|
|
120
|
-
// "Update Measure Unit Family Failed >> ",
|
|
121
|
-
// e?.response?.data,
|
|
122
|
-
// body
|
|
123
|
-
// );
|
|
124
|
-
failed_docs_report.push({
|
|
125
|
-
method: "update",
|
|
126
|
-
doc_id: repzo_family === null || repzo_family === void 0 ? void 0 : repzo_family._id,
|
|
127
|
-
doc: body,
|
|
128
|
-
error_message: set_error(e),
|
|
129
|
-
});
|
|
130
|
-
result.failed++;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
188
|
+
} else {
|
|
189
|
+
if (
|
|
190
|
+
repzo_family.name == body.name &&
|
|
191
|
+
!((_k = _.xor(
|
|
192
|
+
((_j =
|
|
193
|
+
repzo_family === null || repzo_family === void 0
|
|
194
|
+
? void 0
|
|
195
|
+
: repzo_family.measureunits) === null || _j === void 0
|
|
196
|
+
? void 0
|
|
197
|
+
: _j.map((m) =>
|
|
198
|
+
m === null || m === void 0 ? void 0 : m.toString()
|
|
199
|
+
)) || [],
|
|
200
|
+
(body === null || body === void 0 ? void 0 : body.measureunits) ||
|
|
201
|
+
[]
|
|
202
|
+
)) === null || _k === void 0
|
|
203
|
+
? void 0
|
|
204
|
+
: _k.length)
|
|
205
|
+
) {
|
|
206
|
+
continue;
|
|
133
207
|
}
|
|
134
|
-
//
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
208
|
+
// Update
|
|
209
|
+
try {
|
|
210
|
+
const updated_UoM = await repzo.measureunitFamily.update(
|
|
211
|
+
repzo_family._id,
|
|
212
|
+
body
|
|
213
|
+
);
|
|
214
|
+
result.updated++;
|
|
215
|
+
} catch (e) {
|
|
216
|
+
// console.log(
|
|
217
|
+
// "Update Measure Unit Family Failed >> ",
|
|
218
|
+
// e?.response?.data,
|
|
219
|
+
// body
|
|
220
|
+
// );
|
|
221
|
+
failed_docs_report.push({
|
|
222
|
+
method: "update",
|
|
223
|
+
doc_id:
|
|
224
|
+
repzo_family === null || repzo_family === void 0
|
|
225
|
+
? void 0
|
|
226
|
+
: repzo_family._id,
|
|
227
|
+
doc: body,
|
|
228
|
+
error_message: set_error(e),
|
|
229
|
+
});
|
|
230
|
+
result.failed++;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
147
233
|
}
|
|
234
|
+
// console.log(result);
|
|
235
|
+
await update_bench_time(
|
|
236
|
+
repzo,
|
|
237
|
+
commandEvent.app._id,
|
|
238
|
+
bench_time_key,
|
|
239
|
+
new_bench_time
|
|
240
|
+
);
|
|
241
|
+
await commandLog
|
|
242
|
+
.setStatus(
|
|
243
|
+
"success",
|
|
244
|
+
failed_docs_report.length ? failed_docs_report : null
|
|
245
|
+
)
|
|
246
|
+
.setBody(result)
|
|
247
|
+
.commit();
|
|
248
|
+
return result;
|
|
249
|
+
} catch (e) {
|
|
250
|
+
//@ts-ignore
|
|
251
|
+
console.error(
|
|
252
|
+
((_l = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
253
|
+
_l === void 0
|
|
254
|
+
? void 0
|
|
255
|
+
: _l.data) || e
|
|
256
|
+
);
|
|
257
|
+
await commandLog.setStatus("fail", e).commit();
|
|
258
|
+
throw e;
|
|
259
|
+
}
|
|
148
260
|
};
|