@openinc/parse-server-opendash 4.10.1 → 4.11.0
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.
|
@@ -14,17 +14,32 @@ async function init() {
|
|
|
14
14
|
const { object, original, user } = request;
|
|
15
15
|
if (object.get("status") === "disrupted")
|
|
16
16
|
return;
|
|
17
|
-
await addToWorkOrder(object);
|
|
17
|
+
await addToWorkOrder(object, original);
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
* Adds amountGood and amountScrap
|
|
21
|
+
* Adds what a save changed in amountGood and amountScrap of the work time to
|
|
22
|
+
* the related work order.
|
|
23
|
+
*
|
|
24
|
+
* Only the change, not the whole amount: a work time is saved more than once.
|
|
25
|
+
* An interim report of the BDE plugin ("Melden und weiterarbeiten") raises its
|
|
26
|
+
* amounts while it keeps running, and an ERP sync or an edit saves it again.
|
|
27
|
+
* Adding the full amount on every save counted the same parts several times.
|
|
28
|
+
* A save that changes no amount leaves the work order alone.
|
|
22
29
|
*/
|
|
23
|
-
async function addToWorkOrder(workTime) {
|
|
30
|
+
async function addToWorkOrder(workTime, original) {
|
|
31
|
+
const good = (workTime.amountGood || 0) - (original?.amountGood || 0);
|
|
32
|
+
const scrap = (workTime.amountScrap || 0) - (original?.amountScrap || 0);
|
|
33
|
+
if (good === 0 && scrap === 0)
|
|
34
|
+
return;
|
|
24
35
|
const workOrder = await workTime.workOrder?.fetch({ useMasterKey: true });
|
|
25
36
|
if (!workOrder)
|
|
26
37
|
return;
|
|
27
|
-
workOrder.set("amountGood", (workOrder.amountGood || 0
|
|
28
|
-
workOrder.set("amountScrap", (workOrder.amountScrap || 0
|
|
38
|
+
workOrder.set("amountGood", addAmounts(workOrder.amountGood || 0, good));
|
|
39
|
+
workOrder.set("amountScrap", addAmounts(workOrder.amountScrap || 0, scrap));
|
|
29
40
|
await workOrder.save(null, { useMasterKey: true });
|
|
30
41
|
}
|
|
42
|
+
/** Sums of decimal amounts without binary noise (0.1 + 0.2 is 0.3 here). */
|
|
43
|
+
function addAmounts(a, b) {
|
|
44
|
+
return Math.round((a + b) * 1e6) / 1e6;
|
|
45
|
+
}
|
package/package.json
CHANGED