bsgs
January 12, 2022, 3:10pm
1
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: Virtual DocTypes
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
https://pastebin.com/8GefE5EL
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.
avc
January 13, 2022, 8:46am
2
Really interested on this. I’ve tried many times always unsuccesfully. It could be a fantastic feature. Has anyone achieved this?
alack
January 14, 2022, 7:33am
3
We are getting the same problem. Not even the example code is working right now.
Does anyone have any input on this?
kittiu
January 17, 2022, 3:34pm
4
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.
So far, I follow this guy tutorial https://www.youtube.com/watch?v=rvSbDugUJPk and summarize what I have done as following,
Fixing existing core code,
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)
if not frappe.db.exists(doctype, name):
is_virtual = frappe.db.exists("DocType", {"name": doctype, "is_virtual": True})
if not is_virtual:
return []
Create a test Virtual Doctype, I only create super simple virtual doctype, “My Virtual Doctype” with 1 field, “Note” as Text
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.
3 Likes
bsgs
January 21, 2022, 7:31am
5
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!
wale
January 25, 2022, 6:43pm
6
Any chance of doing a PR so this can be fixed in the core ?