Try ERPNext Buy Support Partners Foundation

Training Event doesn't allow duplicates even without any unique field

As the title says, I don’t have any unique field but the event_name field is treated as primary/unique internally in the DB apparently.

I get this stacktrace if I try to import such entries:

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py", line 325, in db_insert
    ), list(d.values()))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 156, in sql
    self._cursor.execute(query, values)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/cursors.py", line 170, in execute
    result = self._query(query)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/cursors.py", line 328, in _query
    conn.query(q)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py", line 517, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py", line 732, in _read_query_result
    result.read()
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py", line 1075, in read
    first_packet = self.connection._read_packet()
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py", line 684, in _read_packet
    packet.check_error()
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/protocol.py", line 220, in check_error
    err.raise_mysql_exception(self._data)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/err.py", line 109, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.IntegrityError: (1062, "Duplicate entry 'Interne Schulung' for key 'PRIMARY'")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/data_import/importer.py", line 126, in import_data
    doc = self.process_doc(doc)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/data_import/importer.py", line 194, in process_doc
    return self.insert_record(doc)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/data_import/importer.py", line 213, in insert_record
    new_doc.insert()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 248, in insert
    raise e
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 245, in insert
    self.db_insert()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py", line 335, in db_insert
    raise frappe.DuplicateEntryError(self.doctype, self.name, e)
frappe.exceptions.DuplicateEntryError: ('Training Event', 'Interne Schulung', IntegrityError(1062, "Duplicate entry 'Interne Schulung' for key 'PRIMARY'"))

What I want is to have non-unique names for Training Events. If a unique field is required: Can I automate this ? Like it’s done for Employees internally? I don’t want to force people adopting their own unique naming scheme when creating reoccurring events. Note also that according to https://github.com/frappe/erpnext/issues/8950 this shouldn’t happen ?

For anyone else with that problem:
Set event_name to hidden and add a default value.
Then add a custom script (client side JS) that takes the values of (for example) start_time + your event type and puts that as the value of event_name. In my case this is unique enough to work. When importing data you still have to create a CSV with unique event_name entries, as the custom script is client side and won’t run during import.

What does not work is trying to add a series to the document, as the event_name field is still required and can’t be “pre” populated from the naming series.

(You may be able to use a name series and populate the event_name field from that using some server side scripts, but I didn’t want to dig any further.)