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


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

Wednesday 25 March 2015

ERPNext: Print warehouse address in Purchase order or Any Transaction

 You can use below code to print value from master.

{%- for row in doc.po_details|slice(1) -%}
    {% set u = frappe.get_doc(""Warehouse"", row[0].warehouse) %}
        <div class=""row"">
            <div class=""col-xs-5 text-right""><label><b>Ship To</b></label></div>
            <div class=""col-xs-7 ""> {{ u.warehouse_name or '' }} </div>
        </div>
        <div class=""row"">
            <div class=""col-xs-5 text-right""></div>
            <div class=""col-xs-7 ""> {{ u.address_line_1 or '' }} </div>
        </div>
        <div class=""row"">
            <div class=""col-xs-5 text-right""></div>
            <div class=""col-xs-7 ""> {{ u.address_line_2 or '' }} </div>
        </div>
        <div class=""row"">
            <div class=""col-xs-5 text-right""></div>
            <div class=""col-xs-7 ""> {{ u.city or '' }}, {{ u.state or '' }} {{ u.pin or '' }} </div>
        </div>
        {%- if u.phone_no -%}
            <div class=""row"">
                <div class=""col-xs-5 text-right""><label><b>Phone:</b></label></div>
                <div class=""col-xs-7 ""> {{ u.phone_no or '' }} </div>
            </div>
        {%- endif -%}
{%- endfor -%}

Tuesday 24 March 2015

In ERPNExt fetch table field from master

In ERPNext:
fetch table field from master using following code.
But, I need this with custom script.
My code is.

  python code:

    def apply_documents_required(self):
            if self.documents_required_master:
                shipping_rule = frappe.get_doc("Documents Required Master", self.documents_required_master)
                frappe.msgprint("from python function")
                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
                    }
                    if (5==5):
                        self.append("documents_required", doc_req)

js code:

    documents_required_master: function() {
            var me = this;
            msgprint("from js function")
            if(5==5) {
                return this.frm.call({
                    doc: this.frm.doc,
                    method: "apply_documents_required",
                    callback: function(r) {
                        if(!r.exc) {
                        }
                    }
                })
            }
        }

Saturday 7 March 2015

git ignore all files of a certain type

using a .gitignore you can ignore files from git.
These file will be not tracked using git.

1) info of excluded files
       cat .git/info/exclude


# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~



2) status of current .gitignore
cat .gitignore
.DS_Store
*.pyc
*.egg-info
*.swp
tags





3) edit .gitignore fiel, so that .~ files will not be tracked. (.~ is temporary files)
vi .gitignore

.DS_Store
*.pyc
*.egg-info
*.swp
*~
tags

Note: 
A gitignore file specifies intentionally untracked files that git should ignore. Files already tracked by git are not affected;
The purpose of gitignore files is to ensure that certain files not tracked by git remain untracked.
To ignore uncommitted changes in a file that is already tracked, use git update-index --assume-unchanged
To stop tracking a file that is currently tracked, use git rm --cached



other reference : http://www.tecmint.com/13-basic-cat-command-examples-in-linux/

Thursday 5 March 2015

Why large companies use open source ERP




The main reason larger companies use open source Enterprise Resource Planning (ERP) systems is because they are cheaper and easier to customize.
 
In many cases, when you are implementing an open source ERP system for a large organization, a new interface shell is created outside of the core system to meet the business needs and line-up with the company organization. With commercial systems the existing interface is customized which makes upgrades difficult to say the least. A further reason that open source ERP is used is because you own the system and its full source content, there is no lock-in or dependency on the vendor, and you are more free on how you are going to implement the software. You can do this all by yourself or hire a provider.

Further, it saves your business costs in the long run. When an open source ERP is used there are typically no license or software maintenance costs. In many cases, the external consultants and programmer fees are lower. Most open source ERP software systems can use open source databases and operating systems, giving you a license-free option. Commercial ERP systems often need expensive commercial databases and operating systems.

Large company IT departments appreciate that an open source ERP has is of higher quality, because many independent, often passionate developers have looked at it, criticized its code, and contributed enhancements. Competition between developers is very common in open source software and improves quality. Open source is often built on other open source projects and database models, so open source does not re-invent the wheel, which is what often happens in commercial systems.
Open source ERP systems are easier to upgrade when customizations are properly implemented (outside the base system) than with commercial systems, and upgrades can therefore be done much more often (every three months to monthly) without disruption of the production system.
Are there disadvantages? Sure, but only a few.

Often documentation of the commercial system is better for the standard supplied system too. However, if you are going to modify the user interface anyway, this documentation will not help you much when you need to customize the system to suit your business needs. Another disadvantage could be that open source ERP is still relatively new in large organizations. Because of this, it is sometimes difficult to convince an accounting department or other decision maker to use open source software. Lastly, auditors may not be familiar with a new interface and do not know the system yet. However, training can be easily implemented to avoid these complications when deploying a new system.

Conclusion

If you want to easily customize the system to your needs, save substantial amounts of money, and avoid vendor locked-in, the choice is easy: go open source.

A version of this article posted on LinkedIn by Hans Bakker. Republished under Creative Commons

HTML table cellspacing, cellpadding attribute Attribute

1) The cellspacing attribute specifies the space, in pixels, between cells.
2) The cellpadding attribute specifies the space, in pixels, between the cell wall and the cell content.


 The cellspacing, cellpadiing attribute is not supported in HTML5.


syntax:
table cellspacing="50" cellpadding = "10"
end table

<p>Table with cellspacing:</p>
<table cellspacing="50" cellpadding = "10">
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
</table>


3) CSS Example To add padding to a table


<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
    border: 1px solid black;
}

th, td {
    padding: 10px;
}
</style>
</head>
<body>

<table>
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
</table>

</body>
</html>