-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Virtual DocType #12121
feat: Virtual DocType #12121
Conversation
bac0d1f
to
78be6c7
Compare
78be6c7
to
6612763
Compare
more elegant solution than my doctype variant #7946 I am wondering whether it is possible to also combine the doctype variant feature into this one? the idea is as following
|
You can probably do that with the current implementation of Virtual DocType. Since here you need to define your own DocType controller, you can use any existing DocType as your data source and limit the fields that you want your Virtual DocType to have within the controller itself. |
Virtual Doctype's data souurce can be anything a file or a secondary database table or an api
Co-authored-by: Chinmay D. Pai <chinmay.pai@zerodha.com> Signed-off-by: Chinmay D. Pai <chinmay.pai@zerodha.com>
d35b89b
to
348cdaa
Compare
Create virtual doctype only for non custom doctype Create virtual doctype only if developer mode is set
This PR is ready to be reviewed! @barredterra @surajshetty3416 :) |
Still waiting this to be merged. |
@Thunderbottom you have to enable edit rights for maintainers so that we can push required changes. |
frappe/desk/form/load.py
Outdated
except frappe.DoesNotExistError: | ||
return [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cannot rely on this, frappe.throw
shows an error modal on the client-side which is why UI tests are failing. Why is this required? What was the issue with the previous handling?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
frappe.db.exists makes a db call, in case of virtual DocType we wont have a table so it will always return empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you think is the best way to handle this issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have a exists
method for virtual doctype as well? frappe.db.exists
can internally use that method to check if virtual document exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think its a correct way to handle. Example consider if virtual doctype's backend is an api then we might end up calling same api twice, first call to check if document exists and second call to get the data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we set frappe.local.message_log to false here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
first call to check if document exists and second call to get the data.
I think that's fine... but it will help in other cases where we are just using frappe.db.exists
for different validations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
frappe.db.exists
internally uses frappe.db.get_value
so I have added support for frappe.db.get_value
in virtual doctype,
…nto virtual_doctype
…nto virtual_doctype
LGTM |
@shridarpatil the change might have created some issue for ERPNext patch
Let me know if you are able to figure out and fix it. |
Thanks a lot for this great addition to Frappe. Could you please guide on the following points (and possibly include in documentation):
I think this would be helpful for a lot of other users as well Thank you kindly |
When this feature will be available ? which release will include this feature? I see this feature was merged, but the codes can't be found in any branch |
This comment was marked as abuse.
This comment was marked as abuse.
This comment was marked as abuse.
This comment was marked as abuse.
@casesolved-co-uk in v13.1.0, only DocType support virutal_doc feature, but list view, form will not work ( couting in list view, form detail) |
Summary
Virtual DocType is a feature-extension for DocType which allows developers to create DocTypes with custom data sources and DocType controller. The purpose is to define custom DocTypes in the system without creating a table in the database, while utilizing the frontend, resource APIs, and roles and permissions from the framework.
These Virtual DocTypes function exactly like normal DocTypes in the frontend and are indistinguishable for the end-user, but gives more control to the developer over the DocType's data source. With this, the data source for a Virtual DocType can be anything: an external API, a secondary database, JSON or CSV files, etc. This enables the developers to plug-in database backends other than MariaDB and Postgres, and makes the Frappe Framework even more powerful!
Usage
Creating a Virtual DocType
To create a Virtual DocType, just select the Virtual DocType checkbox while creating the DocType:
Creating a Custom Controller
As an example, the following controller code uses a JSON file as the DocType datasource:
To integrate other datasources with the Virtual DocType, you will need to add controller methods defining the database access.
Outcome
/api/resource
methods defined by the framework are compatible with Virtual DocTypes.Documentation Link: frappe/frappe_docs#71