Friday, 27 March 2015

ERPNext: Call custom app method using custom script

write this in custom script.

Custom Script

cur_frm.cscript.docs_required = function(doc, cdt, cdn) {
    cur_frm.call({
    "method": 'ef_fruits.ef_doc.ef_doc.apply_documents_requiredd',
     "args": {
           "docs_required": doc.docs_required,
        },
     callback: function(r) {
           if(!r.exc) {
           }
           }
})
};


python function in custom app.

@frappe.whitelist()
def apply_documents_required(docs_required):
    if self.documents_required_master:
        shipping_rule = frappe.get_doc("Documents Required Master", self.documents_required_master)
        frappe.msgprint("Hi @3")
        for condition in shipping_rule.get("documents_required_master"):
            doc_req = {
                "doctype": "Documents Required",
                "name_of_document": condition.name_of_document,
                "dispatch_address": condition.dispatch_address
            }
            frappe.msgprint(condition.name_of_document)
            frappe.msgprint(condition.dispatch_address)

 python function to append data in dict object.

@frappe.whitelist(allow_guest=True)
def apply_documents_required(self, method):
        doc_req = []
        if not self.documents_required and self.documents_required_master:
        doc_master = frappe.get_doc("Documents Required Master", self.documents_required_master)
        for value in doc_master.get("documents_required_master"):
            doc_req = {
                "doctype": "Documents Required",
                "name_of_document": value.name_of_document,
                "dispatch_address": value.dispatch_address,
                                "number_of_copies": value.number_of_copies
            }
                        self.append("documents_required", doc_req)


Note:
Above code will display of document name and document address.
You can return value from python function and set it into custom script.
I will write more on this later


5 comments:

  1. Hi,
    I am having problems installing custom app using "bench install-app appname". I have already tried the following:
    1.all possible combinations of uppercase and lowercase for appname.
    2.made sure the appname has an entry in apps.txt
    3.set "link":"module/appname" in desktop.py
    4.tried ./env/bin/pip install -q -e ./apps/appname (went fine, w/o err)

    I always end up getting Importerror:No module named .

    Any clues?

    ReplyDelete
  2. You need to delete module name from module.txt
    run 'bench migrate' from command line
    then login into site and create new module.

    if you have any error, post here

    My email id: kolate.sambhaji@gmail.com

    ReplyDelete
  3. Thanks sambaji....the following link helped me for now!.....https://discuss.erpnext.com/t/installing-new-custom-app/7852/13

    ReplyDelete
  4. Thanks sambaji....the following link helped me for now!.....https://discuss.erpnext.com/t/installing-new-custom-app/7852/13

    ReplyDelete
  5. Thanks sambaji....the following link helped me for now!.....https://discuss.erpnext.com/t/installing-new-custom-app/7852/13

    ReplyDelete