This commit is contained in:
2021-06-04 00:27:07 +00:00
parent ea0e1736ea
commit 76c20bd3ca
4 changed files with 68 additions and 38 deletions

View File

@@ -125,6 +125,26 @@ export default {
}
}
},
///////////////////////////////
// DEEP COPY FOR API UPDATE
// Deep copy an object skipping all *Viz and named properties from object
//
deepCopySkip: function(source, skipNames) {
if (skipNames == null) {
skipNames = [];
}
let o = {};
for (let key in source) {
if (
!key.endsWith("Viz") &&
!skipNames.some(x => x == key) &&
source.hasOwnProperty(key)
) {
o[key] = source[key];
}
}
return o;
},
/**
* Copy a string to clipboard
* @param {String} string The string to be copied to clipboard

View File

@@ -110,6 +110,20 @@
].quantity`)
"
></gz-decimal>
<template
v-if="
value.items[activeWoItemIndex].parts[activeItemIndex]
.requestAmountViz != null
"
>
<v-btn text @click="doRequest()">
<v-icon left>
$ayiParachuteBox
</v-icon>
{{ requestMore }}
</v-btn>
</template>
</v-col>
<v-col
@@ -466,6 +480,15 @@ export default {
//---
},
computed: {
requestMore: function() {
return this.$ay
.t("WorkOrderItemPartRequestMore")
.replace(
"{n}",
this.value.items[this.activeWoItemIndex].parts[this.activeItemIndex]
.requestAmountViz
);
},
isDeleted: function() {
if (
this.value.items[this.activeWoItemIndex].parts[this.activeItemIndex] ==

View File

@@ -1123,50 +1123,26 @@ async function saveParts(vm, woItemIndex) {
for (let i = 0; i < vm.obj.items[woItemIndex].parts.length; i++) {
if (vm.obj.items[woItemIndex].parts[i].isDirty) {
let o = JSON.parse(JSON.stringify(vm.obj.items[woItemIndex].parts[i]));
// const o = vm.obj.items[woItemIndex].parts[i];
const uid = o.uid;
//strip out viz fields before sending
o.isDirty = undefined;
o.uid = undefined;
o.partViz = undefined;
o.upcViz = undefined;
o.partWarehouseViz = undefined;
o.taxPartSaleViz = undefined;
o.cost = undefined;
o.listPrice = undefined;
o.unitOfMeasureViz = undefined;
o.priceViz = undefined;
o.netViz = undefined;
o.taxAViz = undefined;
o.taxBViz = undefined;
o.partVizlineTotalViz = undefined;
o.lineTotalViz = undefined;
//clone and skip viz and other fields
let o = window.$gz.util.deepCopySkip(vm.obj.items[woItemIndex].parts[i], [
"uid",
"cost",
"listPrice"
]);
const res = await window.$gz.api.upsert(`${API_BASE_URL}items/parts`, o);
if (res.error) {
//insufficient stock?
console.log("part save error:", JSON.parse(JSON.stringify(res.error)));
if (res.error.details) {
const balanceError = res.error.details.find(z => z.error == "2040");
if (balanceError && balanceError.message) {
console.log("Insufficient stock ", {
balance: Number(balanceError.message.split(":")[1]),
obj: vm.obj.items[woItemIndex].parts[i]
});
//set the amount requestable so it surfaces in the UI and can be requested
let balance = window.$gz.util.stringToFloat(balanceError.message);
if (balance != null || balance != 0) {
vm.obj.items[woItemIndex].parts[i].requestAmountViz =
vm.obj.items[woItemIndex].parts[i].quantity - balance;
}
}
// {
// "code": "2200",
// "details": [
// {
// "message": "available:93.00000",
// "target": "Balance",
// "error": "2040"
// }
// ],
// "message": "ErrorAPI2200"
// }
}
handleSaveError(vm, {
@@ -1174,7 +1150,7 @@ async function saveParts(vm, woItemIndex) {
error: res.error,
itemUid: vm.obj.items[woItemIndex].uid,
childKey: "parts",
childUid: uid
childUid: vm.obj.items[woItemIndex].parts[i].uid
});
} else {
//Server will update fields on put or post for most workorder graph objecs so need to update entire object here
@@ -2094,6 +2070,7 @@ async function fetchTranslatedText(vm) {
"WorkOrderItemPartRequestPartID",
"WorkOrderItemPartRequestPartWarehouseID",
"WorkOrderItemPartRequestQuantity",
"WorkOrderItemPartRequestMore",
"PurchaseOrder",
"PurchaseOrderExpectedReceiveDate",
"PurchaseOrderOrderedDate",