@openinc/parse-server-opendash 4.10.0 → 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.
@@ -5,10 +5,14 @@ const index_js_1 = require("../features/schema/index.js");
5
5
  async function init() {
6
6
  // Rules for computed inspection characteristics of the BDE plugin. Read by
7
7
  // every user of the tenant (the inspection mask evaluates them), written by
8
- // the creator and tenant admins only: a rule decides the actual value that
9
- // is reported to the ERP.
8
+ // the creator and tenant admins: a rule decides the actual value that is
9
+ // reported to the ERP.
10
+ //
11
+ // That is only the minimum. Who else may edit a rule — the quality
12
+ // department, say — is granted in the BDE admin's permission dialog, so a
13
+ // custom ACL is kept on later saves instead of being reset.
10
14
  (0, index_js_1.beforeSaveHook)("OD3_BDE_QAFormula", async (request) => {
11
15
  await (0, index_js_1.defaultHandler)(request);
12
- await (0, index_js_1.defaultAclHandler)(request);
16
+ await (0, index_js_1.defaultAclHandler)(request, { allowCustomACL: true });
13
17
  });
14
18
  }
@@ -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 from the workTime to the related workOrder.
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) + (workTime.amountGood || 0));
28
- workOrder.set("amountScrap", (workOrder.amountScrap || 0) + (workTime.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openinc/parse-server-opendash",
3
- "version": "4.10.0",
3
+ "version": "4.11.0",
4
4
  "description": "Parse Server Cloud Code for open.INC Stack.",
5
5
  "packageManager": "pnpm@12.8.1",
6
6
  "keywords": [
@@ -67,6 +67,10 @@
67
67
  "type": "Pointer",
68
68
  "targetClass": "{{PREFIX}}BDE_WorkOrder",
69
69
  "required": false
70
+ },
71
+ "reportedAt": {
72
+ "type": "Date",
73
+ "required": false
70
74
  }
71
75
  },
72
76
  "classLevelPermissions": {