Skip to content

Commit

Permalink
feat: add validation to prevent adding items to submitted invoices
Browse files Browse the repository at this point in the history
  • Loading branch information
AbleKSaju committed Dec 26, 2024
1 parent 2daf2b7 commit 00e9c35
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion schemas/app/inventory/Point of Sale/POSSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"section": "Default"
},
{
"fieldname": " ",
"fieldname": "submitInvoice",
"label": "Post Payment",
"fieldtype": "Check",
"default": false,
Expand Down
27 changes: 17 additions & 10 deletions src/pages/POS/POS.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ import {
ItemQtyMap,
ItemSerialNumbers,
} from 'src/components/POS/types';
import { ValidationError } from 'fyo/utils/errors';
const COMPONENT_NAME = 'POS';
Expand Down Expand Up @@ -477,19 +478,25 @@ export default defineComponent({
},
async addItem(item: POSItem | Item | undefined) {
await this.sinvDoc.runFormulas();
try {
if (this.sinvDoc.isSubmitted) {
throw new ValidationError(
t`Cannot add an item to a submitted invoice.`
);
}
if (!item) {
return;
}
await this.sinvDoc.runFormulas();
const existingItems =
this.sinvDoc.items?.filter(
(invoiceItem) =>
invoiceItem.item === item.name && !invoiceItem.isFreeItem
) ?? [];
if (!item) {
return;
}
const existingItems =
this.sinvDoc.items?.filter(
(invoiceItem) =>
invoiceItem.item === item.name && !invoiceItem.isFreeItem
) ?? [];
try {
if (item.hasBatch) {
for (const invItem of existingItems) {
const itemQty = invItem.quantity ?? 0;
Expand Down
4 changes: 2 additions & 2 deletions src/pages/POS/SavedInvoiceModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
<Button
:background="false"
class="w-full h-full p-2 mt-2"
:class="{ 'dark:bg-gray-890': savedInvoiceList }"
:class="{ 'dark:bg-gray-890 underline': savedInvoiceList }"
@click="savedInvoiceList = true"
>Saved</Button
>

<Button
:background="false"
class="w-full h-full p-2 mt-2"
:class="{ 'dark:bg-gray-890': !savedInvoiceList }"
:class="{ 'dark:bg-gray-890 underline': !savedInvoiceList }"
@click="savedInvoiceList = false"
>Submitted</Button
>
Expand Down

0 comments on commit 00e9c35

Please sign in to comment.