fix: remove empty dn from bulk creation if date filter renders them empty

This commit is contained in:
David Arnold 2024-01-30 12:59:26 +01:00
parent 12a4f2761c
commit 9a705169fd
No known key found for this signature in database
GPG Key ID: AB15A6AF1101390D
2 changed files with 11 additions and 3 deletions

View File

@ -1010,6 +1010,11 @@ def make_delivery_note(source_name, target_doc=None, kwargs=None):
for idx, item in enumerate(target_doc.items):
item.idx = idx + 1
if not kwargs.skip_item_mapping and frappe.flags.bulk_transaction and not target_doc.items:
# the (date) condition filter resulted in an unintendedly created empty DN; remove it
del target_doc
return
# Should be called after mapping items.
set_missing_values(so, target_doc)

View File

@ -156,9 +156,12 @@ def task(doc_name, from_doctype, to_doctype):
else:
obj = mapper[from_doctype][to_doctype](doc_name)
obj.flags.ignore_validate = True
obj.set_title_field()
obj.insert(ignore_mandatory=True)
if obj:
obj.flags.ignore_validate = True
obj.set_title_field()
obj.insert(ignore_mandatory=True)
del obj
del frappe.flags.bulk_transaction