Thursday, 14 May 2015

Interaction to be updated

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

frappe.ui.form.on("Sales Order", "refresh", function(frm, doctype, name) {
cur_frm.add_custom_button(__('Generate Document'), function() {
    msgprint(frm.doc.owner)
    msgprint(frm.doc.doctype)
var d = frappe.prompt([
    {'fieldname': 'birth', 'fieldtype': 'Date', 'label': 'Birth Date', 'reqd': 0},
    {'fieldname': 'comment', 'fieldtype': 'Text', 'label': 'Comment', 'reqd': 1}
],
function(values){
    var c = d.get_values()
    var cmnt = c.comment
    var me = frm.doc
    return frappe.call({
            method: "frappe.desk.form.utils.add_comment",
            args: {
                doc:{
                    doctype: "Comment",
                    comment_type: "Comment",
                    comment_doctype: frm.doc.doctype,
                    comment_docname: frm.doc.name,
                    comment: cmnt,
                    comment_by: user
                }
            },
            callback: function(r) {
                if(!r.exc) {
                    frm.get_docinfo().comments =
                        me.get_comments().concat([r.message]);
                    input.val("");
                    refresh(true);
                }
            }
        });
},
'Age verification',
'Subscribe me'
)
}, "icon-exclamation", "btn-default");
});

frappe.ui.form.on("Sales Order", "press_me", function(frm, doctype, name) {
    msgprint(frm.doc.owner)
    msgprint(frm.doc.doctype)
var d = frappe.prompt([
    {'fieldname': 'birth', 'fieldtype': 'Date', 'label': 'Birth Date', 'reqd': 0},
    {'fieldname': 'comment', 'fieldtype': 'Text', 'label': 'Comment', 'reqd': 1}
],
function(values){
    var c = d.get_values()
    var cmnt = c.comment
    var me = frm.doc
    return frappe.call({
            method: "frappe.desk.form.utils.add_comment",
            args: {
                doc:{
                    doctype: "Comment",
                    comment_type: "Comment",
                    comment_doctype: frm.doc.doctype,
                    comment_docname: frm.doc.name,
                    comment: cmnt,
                    comment_by: user
                }
            },
            callback: function(r) {
                if(!r.exc) {
                    frm.get_docinfo().comments =
                        me.get_comments().concat([r.message]);
                    input.val("");
                    refresh(true);
                }
            }
        });
},
'Age verification',
'Subscribe me'
)
});

working with comment and prompt box



frappe.ui.form.on("Sales Order", "press_me", function(frm, doctype, name) {
var d = frappe.prompt([
    {'fieldname': 'birth', 'fieldtype': 'Date', 'label': 'Birth Date', 'reqd': 0},
    {'fieldname': 'text', 'fieldtype': 'Text', 'label': 'Comment', 'reqd': 1}
],
function(values){
    var c = d.get_values()
    msgprint(frm.doc.customer)
    msgprint(frm.doc.doctype)
    frappe.model.open_mapped_doc({
            "method": "ngse.ngse_doc.ef_doc.apply_prompt_comment",
                        "args:": {
                                 "source_name": cur_frm,
                                 "dtype": frm.doc.doctype,
                         },
        });
},
'Age verification',
'Subscribe me'
)
});



@frappe.whitelist(allow_guest=True)
def apply_comment(source_name, target_doc=None):
        comment = frappe.new_doc("Comment")
        comment.comment = "test two"
        comment.comment_doctype = "Sales Order"
        comment.comment_docname = "SO-00110"
        comment.save()
        msgprint("after save")
        cur_doc = frappe.get_doc("Sales Order", source_name)

@frappe.whitelist(allow_guest=True)
def apply_prompt_comment(source_name, dtype, target_doc=None):
        comment = frappe.new_doc("Comment")
        comment.comment = dtype
        comment.comment_doctype = "Sales Order"
        comment.comment_docname = "SO-00110"
        comment.save()
        msgprint("Interaction Submited")
        cur_doc = frappe.get_doc("Sales Order", source_name)

