pibiDAV is a Frappe App to integrate webDAV with a NextCloud Server, used as (DMS), for a copy of Frappe Files uploaded and tagged to NextCloud while uploading files to Frappe.
MIT# pibiDAV
Requires a Frappe server instance (refer to https://github.com/frappe/frappe). It also uses a tweaked code of pyocclient but this is embedded already in pibiDAV.
PibiDAV branch version-15 is dedicated for Frappe/ERPNext version-15 only.
From the frappe-bench folder, execute
$ bench get-app pibidav --branch version-15 https://github.com/pibico/pibidav.git
$ bench install-app pibidav
If you are using a multi-tenant environment, use the following command
$ bench --site site_name install-app pibidav
Once is installed, be aware that you will need to set developer_mode = 1 on your site_config.json file. Also it is a must to have SSL active in both servers Frappe and NextCloud with specific certificates (wildcard .domain.com certificates are not valid for this integration). Letsencrypt Certificates are valid for both servers. This integration app is prepared for including specific and custom doctypes to upload its attachments to NextCloud at the same time than to Frappe. There is a new frappe.ui.component dialog based on vue.js and called frappe.ui.pibiDocs where to draw the NextCloud Tree and select the destination NextCloud Directory to upload the files.
PibiCo works on NextCloud making the Main Company Folders Superestructure as a shared folder from this NextCloud SuperUser that should be a System Manager on Frappe also. Let's explain with some pictures. This Folder Superstructure has children at different levels and are shared with different groups or users also at different level, thus giving access to these folders and below (both user internal to Company or External such as Customers or Suppliers). At this point, let's go to Frappe Server and once logged-in as System Manager or Administrator we'll go to module pibiDAV on side menu, and on Settings Card we'll choose NextCloud Settings. Once there, we'll activate the NextCloud Enable checkbox (valid also for backup) and fill the credentials of the NextCloud SuperUser in the input fields. We can check that our credentials are correct clicking on NC commands button on upper right side of the screen. Now, automatic uploading of frappe backup is enabled and will be uploaded to the destination folder as given in the backups details section. Frappe Backups files are renamed on NextCloud to files beginning by a number that is the weekday of the backup files, as shown in the picture. So, we will have always the last backup and also all the ancient backups for this weekday as versions in NextCloud, as shown in the picture It's time now of telling to Frappe which doctypes will be integrated to upload its attachments to NextCloud once they are uploaded in Frappe. This is done on the same NextCloud Settings, but on Settings Section, choosing the Frappe Doctype in the table and also giving the DocFields in that DocType that will be used to Tag Automatically the Files on Frappe and On NextCloud as well. We will choose the Sales Invoice Doctype as an example for this configuration. In this case, we will tag the files with the name, the customer and the tax_id from the customer, but whichever field in the doctype, even custom fields are valid.
To get the permissions from NextCloud into Frappe we will fill the User NextCloud Credentials on Frappe User Settings. We'll go through the user settings and will select the Role NextCloud User first. After that we will go at the bottom of de User Settings Form to provide the NextCloud User Credentials. In this example is the System Manager or Administrator having the SuperUser NextCloud Credentials for having access to the full NextCloud Folder SuperStructure.
Provided we have access to the frappe-bench folder, we must hook the Doctypes included in the integration, by adding the following code to hooks.py of pibidav app:
# doctype_calendar_js = {"doctype" : "public/js/doctype_calendar.js"}
nc_list = ["Customer","Project","Sales Invoice","Purchase Invoice","Supplier","Event"]
doctype_js = {}
for item in nc_list:
doctype_js[item] = "public/js/dist/nc_pibidav.js"
# Home Pages
# ----------
In nc_list variable, we will include whichever doctype to integrate with NextCloud.
This new DocType is an extension of existing DocTypes to fill with data given by Attchments, Folders, etc. related to NextCloud and based on its referenced doctype. It is somehow a parallel sheet with data only related to NextCloud Functionalities. It is filled automatically from the different actions derived from NC buttons.
It's time now to try the integration of the NextCloud Folder Structure from Frappe to choose the NC Destination Folder of our uploaded files (except website urls). Let's go to a doctype of the NC Integration List, i.e. a Sales Invoice. On this core doctype, we'll have two new buttons, for enabling NC and for getting the browser dialog to choose the NC destination folder. First of all, we must enable the NC Integration, clicking on Enable NC button. With this action we will generate the pbc_sales_invoice doctype parallel to our sales invoice (same name with 'pbc_' before it). We can check the created Addon clicking on the Check Addon Button. And return to the sales invoice clicking on the ref_docname on the addon. After having saved the original Sales Invoice as draft we can select the NextCloud Destination Folder for our attachments by clicking on the NC Commands Button and selecting Select NC Folder to bring the pop-up dialog for browsing and selecting our NC Folder. When we select the NextCloud Destination Folder in the dialog, this folder path will be filled in our addon text nc_folder field to remember the destination till it is changed by a new selection. While we keep this destination folder, all the attachments uploaded to the Sales Invoice will be also uploaded to NextCloud to this folder. Let's create the pdf from the Sales Invoice, signed electronically outside Frappe and uploaded again as attachment in Frappe/ERPNext We have uploaded the attachment to Frappe/ERPNext as shown in the picture Let's Check if it has been also uploaded to NextCloud on the PBC > Customer > Client > Invoices > 2022 as selected. Looking for details we see the pdf file Sales Invoice uploaded in NextCloud Destination, but also it has been created a shared public Link, tagged with customer, tax_id, doctype and name as we defined in the Settings. VoilĂ , first integration achieved. Let's check the File uploaded to Frappe, it has all metadata from NextCloud as well, and also has some frappe tags also automatically filled on the upload.
Another possible integration is through a Folder Set Doctype Tree integrated in pibiDav. Folder Set is a Doctype for making Folder Structures taken as templates for recreating them in the NextCloud Instance from a destination folder as root. Let's see in action, once we have the template folder set created in Frappe. We can select the root folder and enable the nc_enable check and select the destination folder in NextCloud where to recreate this structure, renaming the folders in NextCloud upon its creation. We select the destination folder in NextCloud browsing in the dialog. And once selected the destination folder, on the tree we click on button Recreate to perform the copy of folders from Frappe to NextCloud. The result is seen on the image for a new Client Structure called CUSTOMER as abbreviation and Customer Name Details as Description for the Folder.
There is an automation to make automatic folders upon creation of selected included doctypes, but try to see if you can make it running. This is an Easter Egg for you to discover.