Skip to content

Commit

Permalink
feat: validate serial number count in row
Browse files Browse the repository at this point in the history
  • Loading branch information
akshayitzme committed Sep 25, 2023
1 parent 11df282 commit 90902b3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/components/POS/SelectedItemRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,7 @@
/>
</div>

<div
v-if="row.links?.item && row.links?.item.hasSerialNumber"
class="px-2 pt-8 col-span-2"
>
<div v-if="hasSerialNumber" class="px-2 pt-8 col-span-2">
<Text
:df="{
label: t`Serial Number`,
Expand All @@ -245,6 +242,7 @@
:value="row.serialNumber"
:show-label="true"
:border="true"
:required="hasSerialNumber"
@change="(value:string)=> setSerialNumber(value)"
/>
</div>
Expand All @@ -264,6 +262,8 @@ import { defineComponent } from 'vue';
import { SalesInvoiceItem } from 'models/baseModels/SalesInvoiceItem/SalesInvoiceItem';
import { Money } from 'pesa';
import { DiscountType } from './types';
import { t } from 'fyo';
import { validateSerialNumberCount } from 'src/utils/pos';
export default defineComponent({
name: 'SelectedItemRow',
Expand Down Expand Up @@ -293,6 +293,9 @@ export default defineComponent({
isUOMConversionEnabled(): boolean {
return !!fyo.singles.InventorySettings?.enableUomConversions;
},
hasSerialNumber(): boolean {
return !!(this.row.links?.item && this.row.links?.item.hasSerialNumber);
},
},
methods: {
async getAvailableQtyInBatch(): Promise<number> {
Expand All @@ -318,8 +321,13 @@ export default defineComponent({
if (!serialNumber) {
return;
}
this.itemSerialNumbers[this.row.item as string] = serialNumber;
validateSerialNumberCount(
serialNumber,
this.row.quantity ?? 0,
this.row.item!
);
},
setItemDiscount(type: DiscountType, value: Money | number) {
if (type === 'percent') {
Expand Down
23 changes: 23 additions & 0 deletions src/utils/pos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,26 @@ export async function transferPOSCashAndWriteOff(

await (await jvDoc.sync()).submit();
}

export function validateSerialNumberCount(
serialNumbers: string | undefined,
quantity: number,
item: string
) {
let serialNumberCount = 0;

if (serialNumbers) {
serialNumberCount = serialNumbers.split('\n').length;
}

if (quantity !== serialNumberCount) {
const errorMessage = t`Need ${quantity} Serial Numbers for Item ${item}. You have provided ${serialNumberCount}`;

showToast({
type: 'error',
message: errorMessage,
duration: 'long',
});
throw new ValidationError(errorMessage);
}
}

0 comments on commit 90902b3

Please sign in to comment.