From 827ecfd809a13cfaba78ae4895c3bf37d3651745 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Mon, 3 Feb 2020 23:25:02 +0530 Subject: [PATCH] fix: Dont allow adding same item in another row --- .../doctype/PurchaseInvoiceItem/PurchaseInvoiceItem.js | 10 +++++++++- models/doctype/SalesInvoiceItem/SalesInvoiceItem.js | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/models/doctype/PurchaseInvoiceItem/PurchaseInvoiceItem.js b/models/doctype/PurchaseInvoiceItem/PurchaseInvoiceItem.js index b1901752..6915b6b3 100644 --- a/models/doctype/PurchaseInvoiceItem/PurchaseInvoiceItem.js +++ b/models/doctype/PurchaseInvoiceItem/PurchaseInvoiceItem.js @@ -10,7 +10,15 @@ module.exports = { label: 'Item', fieldtype: 'Link', target: 'Item', - required: 1 + required: 1, + getFilters(_, doc) { + let items = doc.parentdoc.items.map(d => d.item).filter(Boolean); + if (items.length > 0) { + return { + name: ['not in', items] + }; + } + } }, { fieldname: 'description', diff --git a/models/doctype/SalesInvoiceItem/SalesInvoiceItem.js b/models/doctype/SalesInvoiceItem/SalesInvoiceItem.js index bfc86e5b..77f4a7aa 100644 --- a/models/doctype/SalesInvoiceItem/SalesInvoiceItem.js +++ b/models/doctype/SalesInvoiceItem/SalesInvoiceItem.js @@ -10,7 +10,15 @@ module.exports = { label: 'Item', fieldtype: 'Link', target: 'Item', - required: 1 + required: 1, + getFilters(_, doc) { + let items = doc.parentdoc.items.map(d => d.item).filter(Boolean); + if (items.length > 0) { + return { + name: ['not in', items] + }; + } + } }, { fieldname: 'description',