repzo-sap-absjo 1.0.19 → 1.0.20
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 +13 -19
- package/lib/actions/create_invoice.js +207 -377
- package/lib/actions/create_payment.d.ts +1 -4
- package/lib/actions/create_payment.js +107 -195
- package/lib/actions/create_proforma.d.ts +1 -4
- package/lib/actions/create_proforma.js +146 -285
- package/lib/actions/create_return_invoice.d.ts +1 -4
- package/lib/actions/create_return_invoice.js +158 -312
- package/lib/actions/create_transfer.d.ts +1 -4
- package/lib/actions/create_transfer.js +126 -223
- 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 +48 -67
- package/lib/commands/brand.d.ts +1 -3
- package/lib/commands/brand.js +100 -174
- 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 +62 -62
- 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 +326 -612
- package/lib/commands/product.d.ts +30 -32
- package/lib/commands/product.js +263 -485
- package/lib/commands/product_disabled.d.ts +1 -3
- package/lib/commands/product_disabled.js +94 -160
- 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/brand.js +90 -90
- 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 +334 -337
- 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 +53 -77
- package/lib/util.d.ts +19 -70
- package/lib/util.js +144 -170
- package/package.json +1 -1
- package/src/actions/create_invoice.ts +5 -25
|
@@ -1,260 +1,148 @@
|
|
|
1
1
|
import Repzo from "repzo";
|
|
2
2
|
import _ from "lodash";
|
|
3
|
-
import { update_bench_time, set_error } from "../util.js";
|
|
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
|
-
|
|
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,
|
|
6
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
7
|
+
const repzo = new Repzo((_a = commandEvent.app.formData) === null || _a === void 0 ? void 0 : _a.repzoApiKey, {
|
|
8
|
+
env: commandEvent.env,
|
|
88
9
|
});
|
|
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
|
-
? void 0
|
|
123
|
-
|
|
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
|
-
}
|
|
161
|
-
}
|
|
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++;
|
|
10
|
+
const commandLog = new Repzo.CommandLog(repzo, commandEvent.app, commandEvent.command);
|
|
11
|
+
try {
|
|
12
|
+
// console.log("sync_measureunit_family");
|
|
13
|
+
const new_bench_time = new Date().toISOString();
|
|
14
|
+
const bench_time_key = "bench_time_measureunit_family";
|
|
15
|
+
await commandLog.load(commandEvent.sync_id);
|
|
16
|
+
await commandLog
|
|
17
|
+
.addDetail("Repzo SAP: Started Syncing Measure Units Family")
|
|
18
|
+
.commit();
|
|
19
|
+
const nameSpace = commandEvent.nameSpace.join("_");
|
|
20
|
+
const result = {
|
|
21
|
+
sap_total: 0,
|
|
22
|
+
repzo_total: 0,
|
|
23
|
+
sap_UoM_total: 0,
|
|
24
|
+
repzo_UoM_total: 0,
|
|
25
|
+
created: 0,
|
|
26
|
+
updated: 0,
|
|
27
|
+
failed: 0,
|
|
28
|
+
};
|
|
29
|
+
const failed_docs_report = [];
|
|
30
|
+
const sap_UoMs = await get_sap_UoMs(commandEvent.app.formData.sapHostUrl, {});
|
|
31
|
+
result.sap_UoM_total = sap_UoMs === null || sap_UoMs === void 0 ? void 0 : sap_UoMs.length;
|
|
32
|
+
await commandLog
|
|
33
|
+
.addDetail(`${result.sap_UoM_total} Unit of Measures in SAP`)
|
|
34
|
+
.commit();
|
|
35
|
+
let repzo_UoMs = await repzo.measureunit.find({
|
|
36
|
+
disabled: false,
|
|
37
|
+
per_page: 50000,
|
|
38
|
+
});
|
|
39
|
+
result.repzo_UoM_total = (_b = repzo_UoMs === null || repzo_UoMs === void 0 ? void 0 : repzo_UoMs.data) === null || _b === void 0 ? void 0 : _b.length;
|
|
40
|
+
await commandLog
|
|
41
|
+
.addDetail(`${(_c = repzo_UoMs === null || repzo_UoMs === void 0 ? void 0 : repzo_UoMs.data) === null || _c === void 0 ? void 0 : _c.length} Measure Units in Repzo`)
|
|
42
|
+
.commit();
|
|
43
|
+
if (!((_d = repzo_UoMs === null || repzo_UoMs === void 0 ? void 0 : repzo_UoMs.data) === null || _d === void 0 ? void 0 : _d.length)) {
|
|
44
|
+
throw "measure units are not found or the nameSpace has more than one";
|
|
187
45
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
) {
|
|
206
|
-
continue;
|
|
46
|
+
repzo_UoMs.data = (_e = repzo_UoMs.data) === null || _e === void 0 ? void 0 : _e.filter((UoM) => UoM.integration_meta);
|
|
47
|
+
const repzo_UoMs_family = await repzo.measureunitFamily.find({
|
|
48
|
+
disabled: false,
|
|
49
|
+
per_page: 50000,
|
|
50
|
+
});
|
|
51
|
+
result.repzo_total = (_f = repzo_UoMs_family === null || repzo_UoMs_family === void 0 ? void 0 : repzo_UoMs_family.data) === null || _f === void 0 ? void 0 : _f.length;
|
|
52
|
+
await commandLog
|
|
53
|
+
.addDetail(`${(_g = repzo_UoMs_family === null || repzo_UoMs_family === void 0 ? void 0 : repzo_UoMs_family.data) === null || _g === void 0 ? void 0 : _g.length} Measure Units Family in Repzo`)
|
|
54
|
+
.commit();
|
|
55
|
+
const sap_unique_family = {};
|
|
56
|
+
for (let i = 0; i < (sap_UoMs === null || sap_UoMs === void 0 ? void 0 : sap_UoMs.length); i++) {
|
|
57
|
+
const sap_UoM = sap_UoMs[i];
|
|
58
|
+
const key = sap_UoM.ITEMCODE;
|
|
59
|
+
if (!sap_unique_family[key])
|
|
60
|
+
sap_unique_family[key] = {};
|
|
61
|
+
const uom_key = `${nameSpace}_${sap_UoM.UOMGROUPENTRY}_${sap_UoM.ALTUOMID}`;
|
|
62
|
+
sap_unique_family[key][uom_key] = 1;
|
|
207
63
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
:
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
64
|
+
result.sap_total = (_h = Object.keys(sap_unique_family)) === null || _h === void 0 ? void 0 : _h.length;
|
|
65
|
+
await commandLog
|
|
66
|
+
.addDetail(`${result.sap_total} Measure Units Family in SAP`)
|
|
67
|
+
.commit();
|
|
68
|
+
for (let key in sap_unique_family) {
|
|
69
|
+
const sap_family = sap_unique_family[key];
|
|
70
|
+
const repzo_family = repzo_UoMs_family.data.find((r_family) => { var _a; return ((_a = r_family.integration_meta) === null || _a === void 0 ? void 0 : _a.id) == `${nameSpace}_${key}`; });
|
|
71
|
+
let measureunits = [];
|
|
72
|
+
Object.keys(sap_family).forEach((unit) => {
|
|
73
|
+
var _a;
|
|
74
|
+
{
|
|
75
|
+
const UoM = (_a = repzo_UoMs === null || repzo_UoMs === void 0 ? void 0 : repzo_UoMs.data) === null || _a === void 0 ? void 0 : _a.find((repzo_uom) => { var _a; return ((_a = repzo_uom === null || repzo_uom === void 0 ? void 0 : repzo_uom.integration_meta) === null || _a === void 0 ? void 0 : _a.id) == unit; });
|
|
76
|
+
if (UoM) {
|
|
77
|
+
measureunits.push(UoM._id.toString());
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
const body = {
|
|
82
|
+
name: key,
|
|
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
|
+
}
|
|
231
133
|
}
|
|
232
|
-
|
|
134
|
+
// console.log(result);
|
|
135
|
+
await update_bench_time(repzo, commandEvent.app._id, bench_time_key, new_bench_time);
|
|
136
|
+
await commandLog
|
|
137
|
+
.setStatus("success", failed_docs_report.length ? failed_docs_report : null)
|
|
138
|
+
.setBody(result)
|
|
139
|
+
.commit();
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
catch (e) {
|
|
143
|
+
//@ts-ignore
|
|
144
|
+
console.error(((_l = e === null || e === void 0 ? void 0 : e.response) === null || _l === void 0 ? void 0 : _l.data) || e);
|
|
145
|
+
await commandLog.setStatus("fail", e).commit();
|
|
146
|
+
throw e;
|
|
233
147
|
}
|
|
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
|
-
}
|
|
260
148
|
};
|