feat(coupon-details): prevent duplicate course/batch selections and clear name on type change

This commit is contained in:
Joedeep Singh
2025-10-13 14:54:03 +00:00
parent 99c448e0e5
commit 0f24fd6edc

View File

@@ -65,10 +65,12 @@
{ label: 'Course ', value: 'LMS Course' },
{ label: 'Batch ', value: 'LMS Batch' },
]"
@change="(val) => (row.reference_name = null)"
/>
<Link
class="min-w-40"
:doctype="row.reference_doctype || 'LMS Course'"
:filters="getFilters(idx)"
:label="__('Name')"
:value="row.reference_name"
@change="(opt) => (row.reference_name = opt)"
@@ -158,6 +160,22 @@ function removeRow(idx) {
doc.value.applicable_items.splice(idx, 1)
}
function getFilters(idx) {
// don't show the batch or course that has already been selected
const row = doc.value.applicable_items[idx]
if (!row.reference_doctype) return {}
const doctype = row.reference_doctype
const selectedNames = doc.value.applicable_items
.filter(
(r, i) => i !== idx && r.reference_doctype === doctype && r.reference_name
)
.map((r) => r.reference_name)
if (selectedNames.length === 0) return {}
return {
name: ['not in', selectedNames],
}
}
const saveDoc = createResource({
url: 'frappe.client.save',
makeParams(values) {