Creating Virtual Doctypes

Hello !!

I want to create a virtual doctype.

I need some help from you guys.

Please help me.

Thanks in advance.

Hi @Kiranmai:

Check this resources:

Hope this helps.

Thank you @avc.

But i dont know about `class VirtualDoctype(Document):
“”"This is a virtual doctype controller for demo purposes.

- It uses a single JSON file on disk as "backend".
- Key is docname and value is the document itself.

        "doc1": {"name": "doc1", ...}
        "doc2": {"name": "doc2", ...}

DATA_FILE = "data_file.json"

def get_current_data() -> dict[str, dict]:
    """Read data from disk"""
    if not os.path.exists(VirtualDoctype.DATA_FILE):
        return {}

    with open(VirtualDoctype.DATA_FILE) as f:
        return json.load(f)

def update_data(data: dict[str, dict]) -> None:
    """Flush updated data to disk"""
    with open(VirtualDoctype.DATA_FILE, "w+") as data_file:
        json.dump(data, data_file)

def db_insert(self, *args, **kwargs):
    d = self.get_valid_dict(convert_dates_to_str=True)

    data = self.get_current_data()
    data[] = d


def load_from_db(self):
    data = self.get_current_data()
    d = data.get(
    super(Document, self).__init__(d)

def db_update(self, *args, **kwargs):
    # For this example insert and update are same operation,
    # it might be  different for you.
    self.db_insert(*args, **kwargs)

def delete(self):
    data = self.get_current_data()
    data.pop(, None)

def get_list(args):
    data = VirtualDoctype.get_current_data()
    return [frappe._dict(doc) for name, doc in data.items()]

def get_count(args):
    data = VirtualDoctype.get_current_data()
    return len(data)

def get_stats(args):
    return {}


so i need help

I created a Virtual Doctype and i created a document in it, but nothing is shown in that doctype.

Please help me

I did this.
Thank you

1 Like