diff --git a/bodyshop_translations.babel b/bodyshop_translations.babel index 516cab7d9..31b297cd9 100644 --- a/bodyshop_translations.babel +++ b/bodyshop_translations.babel @@ -2181,6 +2181,27 @@ + + existinginventoryline + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + exporting false diff --git a/client/src/components/bill-delete-button/bill-delete-button.component.jsx b/client/src/components/bill-delete-button/bill-delete-button.component.jsx index eee5f522b..b6cb19992 100644 --- a/client/src/components/bill-delete-button/bill-delete-button.component.jsx +++ b/client/src/components/bill-delete-button/bill-delete-button.component.jsx @@ -15,7 +15,8 @@ export default function BillDeleteButton({ bill }) { setLoading(true); const result = await deleteBill({ variables: { billId: bill.id }, - update(cache) { + update(cache, { errors }) { + if (errors) return; cache.modify({ fields: { bills(existingBills, { readField }) { @@ -36,11 +37,22 @@ export default function BillDeleteButton({ bill }) { if (!!!result.errors) { notification["success"]({ message: t("bills.successes.deleted") }); } else { - notification["error"]({ - message: t("bills.errors.deleting", { - error: JSON.stringify(result.errors), - }), - }); + //Check if it's an fkey violation. + const error = JSON.stringify(result.errors); + + if (error.toLowerCase().includes("inventory_billid_fkey")) { + notification["error"]({ + message: t("bills.errors.deleting", { + error: t("bills.errors.existinginventoryline"), + }), + }); + } else { + notification["error"]({ + message: t("bills.errors.deleting", { + error: JSON.stringify(result.errors), + }), + }); + } } setLoading(false); diff --git a/client/src/components/bill-form/bill-form.lines.component.jsx b/client/src/components/bill-form/bill-form.lines.component.jsx index 18d996d5a..71a0e3b72 100644 --- a/client/src/components/bill-form/bill-form.lines.component.jsx +++ b/client/src/components/bill-form/bill-form.lines.component.jsx @@ -485,22 +485,33 @@ export function BillEnterModalLinesComponent({ dataIndex: "actions", render: (text, record) => ( - - - - {() => - Simple_Inventory.treatment === "on" && ( + + {() => ( + + + {Simple_Inventory.treatment === "on" && ( - ) - } - - + )} + + )} + ), }, ]; diff --git a/client/src/components/billline-add-inventory/billline-add-inventory.component.jsx b/client/src/components/billline-add-inventory/billline-add-inventory.component.jsx index 2a6d76355..d2cbe92bc 100644 --- a/client/src/components/billline-add-inventory/billline-add-inventory.component.jsx +++ b/client/src/components/billline-add-inventory/billline-add-inventory.component.jsx @@ -64,9 +64,9 @@ export function BilllineAddInventory({ cost_center: billline.cost_center, deductedfromlbr: billline.deductedfromlbr, applicable_taxes: { - local: false, //billline.applicable_taxes.local, - state: false, //billline.applicable_taxes.state, - federal: false, // billline.applicable_taxes.federal, + local: billline.applicable_taxes.local, + state: billline.applicable_taxes.state, + federal: billline.applicable_taxes.federal, }, }, ], @@ -76,7 +76,9 @@ export function BilllineAddInventory({ const insertResult = await insertInventoryLine({ variables: { - joblineId: billline.joblineid, + joblineId: + billline.joblineid === "noline" ? billline.id : billline.joblineid, //This will return null as there will be no jobline that has the id of the bill line. + //Unfortunately, we can't send null as the GQL syntax validation fails. joblineStatus: bodyshop.md_order_statuses.default_returned, inv: { shopid: bodyshop.id, @@ -99,8 +101,9 @@ export function BilllineAddInventory({ act_price: billline.actual_price, cost: billline.actual_cost, quantity: billline.quantity, - job_line_id: billline.joblineid, - part_type: billline.jobline.part_type, + job_line_id: + billline.joblineid === "noline" ? null : billline.joblineid, + part_type: billline.jobline && billline.jobline.part_type, cm_received: true, }, ], diff --git a/client/src/redux/media/media.actions.js b/client/src/redux/media/media.actions.js index 1ff5e943c..3d0827123 100644 --- a/client/src/redux/media/media.actions.js +++ b/client/src/redux/media/media.actions.js @@ -6,7 +6,6 @@ export const getJobMedia = (jobid) => ({ }); export const getBillMedia = ({ jobid, invoice_number }) => { - console.log("in the action"); return { type: MediaActionTypes.GET_MEDIA_FOR_BILL, payload: { jobid, invoice_number }, diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index f283e1777..c55a48010 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -147,6 +147,7 @@ "errors": { "creating": "Error adding bill. {{error}}", "deleting": "Error deleting bill. {{error}}", + "existinginventoryline": "This bill cannot be deleted as it is tied to items in inventory.", "exporting": "Error exporting payable(s). {{error}}", "exporting-partner": "Unable to connect to ImEX Partner. Please ensure it is running and logged in.", "invalidro": "Not a valid RO.", diff --git a/client/src/translations/es/common.json b/client/src/translations/es/common.json index b40b5175d..ca89fc4d9 100644 --- a/client/src/translations/es/common.json +++ b/client/src/translations/es/common.json @@ -147,6 +147,7 @@ "errors": { "creating": "", "deleting": "", + "existinginventoryline": "", "exporting": "", "exporting-partner": "", "invalidro": "", diff --git a/client/src/translations/fr/common.json b/client/src/translations/fr/common.json index 6843f664f..bd63176f0 100644 --- a/client/src/translations/fr/common.json +++ b/client/src/translations/fr/common.json @@ -147,6 +147,7 @@ "errors": { "creating": "", "deleting": "", + "existinginventoryline": "", "exporting": "", "exporting-partner": "", "invalidro": "",