Custom Script to Manupulate Child Table Data e.g Purchase Order Item

When we create Purchase Order from Material Request and Purchase UOM is not same as stock uom then we need to reset Purchase order qty.


E.g.1) always change qty = qty/conversion factor
frappe.ui.form.on('Purchase Order', 'validate', function(frm){
    for (var idx in frm.doc.items){
        if (frm.doc.items[idx].stock_uom != frm.doc.items[idx].uom){
            frm.doc.items[idx].qty = frm.doc.items[idx].qty/frm.doc.items[idx].conversion_factor
        }
    }
    });




E.g. 2) change only when PO created from Material Request

frappe.ui.form.on('Purchase Order', 'validate', function(frm){
    if(frm.doc.items[0].prevdoc_docname){
    for (var idx in frm.doc.items){
        if (frm.doc.items[idx].stock_uom != frm.doc.items[idx].uom){
            frm.doc.items[idx].qty = frm.doc.items[idx].qty/frm.doc.items[idx].conversion_factor
        }
    }

    }
    });


Note:
Here, for loop is used to execute loop and change all item values ``for (var idx in frm.doc.items)``



Previously we are trying this for UOM conversion

cur_frm.cscript.rate_per_weight_unit = function(doc, cdt, cdn) {
    var item = frappe.get_doc(cdt, cdn);
    var rate = item.rate_per_weight_unit * item.quantity_in_weight / item.qty;
    frappe.model.set_value(cdt, cdn, "rate", rate);
};

Tuesday, 12 May 2015

Working with BITBUCKET


How to add repository to BITBUCKET?

For existing repository.(initialize, add all files, commit, push
1) git init
2) git remote add origin https://<username>@bitbucket.org/<repo-name>.git
3) git add .
4) git commit -m 'initial commit'
5) git push -u origin master

 For new repository. (create first file, commit, and push)
1) git init
2) git remote add origin https://<username>@bitbucket.org/<repo-name>.git
3) echo "Sambhaji" >>contributors.txt
4) git commit -m 'initial commit with contributors'
5) git push -u origin master

Thursday, 7 May 2015

GL Report With running credit and running debit

python file:

def execute(filters=None):
    if not filters: filters = {}
   
    columns = get_columns()
    data = get_entries(filters)
   
    return columns, data
   
def get_columns():
    return [_("Journal Voucher") + ":Link/Journal Voucher:140", _("Account") + ":Link/Account:140",
        _("Posting Date") + ":Date:100", _("Against Account") + ":Link/Account:200",
        _("Debit") + ":Currency:120", _("Running Debit") + ":Currency:120",
                _("Credit") + ":Currency:120", _("Running Credit") + ":Currency:120",
                _("Posting Reference") + "::130", _("Reference") + "::100", _("Ref Date") + ":Date:110",
    ]

def get_conditions(filters):
    conditions = ""
    if not filters.get("account"):
        msgprint(_("Please select Bank Account"), raise_exception=1)
    else:
        conditions += " and jvd.account = %(account)s"
       
    if filters.get("from_date"): conditions += " and jv.posting_date>=%(from_date)s"
    if filters.get("to_date"): conditions += " and jv.posting_date<=%(to_date)s"
   
    return conditions
   
def get_entries(filters):
    conditions = get_conditions(filters)
    entries =  frappe.db.sql("""select jv.name, jvd.account, jv.posting_date,
        jvd.against_account, jvd.debit, (@rdeb:=@rdeb+(ifnull(jvd.debit, 0))) as RunningDebit,
                jvd.credit, (@rcredit:=@rcredit+(ifnull(jvd.credit, 0))) as RunningCredit,
                jvd.remark, jv.cheque_no, jv.cheque_date
        from `tabJournal Voucher Detail` jvd, `tabJournal Voucher` jv
        JOIN (select @rcredit := 0.0, @rdeb:=0.0) B
        where jvd.parent = jv.name and jv.docstatus=1 %s
        order by jv.name DESC
        """ % conditions, filters, as_list=1)
    return entries



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()