Thursday, 26 March 2015

ERPNext: Call custom app methon using hooks

write this in hooks. i.e. doc events

doc_events = {
    "Sales Order": {
        "validate": "ef_fruits.ef_doc.ef_doc.apply_documents_required"
    }
}


python file code.

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import frappe
import logging
import string
import datetime
import re
import json

from frappe.utils import getdate, flt,validate_email_add, cint
from frappe.model.naming import make_autoname
from frappe import throw, _, msgprint
import frappe.permissions
from frappe.model.document import Document
from frappe.model.mapper import get_mapped_doc

_logger = logging.getLogger(frappe.__name__)

@frappe.whitelist(allow_guest=True)
def apply_documents_required(self, method):
        doc_req = []
        if not self.documents_required:
        doc_master = frappe.get_doc("Documents Required Master", self.docs_required)
        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
            }
                        self.append("documents_required", doc_req)



Note:
1) if you call method from hooks, you will get scope of doc object.

List of events
  • validate
  • before_save
  • before_insert
  • after_insert
  • validate
  • before_submit
  • before_cancel
  • before_update_after_submit
  • on_update
  • on_submit
  • on_cancel
  • on_update_after_submit

No comments:

Post a Comment