Thursday, 30 April 2015

customer and supplier name in general ledger report using case statement in sql query.


This issue is solved using case statement in sql query.
sample query:
select
       item_code, warehouse, voucher_type, voucher_no,
       CASE
            WHEN voucher_type = "Purchase Receipt" then (select supplier_name from `tabPurchase Receipt` where name=voucher_no)
            WHEN voucher_type = "Delivery Note" then (select customer_name from `tabDelivery Note` where name=voucher_no)
            ELSE " "
       END AS Name
       from `tabStock Ledger Entry`
o/p:

Inline image 2

Updated Stock Ledger Report:

Inline image 3

If any query, Please comment.

Monday, 6 April 2015

ERPNext: Create custom button and call custom


ERPNext: Create custom button and call custom method from app

cur_frm.cscript.custom_refresh = function(doc) {
cur_frm.add_custom_button(__('Generate Document'),
cur_frm.cscript['generate_document'], "icon-exclamation", "btn-default");
};

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


above script will create custom button on doctype.
after click, generate_document custom script will be called.
from custom script custom python method is called.

this example explains how to call custom event onclick.



Method II:

frappe.ui.form.on("Sales Order", "generate_document", function(frm, doctype, name) {
    msgprint("hi")
    frappe.model.open_mapped_doc({
            method: "ef_fruits.ef_doc.ef_doc.
generate_document",
            frm: cur_frm
        });
});  


@frappe.whitelist()
def
generate_document(source_name, target=None):
    doc_m = frappe.get_doc("Sales Order", source_name)
    doc_m.submit();

    frappe.msgprint(doc_m.customer)    

Method III: to change customer name
@frappe.whitelist()
def make_sales_invoice(source_name, target=None):
    doc_m = frappe.get_doc("Sales Order", source_name)
    doc_m.customer = "
Sambhaji"
    doc_m.set("customer","Sambhaji");
    doc_m.save();

    frappe.msgprint(doc_m.customer)   

#doc_m.save() this saves the document.
#doc_m.set(key, value)  this saves set the values

Method IV: this will insert new document "Bank Set Of Documents"

@frappe.whitelist()
def make_bank_document(source_name, target=None):
    doc_m = frappe.get_doc("Sales Order", source_name)
    doc_m.customer = "Satish"
    frappe.msgprint(doc_m.name)
    bank=frappe.new_doc("Bank Set Of Documents")
    bank.sales_order = doc_m.name
    bank.rounded_total = doc_m.rounded_total,
    bank.customer_name = doc_m.customer_name,
    bank.payment_terms = doc_m.payment_terms
    bank.insert()