2
0
mirror of https://github.com/frappe/books.git synced 2025-01-03 15:17:30 +00:00

chore: refactor sinv validations

This commit is contained in:
akshayitzme 2023-11-07 15:51:53 +05:30
parent 8d1e0ca8c8
commit df6c472ca4

View File

@ -89,15 +89,19 @@ export async function getItem(item: string): Promise<Item | undefined> {
return itemDoc; return itemDoc;
} }
export function validateSinv( export function validateSinv(sinvDoc: SalesInvoice, itemQtyMap: ItemQtyMap) {
items: SalesInvoiceItem[], if (!sinvDoc) {
itemQtyMap: ItemQtyMap
) {
if (!items) {
return; return;
} }
for (const item of items) { validateSinvItems(sinvDoc.items as SalesInvoiceItem[], itemQtyMap);
}
function validateSinvItems(
sinvItems: SalesInvoiceItem[],
itemQtyMap: ItemQtyMap
) {
for (const item of sinvItems) {
if (!item.quantity || item.quantity < 1) { if (!item.quantity || item.quantity < 1) {
throw new ValidationError( throw new ValidationError(
t`Invalid Quantity for Item ${item.item as string}` t`Invalid Quantity for Item ${item.item as string}`