Skip to content

Community Developed Custom Scripts

Christopher G. Purbaugh edited this page Aug 17, 2016 · 4 revisions

The following provides a database of community developed custom scripts for implementing unique features through the ERPNext custom script tool. In certain cases, server-side scripts have also been written to support the client-side scripts.

###Attachment transfer This script takes attachments identified in specific custom fields of an Item document and copies them into another document as general attachments. This is used in practice to attach critical design documents to Request for Quotations and Purchase Orders that get sent automatically through e-mail.

Custom Script

frappe.ui.form.on("Request for Quotation",{
refresh: function(frm) {
    frm.add_custom_button(__("Load Attachments"), function(foo) {

	frappe.call({
		method:"my_app.my_app.controller.attach_all_docs",
		args: {
			document: cur_frm.doc,
			
		}, 
		callback: function(r) { 
			frm.reload_doc();

		}
	});
    });
    }
});

Server-Side Script

@frappe.whitelist()
def attach_all_docs(document, method=None):
    """This function attaches drawings to the purchase order based on the items being ordered"""
    document = json.loads(document)

    current_attachments = []
    for file_url in frappe.db.sql("""select file_url from `tabFile` where attached_to_doctype = %(doctype)s and     attached_to_name = %(docname)s""", {'doctype': document["doctype"], 'docname': document["name"]}, as_dict=True ):
        current_attachments.append(file_url.file_url)
        count = 0
        for item_doc in document["items"]:
            #frappe.msgprint(item_doc)
            # Check to see if the quantity is = 1
            item = frappe.get_doc("Item",item_doc["item_code"])
	
            attachments = []
            # Get the path for the attachments
            if item.drawing_attachment:
                attachments.append(item.drawing_attachment)
            if item.stp_attachment:
                attachments.append(item.stp_attachment)
            if item.dxf_attachment:
                attachments.append(item.dxf_attachment)
            if item.x_t_attachment:
                attachments.append(item.x_t_attachment)
		
            for attach in attachments:
                # Check to see if this file is attached to the one we are looking for
                if not attach in current_attachments:
                    count = count + 1
                    save_url(attach, document["doctype"], document["name"], "Home/Attachments")
    frappe.msgprint("Attached {0} files".format(count))

###Manual Dropbox Backup Add this to Setup > Custom Script > New
Doctype : Dropbox Backup
Script :

frappe.ui.form.on("Dropbox Backup", "refresh", function(frm){
	if(frm.doc.send_backups_to_dropbox){
		frm.add_custom_button(__("Take Backup"), function() {
			frappe.call({
				method: "frappe.integrations.doctype.dropbox_backup.dropbox_backup.take_backups_dropbox",
				freeze: true,
				freeze_message: __("Taking backup"),
				callback: function(r){
					if(!r.exc) {
						frappe.msgprint(__("Backup taken successfully"));
					} else {
						frappe.msgprint(__("Error while taking backup. <br /> " + r.exc));
					}
				}
			});
		})	
	}
});

Fetch child table

The following fetches all entries in a child table from another document.

frappe.ui.form.on("DocTypeB", "Trigger", function(frm) {
frappe.model.with_doc("DocTypeA", frm.doc.trigger, function() {
var tabletransfer= frappe.model.get_doc("DocTypeA", frm.doc.Trigger)
$.each(qmtable.ChildTableA, function(index, row){
d = frm.add_child("ChildTableB");
d.field1 = row.fielda;
d.field2 = row.fieldb;
cur_frm.refresh_field("ChildTableB");
})
});

});

ERPNext

####Community Wiki

External Links

Wiki Navigation

Installation Guides

  • [Install ERPNext on Debian based systems](Install ERPNext on Debian based systems)
  • [Install ERPNext on RedHat based systems](Install ERPNext on RedHat based systems)

Release Notes

Information Pages

  • [Country wise Chart of Accounts](Country wise Chart of Accounts)
  • [Developer Docs](Developer Docs)
  • [Some Useful Aliases](Some Useful Aliases)
  • [Test Checklists](Test Checklists)
  • [Community Developed Custom Scripts](Community Developed Custom Scripts)

Legacy Print Formats

  • [Legacy Print Formats (Category)](Legacy Print Formats (Category))

Legacy Information Pages

  • [WSGI Production Deployment](WSGI Production Deployment)
  • [Version 4 Permission Use Cases](Version 4 Permission Use Cases)
  • [Adding Custom Form to Website](Adding Custom Form to Website)
  • [Apache HTTP Settings for Mac OS](Apache HTTP Settings for Mac OS)
  • [ERPNext Upgrade to Version 5](ERPNext Upgrade to Version 5)
  • [Feature Suggestions](Feature Suggestions)
  • [How to Install ERPNext Version 3](How to Install ERPNext Version 3)
  • [Future Development: Tracking Productivity](Future Development: Tracking Productivity)
  • [Improve Precision of Stock Valuation](Improve Precision of Stock Valuation)
  • [Integrating Emails in ERPNext](Integrating Emails in ERPNext)
  • [Migrating your erpnext instance to wsgi](Migrating your erpnext instance to wsgi)
  • [MySQL configuration file](MySQL configuration file)
  • [Restoring From ERPNext Backup](Restoring From ERPNext Backup)
  • [Setting up Backup Manager](Setting up Backup Manager)
  • [Setting up TLS SSL certificates Let's Encrypt for ERPNext sites](Setting up TLS SSL certificates Let's Encrypt for ERPNext sites)
  • [Ubuntu HA Cluster with lsyncd, remote MariaDB, Apache Reverse Proxy Setup Guide](Ubuntu HA Cluster with lsyncd, remote MariaDB, Apache Reverse Proxy Setup Guide)
  • [Updating ERPNext Instance](Updating ERPNext Instance)

Blueprints

  • [Agri Farm ERPNext](Agri Farm ERPNext)

Troubleshooting Guides

  • [Troubleshooting Guide Template](Troubleshooting Guide Template)
  • ["Expense or Difference account is mandatory for [YOUR ITEM HERE] as it impacts overall stock value"]("Expense or Difference account is mandatory for [YOUR ITEM HERE] as it impacts overall stock value")

Clone this wiki locally