ERPNext Foundation ERPNext Cloud Chat Blog Discuss Frappé* Donate

Meta? Pass document name, return doctype


#1

Does a method exist that returns a doctype when passed a document name? Something with this sort of flavor?
frappe.meta.get_doctype("PINV-00001")
Which would return “Purchase Invoice” as a string?
I’m not entirely sure where to look if it’s not in model or meta or db or __init__ where it might be.


#2

Nope, there is no such method
But you can check below method

We are using this method for global search, it will return the list of records from multiple doctypes, where the search keyword is present


#3

This makes lots of sense. I don’t think there’s a perfect way to get the doctype from a record’s name anyway, except to make the best guess and then try it. I’ll post the code here when I figure it out.

[edit]: I’ll leave this without a solution until I can post the code.


#4

Good challenge Tyler -

For code learning clues such as you seek, there’s this here to be mined for gems

apps/frappe/frappe/__init__.py

Dozens of handy well documented methods for the picking - just a few that I recognize


#5

So after kicking this around with the team, we decided to also pull doctype along with any time we needed a name. Not that a function like this wouldn’t be useful, it’s just not as good as doing it the right way the first time.

@clarkej __init__.py is only surpassed in its utility and mystery by erpnext/hooks.py.