repzo-sap-absjo 1.0.3 → 1.0.5
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 +15 -0
- package/lib/actions/create_invoice.js +61 -28
- package/lib/actions/create_proforma.js +63 -30
- package/lib/actions/create_return_invoice.js +61 -28
- package/lib/actions/create_transfer.js +47 -33
- package/lib/commands/client.js +7 -9
- package/lib/commands/client_disabled.js +22 -28
- package/lib/commands/join.js +7 -0
- package/lib/commands/rep.js +37 -41
- package/lib/types.d.ts +3 -3
- package/package.json +2 -2
- package/src/actions/create_invoice.ts +42 -16
- package/src/actions/create_payment.ts +1 -1
- package/src/actions/create_proforma.ts +41 -16
- package/src/actions/create_return_invoice.ts +42 -16
- package/src/actions/create_transfer.ts +13 -7
- package/src/commands/client.ts +8 -10
- package/src/commands/client_disabled.ts +16 -15
- package/src/commands/join.ts +5 -0
- package/src/commands/rep.ts +11 -11
- package/src/types.ts +3 -3
package/changelog.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Release Notes
|
|
2
2
|
|
|
3
|
+
## [unreleased]()
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
- [commands/rep] delete hard code of rep.warehouse for reps start with: [WS, RET, MT] @maramalshen
|
|
10
|
+
- [commands/client] decide if client is cash or credit depend on PAYMENTTERM instead of CLIENTGROUP @maramalshen
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
### Removed
|
|
15
|
+
|
|
3
16
|
## [v1.0.0 (2022-04-18)](https://github.com/Repzo/repzo-sap-absjo.git)
|
|
4
17
|
|
|
5
18
|
### Added
|
|
@@ -10,6 +23,8 @@
|
|
|
10
23
|
- fix bug in sync_client @maramalshen
|
|
11
24
|
- add detail with the action.sync_id
|
|
12
25
|
- if create transfer was failed then send command: Adjust Inventory (optionals)
|
|
26
|
+
- [join] if repzo.joinActionsWebHook.status = failure then commandLog.setStatus should be fail @maramalshen
|
|
27
|
+
- update get data from repzo by using PatchAction @maramalshen
|
|
13
28
|
|
|
14
29
|
### Changed
|
|
15
30
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import Repzo from "repzo";
|
|
2
|
-
import { _create
|
|
2
|
+
import { _create } from "../util.js";
|
|
3
3
|
import { v4 as uuid } from "uuid";
|
|
4
4
|
import moment from "moment-timezone";
|
|
5
5
|
export const create_invoice = async (event, options) => {
|
|
6
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
6
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
7
7
|
const repzo = new Repzo(
|
|
8
8
|
(_a = options.data) === null || _a === void 0 ? void 0 : _a.repzoApiKey,
|
|
9
9
|
{ env: options.env }
|
|
@@ -147,20 +147,44 @@ export const create_invoice = async (event, options) => {
|
|
|
147
147
|
] = true;
|
|
148
148
|
}
|
|
149
149
|
});
|
|
150
|
-
const repzo_taxes = await
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
150
|
+
const repzo_taxes = await repzo.patchAction.create(
|
|
151
|
+
{
|
|
152
|
+
slug: "tax",
|
|
153
|
+
readQuery: [
|
|
154
|
+
{
|
|
155
|
+
key: "_id",
|
|
156
|
+
value: Object.keys(repzo_tax_ids),
|
|
157
|
+
operator: "in",
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
},
|
|
161
|
+
{ per_page: 50000 }
|
|
154
162
|
);
|
|
155
|
-
const repzo_measureunits = await
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
163
|
+
const repzo_measureunits = await repzo.patchAction.create(
|
|
164
|
+
{
|
|
165
|
+
slug: "measureunits",
|
|
166
|
+
readQuery: [
|
|
167
|
+
{
|
|
168
|
+
key: "_id",
|
|
169
|
+
value: Object.keys(repzo_measureunit_ids),
|
|
170
|
+
operator: "in",
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
},
|
|
174
|
+
{ per_page: 50000 }
|
|
159
175
|
);
|
|
160
|
-
const repzo_products = await
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
176
|
+
const repzo_products = await repzo.patchAction.create(
|
|
177
|
+
{
|
|
178
|
+
slug: "product",
|
|
179
|
+
readQuery: [
|
|
180
|
+
{
|
|
181
|
+
key: "_id",
|
|
182
|
+
value: Object.keys(repzo_product_ids),
|
|
183
|
+
operator: "in",
|
|
184
|
+
},
|
|
185
|
+
],
|
|
186
|
+
},
|
|
187
|
+
{ per_page: 50000 }
|
|
164
188
|
);
|
|
165
189
|
// Prepare SAP_invoice_items
|
|
166
190
|
const items = [];
|
|
@@ -178,9 +202,12 @@ export const create_invoice = async (event, options) => {
|
|
|
178
202
|
const item = repzo_invoice.items[i];
|
|
179
203
|
// Get Repzo Tax
|
|
180
204
|
const repzo_tax =
|
|
181
|
-
|
|
205
|
+
(_h =
|
|
206
|
+
repzo_taxes === null || repzo_taxes === void 0
|
|
207
|
+
? void 0
|
|
208
|
+
: repzo_taxes.data) === null || _h === void 0
|
|
182
209
|
? void 0
|
|
183
|
-
:
|
|
210
|
+
: _h.find((t) => {
|
|
184
211
|
var _a, _b, _c;
|
|
185
212
|
return (
|
|
186
213
|
((_a = t._id) === null || _a === void 0
|
|
@@ -197,9 +224,12 @@ export const create_invoice = async (event, options) => {
|
|
|
197
224
|
if (!repzo_tax) throw `Tax with _id: ${item.tax._id} not found in Repzo`;
|
|
198
225
|
// Get Repzo UoM
|
|
199
226
|
const repzo_measureunit =
|
|
200
|
-
|
|
227
|
+
(_j =
|
|
228
|
+
repzo_measureunits === null || repzo_measureunits === void 0
|
|
229
|
+
? void 0
|
|
230
|
+
: repzo_measureunits.data) === null || _j === void 0
|
|
201
231
|
? void 0
|
|
202
|
-
:
|
|
232
|
+
: _j.find((m) => {
|
|
203
233
|
var _a, _b, _c;
|
|
204
234
|
return (
|
|
205
235
|
((_a = m._id) === null || _a === void 0
|
|
@@ -215,13 +245,16 @@ export const create_invoice = async (event, options) => {
|
|
|
215
245
|
});
|
|
216
246
|
if (!repzo_measureunit)
|
|
217
247
|
throw `Uom with _id: ${
|
|
218
|
-
(
|
|
248
|
+
(_k = item.measureunit) === null || _k === void 0 ? void 0 : _k._id
|
|
219
249
|
} not found in Repzo`;
|
|
220
250
|
// Get Repzo Product
|
|
221
251
|
const repzo_product =
|
|
222
|
-
|
|
252
|
+
(_l =
|
|
253
|
+
repzo_products === null || repzo_products === void 0
|
|
254
|
+
? void 0
|
|
255
|
+
: repzo_products.data) === null || _l === void 0
|
|
223
256
|
? void 0
|
|
224
|
-
:
|
|
257
|
+
: _l.find((p) => {
|
|
225
258
|
var _a, _b, _c;
|
|
226
259
|
return (
|
|
227
260
|
((_a = p._id) === null || _a === void 0
|
|
@@ -247,19 +280,19 @@ export const create_invoice = async (event, options) => {
|
|
|
247
280
|
LineTotal: item.total_before_tax / 1000,
|
|
248
281
|
UomCode: repzo_measureunit.integration_meta.ALTUOMID,
|
|
249
282
|
Brand:
|
|
250
|
-
(
|
|
283
|
+
(_m = repzo_product.integration_meta) === null || _m === void 0
|
|
251
284
|
? void 0
|
|
252
|
-
:
|
|
285
|
+
: _m.BRAND,
|
|
253
286
|
Department:
|
|
254
|
-
((
|
|
287
|
+
((_o =
|
|
255
288
|
repzo_rep === null || repzo_rep === void 0
|
|
256
289
|
? void 0
|
|
257
|
-
: repzo_rep.integration_meta) === null ||
|
|
290
|
+
: repzo_rep.integration_meta) === null || _o === void 0
|
|
258
291
|
? void 0
|
|
259
|
-
:
|
|
260
|
-
((
|
|
292
|
+
: _o.DEPARTMENTCODE) ||
|
|
293
|
+
((_p = options.data) === null || _p === void 0
|
|
261
294
|
? void 0
|
|
262
|
-
:
|
|
295
|
+
: _p.DepartmentCode), // "D2",
|
|
263
296
|
});
|
|
264
297
|
}
|
|
265
298
|
const sap_invoice = {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import Repzo from "repzo";
|
|
2
|
-
import { _create
|
|
2
|
+
import { _create } from "../util.js";
|
|
3
3
|
import { v4 as uuid } from "uuid";
|
|
4
4
|
import moment from "moment-timezone";
|
|
5
5
|
export const create_proforma = async (event, options) => {
|
|
6
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
6
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
7
7
|
const repzo = new Repzo(
|
|
8
8
|
(_a = options.data) === null || _a === void 0 ? void 0 : _a.repzoApiKey,
|
|
9
9
|
{ env: options.env }
|
|
@@ -87,20 +87,44 @@ export const create_proforma = async (event, options) => {
|
|
|
87
87
|
] = true;
|
|
88
88
|
}
|
|
89
89
|
});
|
|
90
|
-
const repzo_taxes = await
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
const repzo_taxes = await repzo.patchAction.create(
|
|
91
|
+
{
|
|
92
|
+
slug: "tax",
|
|
93
|
+
readQuery: [
|
|
94
|
+
{
|
|
95
|
+
key: "_id",
|
|
96
|
+
value: Object.keys(repzo_tax_ids),
|
|
97
|
+
operator: "in",
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
},
|
|
101
|
+
{ per_page: 50000 }
|
|
94
102
|
);
|
|
95
|
-
const repzo_measureunits = await
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
103
|
+
const repzo_measureunits = await repzo.patchAction.create(
|
|
104
|
+
{
|
|
105
|
+
slug: "measureunits",
|
|
106
|
+
readQuery: [
|
|
107
|
+
{
|
|
108
|
+
key: "_id",
|
|
109
|
+
value: Object.keys(repzo_measureunit_ids),
|
|
110
|
+
operator: "in",
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
},
|
|
114
|
+
{ per_page: 50000 }
|
|
99
115
|
);
|
|
100
|
-
const repzo_products = await
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
116
|
+
const repzo_products = await repzo.patchAction.create(
|
|
117
|
+
{
|
|
118
|
+
slug: "product",
|
|
119
|
+
readQuery: [
|
|
120
|
+
{
|
|
121
|
+
key: "_id",
|
|
122
|
+
value: Object.keys(repzo_product_ids),
|
|
123
|
+
operator: "in",
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
{ per_page: 50000 }
|
|
104
128
|
);
|
|
105
129
|
// Prepare SAP_invoice_items
|
|
106
130
|
const items = [];
|
|
@@ -118,9 +142,12 @@ export const create_proforma = async (event, options) => {
|
|
|
118
142
|
const item = repzo_proforma.items[i];
|
|
119
143
|
// Get Repzo Tax
|
|
120
144
|
const repzo_tax =
|
|
121
|
-
|
|
145
|
+
(_h =
|
|
146
|
+
repzo_taxes === null || repzo_taxes === void 0
|
|
147
|
+
? void 0
|
|
148
|
+
: repzo_taxes.data) === null || _h === void 0
|
|
122
149
|
? void 0
|
|
123
|
-
:
|
|
150
|
+
: _h.find((t) => {
|
|
124
151
|
var _a, _b, _c;
|
|
125
152
|
return (
|
|
126
153
|
((_a = t._id) === null || _a === void 0
|
|
@@ -137,9 +164,12 @@ export const create_proforma = async (event, options) => {
|
|
|
137
164
|
if (!repzo_tax) throw `Tax with _id: ${item.tax._id} not found in Repzo`;
|
|
138
165
|
// Get Repzo UoM
|
|
139
166
|
const repzo_measureunit =
|
|
140
|
-
|
|
167
|
+
(_j =
|
|
168
|
+
repzo_measureunits === null || repzo_measureunits === void 0
|
|
169
|
+
? void 0
|
|
170
|
+
: repzo_measureunits.data) === null || _j === void 0
|
|
141
171
|
? void 0
|
|
142
|
-
:
|
|
172
|
+
: _j.find((m) => {
|
|
143
173
|
var _a, _b, _c;
|
|
144
174
|
return (
|
|
145
175
|
((_a = m._id) === null || _a === void 0
|
|
@@ -155,13 +185,16 @@ export const create_proforma = async (event, options) => {
|
|
|
155
185
|
});
|
|
156
186
|
if (!repzo_measureunit)
|
|
157
187
|
throw `Uom with _id: ${
|
|
158
|
-
(
|
|
188
|
+
(_k = item.measureunit) === null || _k === void 0 ? void 0 : _k._id
|
|
159
189
|
} not found in Repzo`;
|
|
160
190
|
// Get Repzo Product
|
|
161
191
|
const repzo_product =
|
|
162
|
-
|
|
192
|
+
(_l =
|
|
193
|
+
repzo_products === null || repzo_products === void 0
|
|
194
|
+
? void 0
|
|
195
|
+
: repzo_products.data) === null || _l === void 0
|
|
163
196
|
? void 0
|
|
164
|
-
:
|
|
197
|
+
: _l.find((p) => {
|
|
165
198
|
var _a, _b, _c;
|
|
166
199
|
return (
|
|
167
200
|
((_a = p._id) === null || _a === void 0
|
|
@@ -187,28 +220,28 @@ export const create_proforma = async (event, options) => {
|
|
|
187
220
|
LineTotal: item.total_before_tax / 1000,
|
|
188
221
|
UomCode: repzo_measureunit.integration_meta.ALTUOMID,
|
|
189
222
|
Brand:
|
|
190
|
-
(
|
|
223
|
+
(_m = repzo_product.integration_meta) === null || _m === void 0
|
|
191
224
|
? void 0
|
|
192
|
-
:
|
|
225
|
+
: _m.BRAND,
|
|
193
226
|
Department:
|
|
194
|
-
((
|
|
227
|
+
((_o =
|
|
195
228
|
repzo_rep === null || repzo_rep === void 0
|
|
196
229
|
? void 0
|
|
197
|
-
: repzo_rep.integration_meta) === null ||
|
|
230
|
+
: repzo_rep.integration_meta) === null || _o === void 0
|
|
198
231
|
? void 0
|
|
199
|
-
:
|
|
200
|
-
((
|
|
232
|
+
: _o.DEPARTMENTCODE) ||
|
|
233
|
+
((_p = options.data) === null || _p === void 0
|
|
201
234
|
? void 0
|
|
202
|
-
:
|
|
235
|
+
: _p.DepartmentCode), // "D2"
|
|
203
236
|
});
|
|
204
237
|
}
|
|
205
238
|
const sap_invoice = {
|
|
206
239
|
RefNum: repzo_proforma.serial_number.formatted,
|
|
207
240
|
SalPersCode: repzo_rep
|
|
208
241
|
? repzo_rep.integration_id
|
|
209
|
-
: (
|
|
242
|
+
: (_q = options.data) === null || _q === void 0
|
|
210
243
|
? void 0
|
|
211
|
-
:
|
|
244
|
+
: _q.SalPersCode,
|
|
212
245
|
DocDate: moment(repzo_proforma.issue_date, "YYYY-MM-DD").format(
|
|
213
246
|
"YYYYMMDD"
|
|
214
247
|
),
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import Repzo from "repzo";
|
|
2
|
-
import { _create
|
|
2
|
+
import { _create } from "../util.js";
|
|
3
3
|
import { v4 as uuid } from "uuid";
|
|
4
4
|
import moment from "moment-timezone";
|
|
5
5
|
export const create_return_invoice = async (event, options) => {
|
|
6
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
6
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
7
7
|
const repzo = new Repzo(
|
|
8
8
|
(_a = options.data) === null || _a === void 0 ? void 0 : _a.repzoApiKey,
|
|
9
9
|
{ env: options.env }
|
|
@@ -102,20 +102,44 @@ export const create_return_invoice = async (event, options) => {
|
|
|
102
102
|
] = true;
|
|
103
103
|
}
|
|
104
104
|
});
|
|
105
|
-
const repzo_taxes = await
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
const repzo_taxes = await repzo.patchAction.create(
|
|
106
|
+
{
|
|
107
|
+
slug: "tax",
|
|
108
|
+
readQuery: [
|
|
109
|
+
{
|
|
110
|
+
key: "_id",
|
|
111
|
+
value: Object.keys(repzo_tax_ids),
|
|
112
|
+
operator: "in",
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
{ per_page: 50000 }
|
|
109
117
|
);
|
|
110
|
-
const repzo_measureunits = await
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
118
|
+
const repzo_measureunits = await repzo.patchAction.create(
|
|
119
|
+
{
|
|
120
|
+
slug: "measureunits",
|
|
121
|
+
readQuery: [
|
|
122
|
+
{
|
|
123
|
+
key: "_id",
|
|
124
|
+
value: Object.keys(repzo_measureunit_ids),
|
|
125
|
+
operator: "in",
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
},
|
|
129
|
+
{ per_page: 50000 }
|
|
114
130
|
);
|
|
115
|
-
const repzo_products = await
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
131
|
+
const repzo_products = await repzo.patchAction.create(
|
|
132
|
+
{
|
|
133
|
+
slug: "product",
|
|
134
|
+
readQuery: [
|
|
135
|
+
{
|
|
136
|
+
key: "_id",
|
|
137
|
+
value: Object.keys(repzo_product_ids),
|
|
138
|
+
operator: "in",
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
},
|
|
142
|
+
{ per_page: 50000 }
|
|
119
143
|
);
|
|
120
144
|
// Prepare SAP_invoice_items
|
|
121
145
|
const return_items = [];
|
|
@@ -133,9 +157,12 @@ export const create_return_invoice = async (event, options) => {
|
|
|
133
157
|
const item = repzo_invoice.return_items[i];
|
|
134
158
|
// Get Repzo Tax
|
|
135
159
|
const repzo_tax =
|
|
136
|
-
|
|
160
|
+
(_j =
|
|
161
|
+
repzo_taxes === null || repzo_taxes === void 0
|
|
162
|
+
? void 0
|
|
163
|
+
: repzo_taxes.data) === null || _j === void 0
|
|
137
164
|
? void 0
|
|
138
|
-
:
|
|
165
|
+
: _j.find((t) => {
|
|
139
166
|
var _a, _b, _c;
|
|
140
167
|
return (
|
|
141
168
|
((_a = t._id) === null || _a === void 0
|
|
@@ -152,9 +179,12 @@ export const create_return_invoice = async (event, options) => {
|
|
|
152
179
|
if (!repzo_tax) throw `Tax with _id: ${item.tax._id} not found in Repzo`;
|
|
153
180
|
// Get Repzo UoM
|
|
154
181
|
const repzo_measureunit =
|
|
155
|
-
|
|
182
|
+
(_k =
|
|
183
|
+
repzo_measureunits === null || repzo_measureunits === void 0
|
|
184
|
+
? void 0
|
|
185
|
+
: repzo_measureunits.data) === null || _k === void 0
|
|
156
186
|
? void 0
|
|
157
|
-
:
|
|
187
|
+
: _k.find((m) => {
|
|
158
188
|
var _a, _b, _c;
|
|
159
189
|
return (
|
|
160
190
|
((_a = m._id) === null || _a === void 0
|
|
@@ -170,13 +200,16 @@ export const create_return_invoice = async (event, options) => {
|
|
|
170
200
|
});
|
|
171
201
|
if (!repzo_measureunit)
|
|
172
202
|
throw `Uom with _id: ${
|
|
173
|
-
(
|
|
203
|
+
(_l = item.measureunit) === null || _l === void 0 ? void 0 : _l._id
|
|
174
204
|
} not found in Repzo`;
|
|
175
205
|
// Get Repzo Product
|
|
176
206
|
const repzo_product =
|
|
177
|
-
|
|
207
|
+
(_m =
|
|
208
|
+
repzo_products === null || repzo_products === void 0
|
|
209
|
+
? void 0
|
|
210
|
+
: repzo_products.data) === null || _m === void 0
|
|
178
211
|
? void 0
|
|
179
|
-
:
|
|
212
|
+
: _m.find((p) => {
|
|
180
213
|
var _a, _b, _c;
|
|
181
214
|
return (
|
|
182
215
|
((_a = p._id) === null || _a === void 0
|
|
@@ -207,19 +240,19 @@ export const create_return_invoice = async (event, options) => {
|
|
|
207
240
|
LineTotal: (-1 * item.total_before_tax) / 1000,
|
|
208
241
|
UomCode: repzo_measureunit.integration_meta.ALTUOMID,
|
|
209
242
|
Brand:
|
|
210
|
-
(
|
|
243
|
+
(_o = repzo_product.integration_meta) === null || _o === void 0
|
|
211
244
|
? void 0
|
|
212
|
-
:
|
|
245
|
+
: _o.BRAND,
|
|
213
246
|
Department:
|
|
214
|
-
((
|
|
247
|
+
((_p =
|
|
215
248
|
repzo_rep === null || repzo_rep === void 0
|
|
216
249
|
? void 0
|
|
217
|
-
: repzo_rep.integration_meta) === null ||
|
|
250
|
+
: repzo_rep.integration_meta) === null || _p === void 0
|
|
218
251
|
? void 0
|
|
219
|
-
:
|
|
220
|
-
((
|
|
252
|
+
: _p.DEPARTMENTCODE) ||
|
|
253
|
+
((_q = options.data) === null || _q === void 0
|
|
221
254
|
? void 0
|
|
222
|
-
:
|
|
255
|
+
: _q.DepartmentCode),
|
|
223
256
|
Return_Reason:
|
|
224
257
|
item_return_reason === null || item_return_reason === void 0
|
|
225
258
|
? void 0
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import Repzo from "repzo";
|
|
2
|
-
import { _create,
|
|
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
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
5
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
6
6
|
const repzo = new Repzo(
|
|
7
7
|
(_a = options.data) === null || _a === void 0 ? void 0 : _a.repzoApiKey,
|
|
8
8
|
{ env: options.env }
|
|
@@ -64,11 +64,18 @@ export const create_transfer = async (event, options) => {
|
|
|
64
64
|
repzo_product_ids[item.product_id.toString()] = true;
|
|
65
65
|
}
|
|
66
66
|
});
|
|
67
|
-
const repzo_products = await
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
const repzo_products = await repzo.patchAction.create(
|
|
68
|
+
{
|
|
69
|
+
slug: "product",
|
|
70
|
+
readQuery: [
|
|
71
|
+
{
|
|
72
|
+
key: "_id",
|
|
73
|
+
value: Object.keys(repzo_product_ids),
|
|
74
|
+
operator: "in",
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
{ per_page: 50000, populatedKeys: ["measureunit"] }
|
|
72
79
|
);
|
|
73
80
|
// Prepare Transfer Items
|
|
74
81
|
const variants = [];
|
|
@@ -81,18 +88,25 @@ export const create_transfer = async (event, options) => {
|
|
|
81
88
|
i++
|
|
82
89
|
) {
|
|
83
90
|
const repzo_transfer_item = repzo_transfer.variants[i];
|
|
84
|
-
const repzo_product =
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
91
|
+
const repzo_product =
|
|
92
|
+
(_h =
|
|
93
|
+
repzo_products === null || repzo_products === void 0
|
|
94
|
+
? void 0
|
|
95
|
+
: repzo_products.data) === null || _h === void 0
|
|
96
|
+
? void 0
|
|
97
|
+
: _h.find(
|
|
98
|
+
//@ts-ignore
|
|
99
|
+
(p) => {
|
|
100
|
+
var _a;
|
|
101
|
+
return (
|
|
102
|
+
p._id.toString() ==
|
|
103
|
+
((_a = repzo_transfer_item.product_id) === null ||
|
|
104
|
+
_a === void 0
|
|
105
|
+
? void 0
|
|
106
|
+
: _a.toString())
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
);
|
|
96
110
|
if (!repzo_product) {
|
|
97
111
|
// console.log(
|
|
98
112
|
// `Product with _id: ${repzo_transfer_item.product_id} was not found In Repzo`,
|
|
@@ -112,9 +126,9 @@ export const create_transfer = async (event, options) => {
|
|
|
112
126
|
// );
|
|
113
127
|
throw new Error(
|
|
114
128
|
`Measureunit with _id: ${
|
|
115
|
-
(
|
|
129
|
+
(_j = repzo_product.sv_measureUnit) === null || _j === void 0
|
|
116
130
|
? void 0
|
|
117
|
-
:
|
|
131
|
+
: _j.toString()
|
|
118
132
|
} was not found`
|
|
119
133
|
);
|
|
120
134
|
}
|
|
@@ -124,21 +138,21 @@ export const create_transfer = async (event, options) => {
|
|
|
124
138
|
Quantity: repzo_transfer_item.qty / Number(repzo_measure_unit.factor),
|
|
125
139
|
//@ts-ignore
|
|
126
140
|
FromWarehouse:
|
|
127
|
-
(
|
|
141
|
+
(_k = repzo_transfer.from) === null || _k === void 0
|
|
128
142
|
? void 0
|
|
129
|
-
:
|
|
143
|
+
: _k.code,
|
|
130
144
|
//@ts-ignore
|
|
131
145
|
ToWarehouse:
|
|
132
|
-
(
|
|
146
|
+
(_l = repzo_transfer.to) === null || _l === void 0 ? void 0 : _l.code,
|
|
133
147
|
});
|
|
134
148
|
}
|
|
135
149
|
const sap_transfer = {
|
|
136
150
|
StockTransferID: body.serial_number.formatted,
|
|
137
151
|
SalesPersonCode: repzo_rep
|
|
138
152
|
? repzo_rep.integration_id
|
|
139
|
-
: (
|
|
153
|
+
: (_m = options.data) === null || _m === void 0
|
|
140
154
|
? void 0
|
|
141
|
-
:
|
|
155
|
+
: _m.SalesPersonCode,
|
|
142
156
|
FromWarehouse: body.from.code,
|
|
143
157
|
ToWarehouse: body.to.code,
|
|
144
158
|
RepzoStockTransferLines: variants,
|
|
@@ -168,23 +182,23 @@ export const create_transfer = async (event, options) => {
|
|
|
168
182
|
console.error((e === null || e === void 0 ? void 0 : e.response) || e);
|
|
169
183
|
await actionLog.setStatus("fail", e).setBody(body).commit();
|
|
170
184
|
if (
|
|
171
|
-
(
|
|
172
|
-
(
|
|
185
|
+
(_p =
|
|
186
|
+
(_o =
|
|
173
187
|
options === null || options === void 0 ? void 0 : options.data) ===
|
|
174
|
-
null ||
|
|
188
|
+
null || _o === void 0
|
|
175
189
|
? void 0
|
|
176
|
-
:
|
|
190
|
+
: _o.transfers) === null || _p === void 0
|
|
177
191
|
? void 0
|
|
178
|
-
:
|
|
192
|
+
: _p.adjustInventoryInFailedTransfer
|
|
179
193
|
) {
|
|
180
194
|
send_command_to_marketplace({
|
|
181
195
|
command: "adjust_inventory",
|
|
182
196
|
app_id: options.app_id,
|
|
183
197
|
env: options.env,
|
|
184
198
|
repzoApiKey:
|
|
185
|
-
(
|
|
199
|
+
(_q = options.data) === null || _q === void 0
|
|
186
200
|
? void 0
|
|
187
|
-
:
|
|
201
|
+
: _q.repzoApiKey,
|
|
188
202
|
});
|
|
189
203
|
}
|
|
190
204
|
throw e;
|
package/lib/commands/client.js
CHANGED
|
@@ -219,21 +219,19 @@ export const sync_client = async (commandEvent) => {
|
|
|
219
219
|
comment: sap_client.CLIENTNOTE,
|
|
220
220
|
formatted_address: sap_client.CLIENTADDRESSID,
|
|
221
221
|
tags: tag ? [tag._id] : [],
|
|
222
|
-
credit_limit:
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
: credit_limit && Math.round(credit_limit * 1000),
|
|
222
|
+
credit_limit: sap_client.PAYMENTTERM // sap_client.CLIENTGROUP == "Cash Van"
|
|
223
|
+
? credit_limit && Math.round(credit_limit * 1000)
|
|
224
|
+
: 1000000000,
|
|
226
225
|
financials: {
|
|
227
|
-
credit_limit:
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
: credit_limit && Math.round(credit_limit * 1000),
|
|
226
|
+
credit_limit: sap_client.PAYMENTTERM // sap_client.CLIENTGROUP == "Cash Van"
|
|
227
|
+
? credit_limit && Math.round(credit_limit * 1000)
|
|
228
|
+
: 1000000000,
|
|
231
229
|
},
|
|
232
230
|
channel: channel ? channel._id : undefined,
|
|
233
231
|
paymentTerm: paymentTerm ? paymentTerm._id : undefined,
|
|
234
232
|
sv_priceList: priceList ? priceList._id : undefined,
|
|
235
233
|
disabled: sap_client.ACTIVE == "Y" ? false : true,
|
|
236
|
-
payment_type: sap_client.
|
|
234
|
+
payment_type: sap_client.PAYMENTTERM ? "credit" : "cash",
|
|
237
235
|
integrated_client_balance:
|
|
238
236
|
client_credit_consumed && Math.round(client_credit_consumed * 1000),
|
|
239
237
|
};
|