IO-1914 Inventory bugfixes.

This commit is contained in:
Patrick Fic
2022-06-07 11:41:27 -07:00
parent 9bf3974ba0
commit fe5e2a247a
8 changed files with 74 additions and 25 deletions

View File

@@ -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);

View File

@@ -485,22 +485,33 @@ export function BillEnterModalLinesComponent({
dataIndex: "actions",
render: (text, record) => (
<Space wrap>
<Button disabled={disabled} onClick={() => remove(record.name)}>
<DeleteFilled />
</Button>
<Form.Item shouldUpdate noStyle>
{() =>
Simple_Inventory.treatment === "on" && (
<Form.Item shouldUpdate noStyle>
{() => (
<Space wrap>
<Button
disabled={
disabled ||
getFieldValue("billlines")[record.fieldKey]?.inventories
?.length > 0
}
onClick={() => remove(record.name)}
>
<DeleteFilled />
</Button>
{Simple_Inventory.treatment === "on" && (
<BilllineAddInventory
disabled={!billEdit || form.isFieldsTouched()}
disabled={
!billEdit ||
form.isFieldsTouched() ||
form.getFieldValue("is_credit_memo")
}
billline={getFieldValue("billlines")[record.fieldKey]}
jobid={getFieldValue("jobid")}
/>
)
}
</Form.Item>
</Space>
)}
</Space>
)}
</Form.Item>
),
},
];

View File

@@ -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,
},
],