ERPNext.com Frappe Cloud Documentation Partners Frappe School Public Chat

Virtual doctype testing errors

Hi,

We are testing the new virtual doctypes on v13. Right now, we have this versions installed so it’s supossed to be a working feature:
ERPJarl: v13.17.0 (version-13)
Frappe Framework: v13.17.1 (version-13)

  • We created a virtual doctype called “prod_6” with some fields:

  • At first, we were trying to connect the virtual doctype to an external doctype in SQL server but we were getting some errors. So we decided to test with the more simple example fron the documentation: https://frappeframework.com/docs/v13/user/en/basics/doctypes/virtual-doctype

  • Created a json with this data:
    [
    {“id”:“123”,
    “da”:“snhg”,
    “price”:“111”,
    “control”:“1223”},

          {"id":"456",
          "da":"asdasd",
          "price":"222",
          "control":"1223"}
    

    ]

  • Edited the controller prod_6.py with the test:

But we are getting this error trying to load the doctype:

Here is the stack error with some debugging from reportview.py

As far I can tell, the error seems to be inside row.get in reportview.py but I dunno why.

Any idea why is this happening? Is it really a working feature?

Thanks in advance.

Really interested on this. I’ve tried many times always unsuccesfully. It could be a fantastic feature. Has anyone achieved this?

We are getting the same problem. Not even the example code is working right now.

Does anyone have any input on this?

Indeed, this is a very interesting feature !

From some research, AFAIK, this seem to be an unfinished feature. May be Frappe guys can tell us. :slight_smile:

So far, I follow this guy tutorial https://www.youtube.com/watch?v=rvSbDugUJPk and summarize what I have done as following,

  1. Fixing existing core code,
  • reportview.py, line 46
def execute(doctype, *args, **kwargs):
	is_virtual = frappe.db.exists("DocType", {"name": doctype, "is_virtual": True})
	if is_virtual:
		return [{"total_count": 0}]
	return DatabaseQuery(doctype).execute(*args, **kwargs)
  • load.py, line 31
	if not frappe.db.exists(doctype, name):
		is_virtual = frappe.db.exists("DocType", {"name": doctype, "is_virtual": True})
		if not is_virtual:
			return []
  1. Create a test Virtual Doctype, I only create super simple virtual doctype, “My Virtual Doctype” with 1 field, “Note” as Text
  2. On the my_virtual_doctype.py created by the framework, here is the code.
from frappe.model.document import Document

DATA = [
	{"name": "rec1", "note": "Note for 1st record"},
	{"name": "rec2", "note": "Note for 2nd record"},
	{"name": "rec3", "note": "Note for 3rd record"},
]

class MyVirtualDoctype(Document):

	def load_from_db(self):
		if self.name != self.doctype:
			d = list(filter(lambda l: l["name"] == self.name, DATA))
			super(Document, self).__init__(d[0])

	def get_list(self, args):
		return DATA

Now, I am able to see the list of DATA and click to open it.

image

3 Likes

Yep, those modifications to reportview.py and load.py seems to be working right. Even managed to connect it to another sources that way.

Thanks a lot!