Merge pull request #20617 from jsukrut/develop

fix: restricted duplicate courses on Program Enrollment doctype (#20611)
diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml
new file mode 100644
index 0000000..7c6b843
--- /dev/null
+++ b/.github/workflows/backport.yml
@@ -0,0 +1,16 @@
+name: Backport
+on:
+  pull_request:
+    types:
+      - closed
+      - labeled
+
+jobs:
+  backport:
+    runs-on: ubuntu-18.04
+    name: Backport
+    steps:
+      - name: Backport
+        uses: tibdex/backport@v1
+        with:
+          github_token: ${{ secrets.GITHUB_TOKEN }}
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
index 365eb67..213445b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -77,5 +77,6 @@
   - bench --site test_site reinstall --yes
 
 after_script:
+  - pip install coverage==4.5.4
   - pip install python-coveralls
   - coveralls -b apps/erpnext -d ../../sites/.coverage
diff --git a/erpnext/accounts/doctype/account/chart_of_accounts/verified/de_kontenplan_SKR03_gnucash.json b/erpnext/accounts/doctype/account/chart_of_accounts/verified/de_kontenplan_SKR03_gnucash.json
new file mode 100644
index 0000000..89465ee
--- /dev/null
+++ b/erpnext/accounts/doctype/account/chart_of_accounts/verified/de_kontenplan_SKR03_gnucash.json
@@ -0,0 +1,526 @@
+{
+    "country_code": "de",
+    "name": "SKR03 mit Kontonummern",
+    "tree": {
+        "Aktiva": {
+            "is_group": 1,
+			"root_type": "Asset",
+            "A - Anlagevermögen": {
+                "is_group": 1,
+                "EDV-Software": {
+                    "account_number": "0027",
+                    "account_type": "Fixed Asset"
+                },
+                "Gesch\u00e4ftsausstattung": {
+                    "account_number": "0410",
+                    "account_type": "Fixed Asset"
+                },
+                "B\u00fcroeinrichtung": {
+                    "account_number": "0420",
+                    "account_type": "Fixed Asset"
+                },
+                "Darlehen": {
+                    "account_number": "0565"
+                },
+                "Maschinen": {
+                    "account_number": "0210",
+                    "account_type": "Fixed Asset"
+                },
+                "Betriebsausstattung": {
+                    "account_number": "0400",
+                    "account_type": "Fixed Asset"
+                },
+                "Ladeneinrichtung": {
+                    "account_number": "0430",
+                    "account_type": "Fixed Asset"
+				},
+				"Accumulated Depreciation": {
+					"account_type": "Accumulated Depreciation"
+				}
+			},
+			"B - Umlaufvermögen": {
+				"is_group": 1,
+				"I. Vorräte": {
+					"is_group": 1,
+					"Roh-, Hilfs- und Betriebsstoffe (Bestand)": {
+						"account_number": "3970",
+						"account_type": "Stock"
+					},
+					"Waren (Bestand)": {
+						"account_number": "3980",
+						"account_type": "Stock"
+					}
+				},
+				"II. Forderungen und sonstige Vermögensgegenstände": {
+					"is_group": 1,
+					"Ford. a. Lieferungen und Leistungen": {
+						"account_number": "1400",
+						"account_type": "Receivable"
+					},
+					"Durchlaufende Posten": {
+						"account_number": "1590"
+					},
+					"Gewinnermittlung \u00a74/3 nicht Ergebniswirksam": {
+						"account_number": "1371"
+					},
+					"Abziehbare VSt. 7%": {
+						"account_number": "1571"
+					},
+					"Abziehbare VSt. 19%": {
+						"account_number": "1576"
+					},
+					"Abziehbare VStr. nach \u00a713b UStG 19%": {
+						"account_number": "1577"
+					},
+					"Leistungen \u00a713b UStG 19% Vorsteuer, 19% Umsatzsteuer": {
+						"account_number": "3120"
+					}
+				},
+				"III. Wertpapiere": {
+					"is_group": 1
+				},
+				"IV. Kassenbestand, Bundesbankguthaben, Guthaben bei Kreditinstituten und Schecks.": {
+					"is_group": 1,
+					"Kasse": {
+						"account_type": "Cash",
+						"is_group": 1,
+						"Kasse": {
+							"is_group": 1,
+							"account_number": "1000",
+							"account_type": "Cash"
+						}
+					},
+					"Bank": {
+						"is_group": 1,
+						"account_type": "Bank",
+						"Postbank": {
+							"account_number": "1100",
+							"account_type": "Bank"
+						},
+						"Bankkonto": {
+							"account_number": "1200",
+							"account_type": "Bank"
+						}
+					}
+				}
+			},
+			"C - Rechnungsabgrenzungsposten": {
+				"is_group": 1,
+				"Aktive Rechnungsabgrenzung": {
+                    "account_number": "0980"
+				}
+			},
+			"D - Aktive latente Steuern": {
+				"is_group": 1,
+				"Aktive latente Steuern": {
+                    "account_number": "0983"
+				}
+			},
+			"E - Aktiver Unterschiedsbetrag aus der Vermögensverrechnung": {
+				"is_group": 1
+			}
+        },
+        "Passiva": {
+            "is_group": 1,
+			"root_type": "Liability",
+			"A. Eigenkapital": {
+				"is_group": 1,
+				"I. Gezeichnetes Kapital": {
+					"is_group": 1
+				},
+				"II. Kapitalrücklage": {
+					"is_group": 1
+				},
+				"III. Gewinnrücklagen": {
+					"is_group": 1
+				},
+				"IV. Gewinnvortrag/Verlustvortrag": {
+					"is_group": 1
+				},
+				"V. Jahresüberschuß/Jahresfehlbetrag": {
+					"is_group": 1
+				}
+			},
+			"B. Rückstellungen": {
+				"is_group": 1,
+				"I. Rückstellungen für Pensionen und ähnliche Verpflichtungen": {
+					"is_group": 1
+				},
+				"II. Steuerrückstellungen": {
+					"is_group": 1
+				},
+				"III. sonstige Rückstellungen": {
+					"is_group": 1
+				}
+			},
+			"C. Verbindlichkeiten": {
+				"is_group": 1,
+				"I. Anleihen": {
+					"is_group": 1
+				},
+				"II. Verbindlichkeiten gegenüber Kreditinstituten": {
+					"is_group": 1
+				},
+				"III. Erhaltene Anzahlungen auf Bestellungen": {
+					"is_group": 1
+				},
+				"IV. Verbindlichkeiten aus Lieferungen und Leistungen": {
+					"is_group": 1,
+					"Verbindlichkeiten aus Lieferungen u. Leistungen": {
+						"account_number": "1600",
+						"account_type": "Payable"
+					}
+				},
+				"V. Verbindlichkeiten aus der Annahme gezogener Wechsel und der Ausstellung eigener Wechsel": {
+					"is_group": 1
+				},
+				"VI. Verbindlichkeiten gegenüber verbundenen Unternehmen": {
+					"is_group": 1
+				},
+				"VII. Verbindlichkeiten gegenüber Unternehmen, mit denen ein Beteiligungsverhältnis besteht": {
+					"is_group": 1
+				},
+				"VIII. sonstige Verbindlichkeiten": {
+					"is_group": 1,
+					"Sonstige Verbindlichkeiten": {
+						"account_number": "1700",
+						"account_type": "Asset Received But Not Billed"
+					},
+					"Sonstige Verbindlichkeiten (1 bis 5 Jahre)": {
+						"account_number": "1702",
+						"account_type": "Stock Received But Not Billed"
+					},
+					"Verbindlichkeiten aus Lohn und Gehalt": {
+						"account_number": "1740",
+						"account_type": "Payable"
+					},
+					"Umsatzsteuer": {
+						"is_group": 1,
+						"Umsatzsteuer 7%": {
+							"account_number": "1771"
+						},
+						"Umsatzsteuer 19%": {
+							"account_number": "1776"
+						},
+						"Umsatzsteuer-Vorauszahlung": {
+							"account_number": "1780"
+						},
+						"Umsatzsteuer-Vorauszahlung 1/11": {
+							"account_number": "1781"
+						},
+						"Umsatzsteuer \u00a7 13b UStG 19%": {
+							"account_number": "1787"
+						},
+						"Umsatzsteuer Vorjahr": {
+							"account_number": "1790"
+						},
+						"Umsatzsteuer fr\u00fchere Jahre": {
+							"account_number": "1791"
+						}
+					}
+				}
+			},
+			"D. Rechnungsabgrenzungsposten": {
+				"is_group": 1,
+				"Passive Rechnungsabgrenzung": {
+					"account_number": "0990"
+				}
+			},
+			"E. Passive latente Steuern": {
+				"is_group": 1
+			}
+        },
+        "Erl\u00f6se u. Ertr\u00e4ge 2/8": {
+            "is_group": 1,
+            "root_type": "Income",
+            "Erl\u00f6skonten 8": {
+				"is_group": 1,
+				"Erl\u00f6se": {
+                    "account_number": "8200",
+                    "account_type": "Income Account"
+                },
+                "Erl\u00f6se USt. 19%": {
+                    "account_number": "8400",
+                    "account_type": "Income Account"
+                },
+                "Erl\u00f6se USt. 7%": {
+                    "account_number": "8300",
+                    "account_type": "Income Account"
+                }
+            },
+            "Ertragskonten 2": {
+                "is_group": 1,
+                "sonstige Zinsen und \u00e4hnliche Ertr\u00e4ge": {
+                    "account_number": "2650",
+                    "account_type": "Income Account"
+                },
+                "Au\u00dferordentliche Ertr\u00e4ge": {
+                    "account_number": "2500",
+                    "account_type": "Income Account"
+                },
+                "Sonstige Ertr\u00e4ge": {
+                    "account_number": "2700",
+                    "account_type": "Income Account"
+                }
+            }
+        },
+        "Aufwendungen 2/4": {
+            "is_group": 1,
+			"root_type": "Expense",
+			"Wareneingang": {
+				"account_number": "3200"
+			},
+			"Bezugsnebenkosten": {
+				"account_number": "3800",
+				"account_type": "Expenses Included In Asset Valuation"
+			},
+			"Herstellungskosten": {
+				"account_number": "4996",
+				"account_type": "Cost of Goods Sold"
+			},
+			"Verluste aus dem Abgang von Gegenständen des Anlagevermögens": {
+				"account_number": "2320",
+				"account_type": "Stock Adjustment"
+			},
+			"Verwaltungskosten": {
+				"account_number": "4997",
+				"account_type": "Expenses Included In Valuation"
+			},
+			"Vertriebskosten": {
+				"account_number": "4998",
+				"account_type": "Expenses Included In Valuation"
+			},
+			"Gegenkonto 4996-4998": {
+				"account_number": "4999"
+			},
+            "Abschreibungen": {
+                "is_group": 1,
+				"Abschreibungen auf Sachanlagen (ohne AfA auf Kfz und Gebäude)": {
+                    "account_number": "4830",
+                    "account_type": "Accumulated Depreciation"
+				},
+				"Abschreibungen auf Gebäude": {
+                    "account_number": "4831",
+                    "account_type": "Depreciation"
+				},
+				"Abschreibungen auf Kfz": {
+                    "account_number": "4832",
+                    "account_type": "Depreciation"
+				},
+				"Sofortabschreibung GWG": {
+                    "account_number": "4855",
+                    "account_type": "Expense Account"
+				}
+            },
+            "Kfz-Kosten": {
+                "is_group": 1,
+                "Kfz-Steuer": {
+                    "account_number": "4510",
+                    "account_type": "Expense Account"
+                },
+                "Kfz-Versicherungen": {
+                    "account_number": "4520",
+                    "account_type": "Expense Account"
+                },
+                "laufende Kfz-Betriebskosten": {
+                    "account_number": "4530",
+                    "account_type": "Expense Account"
+                },
+                "Kfz-Reparaturen": {
+                    "account_number": "4540",
+                    "account_type": "Expense Account"
+                },
+                "Fremdfahrzeuge": {
+                    "account_number": "4570",
+                    "account_type": "Expense Account"
+                },
+                "sonstige Kfz-Kosten": {
+                    "account_number": "4580",
+                    "account_type": "Expense Account"
+                }
+            },
+            "Personalkosten": {
+                "is_group": 1,
+                "Geh\u00e4lter": {
+                    "account_number": "4120",
+                    "account_type": "Expense Account"
+                },
+                "gesetzliche soziale Aufwendungen": {
+                    "account_number": "4130",
+                    "account_type": "Expense Account"
+                },
+                "Aufwendungen f\u00fcr Altersvorsorge": {
+                    "account_number": "4165",
+                    "account_type": "Expense Account"
+                },
+                "Verm\u00f6genswirksame Leistungen": {
+                    "account_number": "4170",
+                    "account_type": "Expense Account"
+                },
+                "Aushilfsl\u00f6hne": {
+                    "account_number": "4190",
+                    "account_type": "Expense Account"
+                }
+            },
+            "Raumkosten": {
+                "is_group": 1,
+                "Miete und Nebenkosten": {
+                    "account_number": "4210",
+                    "account_type": "Expense Account"
+                },
+                "Gas, Wasser, Strom (Verwaltung, Vertrieb)": {
+                    "account_number": "4240",
+                    "account_type": "Expense Account"
+                },
+                "Reinigung": {
+                    "account_number": "4250",
+                    "account_type": "Expense Account"
+                }
+            },
+            "Reparatur/Instandhaltung": {
+                "is_group": 1,
+                "Reparatur u. Instandh. von Anlagen/Maschinen u. Betriebs- u. Gesch\u00e4ftsausst.": {
+                    "account_number": "4805",
+                    "account_type": "Expense Account"
+                }
+            },
+            "Versicherungsbeitr\u00e4ge": {
+                "is_group": 1,
+                "Versicherungen": {
+                    "account_number": "4360",
+                    "account_type": "Expense Account"
+                },
+                "Beitr\u00e4ge": {
+                    "account_number": "4380",
+                    "account_type": "Expense Account"
+                },
+                "sonstige Ausgaben": {
+                    "account_number": "4390",
+                    "account_type": "Expense Account"
+                },
+                "steuerlich abzugsf\u00e4hige Versp\u00e4tungszuschl\u00e4ge und Zwangsgelder": {
+                    "account_number": "4396",
+                    "account_type": "Expense Account"
+                }
+            },
+            "Werbe-/Reisekosten": {
+                "is_group": 1,
+                "Werbekosten": {
+                    "account_number": "4610",
+                    "account_type": "Expense Account"
+                },
+                "Aufmerksamkeiten": {
+                    "account_number": "4653",
+                    "account_type": "Expense Account"
+                },
+                "nicht abzugsf\u00e4hige Betriebsausg. aus Werbe-, Repr\u00e4s.- u. Reisekosten": {
+                    "account_number": "4665",
+                    "account_type": "Expense Account"
+                },
+                "Reisekosten Unternehmer": {
+                    "account_number": "4670",
+                    "account_type": "Expense Account"
+                }
+            },
+            "verschiedene Kosten": {
+                "is_group": 1,
+                "Porto": {
+                    "account_number": "4910",
+                    "account_type": "Expense Account"
+                },
+                "Telekom": {
+                    "account_number": "4920",
+                    "account_type": "Expense Account"
+                },
+                "Mobilfunk D2": {
+                    "account_number": "4921",
+                    "account_type": "Expense Account"
+                },
+                "Internet": {
+                    "account_number": "4922",
+                    "account_type": "Expense Account"
+                },
+                "B\u00fcrobedarf": {
+                    "account_number": "4930",
+                    "account_type": "Expense Account"
+                },
+                "Zeitschriften, B\u00fccher": {
+                    "account_number": "4940",
+                    "account_type": "Expense Account"
+                },
+                "Fortbildungskosten": {
+                    "account_number": "4945",
+                    "account_type": "Expense Account"
+                },
+                "Buchf\u00fchrungskosten": {
+                    "account_number": "4955",
+                    "account_type": "Expense Account"
+                },
+                "Abschlu\u00df- u. Pr\u00fcfungskosten": {
+                    "account_number": "4957",
+                    "account_type": "Expense Account"
+                },
+                "Nebenkosten des Geldverkehrs": {
+                    "account_number": "4970",
+                    "account_type": "Expense Account"
+                },
+                "Werkzeuge und Kleinger\u00e4te": {
+                    "account_number": "4985",
+                    "account_type": "Expense Account"
+                }
+            },
+            "Zinsaufwendungen": {
+                "is_group": 1,
+                "Zinsaufwendungen f\u00fcr kurzfristige Verbindlichkeiten": {
+                    "account_number": "2110",
+                    "account_type": "Expense Account"
+                },
+                "Zinsaufwendungen f\u00fcr KFZ Finanzierung": {
+                    "account_number": "2121",
+                    "account_type": "Expense Account"
+                }
+            }
+        },
+        "Anfangsbestand 9": {
+            "is_group": 1,
+            "root_type": "Equity",
+            "Saldenvortragskonten": {
+                "is_group": 1,
+                "Saldenvortrag Sachkonten": {
+                    "account_number": "9000"
+                },
+                "Saldenvortr\u00e4ge Debitoren": {
+                    "account_number": "9008"
+                },
+                "Saldenvortr\u00e4ge Kreditoren": {
+                    "account_number": "9009"
+                }
+            }
+        },
+        "Privatkonten 1": {
+            "is_group": 1,
+            "root_type": "Equity",
+            "Privatentnahmen/-einlagen": {
+                "is_group": 1,
+                "Privatentnahme allgemein": {
+                    "account_number": "1800"
+                },
+                "Privatsteuern": {
+                    "account_number": "1810"
+                },
+                "Sonderausgaben beschr\u00e4nkt abzugsf\u00e4hig": {
+                    "account_number": "1820"
+                },
+                "Sonderausgaben unbeschr\u00e4nkt abzugsf\u00e4hig": {
+                    "account_number": "1830"
+                },
+                "Au\u00dfergew\u00f6hnliche Belastungen": {
+                    "account_number": "1850"
+                },
+                "Privateinlagen": {
+                    "account_number": "1890"
+                }
+            }
+        }
+    }
+}
diff --git a/erpnext/accounts/doctype/bank_reconciliation/bank_reconciliation.js b/erpnext/accounts/doctype/bank_reconciliation/bank_reconciliation.js
index 7c94455..19fadbf 100644
--- a/erpnext/accounts/doctype/bank_reconciliation/bank_reconciliation.js
+++ b/erpnext/accounts/doctype/bank_reconciliation/bank_reconciliation.js
@@ -3,16 +3,16 @@
 
 frappe.ui.form.on("Bank Reconciliation", {
 	setup: function(frm) {
-		frm.add_fetch("bank_account", "account_currency", "account_currency");
+		frm.add_fetch("account", "account_currency", "account_currency");
 	},
 
 	onload: function(frm) {
 
 		let default_bank_account =  frappe.defaults.get_user_default("Company")? 
 			locals[":Company"][frappe.defaults.get_user_default("Company")]["default_bank_account"]: "";
-		frm.set_value("bank_account", default_bank_account);
+		frm.set_value("account", default_bank_account);
 
-		frm.set_query("bank_account", function() {
+		frm.set_query("account", function() {
 			return {
 				"filters": {
 					"account_type": ["in",["Bank","Cash"]],
diff --git a/erpnext/accounts/doctype/bank_reconciliation/bank_reconciliation.json b/erpnext/accounts/doctype/bank_reconciliation/bank_reconciliation.json
index e2f967d..b85ef3e 100644
--- a/erpnext/accounts/doctype/bank_reconciliation/bank_reconciliation.json
+++ b/erpnext/accounts/doctype/bank_reconciliation/bank_reconciliation.json
@@ -19,10 +19,9 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "description": "Select account head of the bank where cheque was deposited.", 
-   "fetch_from": "bank_account_no.account", 
+   "fetch_from": "bank_account.account", 
    "fetch_if_empty": 1, 
-   "fieldname": "bank_account", 
+   "fieldname": "account", 
    "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
@@ -31,7 +30,7 @@
    "in_global_search": 0, 
    "in_list_view": 1, 
    "in_standard_filter": 0, 
-   "label": "Bank Account", 
+   "label": "Account", 
    "length": 0, 
    "no_copy": 0, 
    "options": "Account", 
@@ -164,7 +163,6 @@
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
-   "precision": "", 
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
@@ -183,8 +181,9 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "description": "Select the Bank Account to reconcile.",
    "fetch_if_empty": 0, 
-   "fieldname": "bank_account_no", 
+   "fieldname": "bank_account", 
    "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
@@ -193,12 +192,11 @@
    "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Bank Account No", 
+   "label": "Bank Account", 
    "length": 0, 
    "no_copy": 0, 
    "options": "Bank Account", 
    "permlevel": 0, 
-   "precision": "", 
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
@@ -450,7 +448,7 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2019-04-09 18:41:06.110453", 
+ "modified": "2020-01-22 00:00:00.000000", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Bank Reconciliation", 
@@ -483,4 +481,4 @@
  "track_changes": 0, 
  "track_seen": 0, 
  "track_views": 0
-}
\ No newline at end of file
+}
diff --git a/erpnext/accounts/doctype/bank_reconciliation/bank_reconciliation.py b/erpnext/accounts/doctype/bank_reconciliation/bank_reconciliation.py
index 90cdf83..52bbe33 100644
--- a/erpnext/accounts/doctype/bank_reconciliation/bank_reconciliation.py
+++ b/erpnext/accounts/doctype/bank_reconciliation/bank_reconciliation.py
@@ -21,10 +21,6 @@
 		if not self.include_reconciled_entries:
 			condition = " and (clearance_date is null or clearance_date='0000-00-00')"
 
-		account_cond = ""
-		if self.bank_account_no:
-			account_cond = " and t2.bank_account_no = {0}".format(frappe.db.escape(self.bank_account_no))
-
 		journal_entries = frappe.db.sql("""
 			select
 				"Journal Entry" as payment_document, t1.name as payment_entry,
@@ -34,15 +30,12 @@
 			from
 				`tabJournal Entry` t1, `tabJournal Entry Account` t2
 			where
-				t2.parent = t1.name and t2.account = %s and t1.docstatus=1
-				and t1.posting_date >= %s and t1.posting_date <= %s
-				and ifnull(t1.is_opening, 'No') = 'No' {0} {1}
+				t2.parent = t1.name and t2.account = %(account)s and t1.docstatus=1
+				and t1.posting_date >= %(from)s and t1.posting_date <= %(to)s
+				and ifnull(t1.is_opening, 'No') = 'No' %(condition)s
 			group by t2.account, t1.name
 			order by t1.posting_date ASC, t1.name DESC
-		""".format(condition, account_cond), (self.bank_account, self.from_date, self.to_date), as_dict=1)
-
-		if self.bank_account_no:
-			condition = " and bank_account = %(bank_account_no)s"
+		""", {"condition":condition, "account": self.account, "from": self.from_date, "to": self.to_date}, as_dict=1)
 
 		payment_entries = frappe.db.sql("""
 			select
@@ -55,12 +48,12 @@
 			from `tabPayment Entry`
 			where
 				(paid_from=%(account)s or paid_to=%(account)s) and docstatus=1
-				and posting_date >= %(from)s and posting_date <= %(to)s {0}
+				and posting_date >= %(from)s and posting_date <= %(to)s
+				and bank_account = %(bank_account)s
 			order by
 				posting_date ASC, name DESC
-		""".format(condition),
-		        {"account":self.bank_account, "from":self.from_date,
-				"to":self.to_date, "bank_account_no": self.bank_account_no}, as_dict=1)
+		""", {"account": self.account, "from":self.from_date,
+				"to": self.to_date, "bank_account": self.bank_account}, as_dict=1)
 
 		pos_entries = []
 		if self.include_pos_transactions:
@@ -72,11 +65,10 @@
 				from `tabSales Invoice Payment` sip, `tabSales Invoice` si, `tabAccount` account
 				where
 					sip.account=%(account)s and si.docstatus=1 and sip.parent = si.name
-					and account.name = sip.account and si.posting_date >= %(from)s and si.posting_date <= %(to)s {0}
+					and account.name = sip.account and si.posting_date >= %(from)s and si.posting_date <= %(to)s
 				order by
 					si.posting_date ASC, si.name DESC
-			""".format(condition),
-			        {"account":self.bank_account, "from":self.from_date, "to":self.to_date}, as_dict=1)
+			""", {"account":self.account, "from":self.from_date, "to":self.to_date}, as_dict=1)
 
 		entries = sorted(list(payment_entries)+list(journal_entries+list(pos_entries)),
 			key=lambda k: k['posting_date'] or getdate(nowdate()))
diff --git a/erpnext/accounts/doctype/bank_transaction_payments/bank_transaction_payments.json b/erpnext/accounts/doctype/bank_transaction_payments/bank_transaction_payments.json
index a75e866..ab3f60d 100644
--- a/erpnext/accounts/doctype/bank_transaction_payments/bank_transaction_payments.json
+++ b/erpnext/accounts/doctype/bank_transaction_payments/bank_transaction_payments.json
@@ -110,6 +110,15 @@
    "set_only_once": 0, 
    "translatable": 0, 
    "unique": 0
+  }, 
+  {
+   "depends_on": "eval:doc.docstatus==1",
+   "fieldname": "clearance_date",
+   "fieldtype": "Date",
+   "label": "Clearance Date",
+   "no_copy": 1,
+   "print_hide": 1,
+   "read_only": 1
   }
  ], 
  "has_web_view": 0, 
@@ -122,7 +131,7 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2018-12-06 10:57:02.635141", 
+ "modified": "2020-01-22 00:00:00.000000", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Bank Transaction Payments", 
@@ -138,4 +147,4 @@
  "track_changes": 1, 
  "track_seen": 0, 
  "track_views": 0
-}
\ No newline at end of file
+}
diff --git a/erpnext/accounts/doctype/mode_of_payment/mode_of_payment.py b/erpnext/accounts/doctype/mode_of_payment/mode_of_payment.py
index fcf94ce..d54a47e 100644
--- a/erpnext/accounts/doctype/mode_of_payment/mode_of_payment.py
+++ b/erpnext/accounts/doctype/mode_of_payment/mode_of_payment.py
@@ -11,6 +11,7 @@
 	def validate(self):
 		self.validate_accounts()
 		self.validate_repeating_companies()
+		self.validate_pos_mode_of_payment()
 	
 	def validate_repeating_companies(self):
 		"""Error when Same Company is entered multiple times in accounts"""
@@ -27,3 +28,15 @@
 			if frappe.db.get_value("Account", entry.default_account, "company") != entry.company:
 				frappe.throw(_("Account {0} does not match with Company {1} in Mode of Account: {2}")
 					.format(entry.default_account, entry.company, self.name))
+
+	def validate_pos_mode_of_payment(self):
+		if not self.enabled:
+			pos_profiles = frappe.db.sql("""SELECT sip.parent FROM `tabSales Invoice Payment` sip 
+				WHERE sip.parenttype = 'POS Profile' and sip.mode_of_payment = %s""", (self.name))
+			pos_profiles = list(map(lambda x: x[0], pos_profiles))
+			
+			if pos_profiles:
+				message = "POS Profile " + frappe.bold(", ".join(pos_profiles)) + " contains \
+					Mode of Payment " + frappe.bold(str(self.name)) + ". Please remove them to disable this mode."
+				frappe.throw(_(message), title="Not Allowed")
+
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
index 7725994..3cd988c 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
@@ -149,6 +149,7 @@
   "column_break_63",
   "status",
   "inter_company_invoice_reference",
+  "is_internal_supplier",
   "remarks",
   "subscription_section",
   "from_date",
@@ -418,7 +419,6 @@
    "fieldname": "contact_email",
    "fieldtype": "Small Text",
    "label": "Contact Email",
-   "options": "Email",
    "print_hide": 1,
    "read_only": 1
   },
@@ -1284,6 +1284,14 @@
   {
    "fieldname": "dimension_col_break",
    "fieldtype": "Column Break"
+  },
+  {
+   "default": "0",
+   "fetch_from": "supplier.is_internal_supplier",
+   "fieldname": "is_internal_supplier",
+   "fieldtype": "Check",
+   "label": "Is Internal Supplier",
+   "read_only": 1
   }
  ],
  "icon": "fa fa-file-text",
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index 4002d7e..a68c368 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -224,7 +224,7 @@
 		for item in self.get("items"):
 			# in case of auto inventory accounting,
 			# expense account is always "Stock Received But Not Billed" for a stock item
-			# except epening entry, drop-ship entry and fixed asset items
+			# except opening entry, drop-ship entry and fixed asset items
 			if item.item_code:
 				asset_category = frappe.get_cached_value("Item", item.item_code, "asset_category")
 
@@ -233,10 +233,22 @@
 				and (not item.po_detail or
 					not frappe.db.get_value("Purchase Order Item", item.po_detail, "delivered_by_supplier")):
 
-				if self.update_stock:
+				if self.update_stock and (not item.from_warehouse):
 					item.expense_account = warehouse_account[item.warehouse]["account"]
 				else:
-					item.expense_account = stock_not_billed_account
+					# check if 'Stock Received But Not Billed' account is credited in Purchase receipt or not
+					if item.purchase_receipt:
+						negative_expense_booked_in_pr = frappe.db.sql("""select name from `tabGL Entry`
+							where voucher_type='Purchase Receipt' and voucher_no=%s and account = %s""",
+							(item.purchase_receipt, stock_not_billed_account))
+
+						if negative_expense_booked_in_pr:
+							item.expense_account = stock_not_billed_account
+					else:
+						# If no purchase receipt present then book expense in 'Stock Received But Not Billed'
+						# This is done in cases when Purchase Invoice is created before Purchase Receipt
+						item.expense_account = stock_not_billed_account
+
 			elif item.is_fixed_asset and not is_cwip_accounting_enabled(asset_category):
 				item.expense_account = get_asset_category_account('fixed_asset_account', item=item.item_code,
 					company = self.company)
@@ -467,16 +479,47 @@
 					warehouse_debit_amount = self.make_stock_adjustment_entry(gl_entries,
 						item, voucher_wise_stock_value, account_currency)
 
-					gl_entries.append(
-						self.get_gl_dict({
-							"account": item.expense_account,
-							"against": self.supplier,
-							"debit": warehouse_debit_amount,
-							"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
+					if item.from_warehouse:
+
+						gl_entries.append(self.get_gl_dict({
+							"account":  warehouse_account[item.warehouse]['account'],
+							"against": warehouse_account[item.from_warehouse]["account"],
 							"cost_center": item.cost_center,
-							"project": item.project
-						}, account_currency, item=item)
-					)
+							"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
+							"debit": warehouse_debit_amount,
+						}, warehouse_account[item.warehouse]["account_currency"], item=item))
+
+						# Intentionally passed negative debit amount to avoid incorrect GL Entry validation
+						gl_entries.append(self.get_gl_dict({
+							"account":  warehouse_account[item.from_warehouse]['account'],
+							"against": warehouse_account[item.warehouse]["account"],
+							"cost_center": item.cost_center,
+							"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
+							"debit": -1 * flt(item.base_net_amount, item.precision("base_net_amount")),
+						}, warehouse_account[item.from_warehouse]["account_currency"], item=item))
+
+						gl_entries.append(
+							self.get_gl_dict({
+								"account": item.expense_account,
+								"against": self.supplier,
+								"debit": flt(item.base_net_amount, item.precision("base_net_amount")),
+								"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
+								"cost_center": item.cost_center,
+								"project": item.project
+							}, account_currency, item=item)
+						)
+
+					else:
+						gl_entries.append(
+							self.get_gl_dict({
+								"account": item.expense_account,
+								"against": self.supplier,
+								"debit": warehouse_debit_amount,
+								"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
+								"cost_center": item.cost_center,
+								"project": item.project
+							}, account_currency, item=item)
+						)
 
 					# Amount added through landed-cost-voucher
 					if landed_cost_entries:
@@ -1015,7 +1058,7 @@
 
 
 @frappe.whitelist()
-def block_invoice(name, hold_comment, release_date):
+def block_invoice(name, release_date, hold_comment=None):
 	if frappe.db.exists('Purchase Invoice', name):
 		pi = frappe.get_doc('Purchase Invoice', name)
 		pi.block_invoice(hold_comment, release_date)
diff --git a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
index acb0398..28208ce 100644
--- a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
+++ b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
@@ -63,6 +63,7 @@
   "warehouse_section",
   "warehouse",
   "rejected_warehouse",
+  "from_warehouse",
   "quality_inspection",
   "batch_no",
   "col_br_wh",
@@ -762,16 +763,22 @@
    "fetch_from": "item_code.asset_category",
    "fieldname": "asset_category",
    "fieldtype": "Data",
-   "in_preview": 1,
    "label": "Asset Category",
    "options": "Asset Category",
    "read_only": 1
+  },
+  {
+   "fieldname": "from_warehouse",
+   "fieldtype": "Link",
+   "ignore_user_permissions": 1,
+   "label": "Supplier Warehouse",
+   "options": "Warehouse"
   }
  ],
  "idx": 1,
  "istable": 1,
  "links": [],
- "modified": "2019-12-04 12:23:17.046413",
+ "modified": "2020-01-13 16:04:14.200462",
  "modified_by": "Administrator",
  "module": "Accounts",
  "name": "Purchase Invoice Item",
diff --git a/erpnext/accounts/doctype/sales_invoice/pos.py b/erpnext/accounts/doctype/sales_invoice/pos.py
index a48d224..749816f 100755
--- a/erpnext/accounts/doctype/sales_invoice/pos.py
+++ b/erpnext/accounts/doctype/sales_invoice/pos.py
@@ -152,8 +152,11 @@
 
 
 def get_mode_of_payment(doc):
-	return frappe.db.sql(""" select mpa.default_account, mpa.parent, mp.type as type from `tabMode of Payment Account` mpa, \
-			`tabMode of Payment` mp where mpa.parent = mp.name and mpa.company = %(company)s""", {'company': doc.company}, as_dict=1)
+	return frappe.db.sql("""
+		select mpa.default_account, mpa.parent, mp.type as type 
+		from `tabMode of Payment Account` mpa,`tabMode of Payment` mp 
+		where mpa.parent = mp.name and mpa.company = %(company)s and mp.enabled = 1""",
+	{'company': doc.company}, as_dict=1)
 
 
 def update_tax_table(doc):
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
index 52a0f4e..e239f91 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
@@ -153,6 +153,7 @@
   "select_print_heading",
   "more_information",
   "inter_company_invoice_reference",
+  "is_internal_customer",
   "customer_group",
   "campaign",
   "is_discounted",
@@ -1563,6 +1564,14 @@
   {
    "fieldname": "dimension_col_break",
    "fieldtype": "Column Break"
+  },
+  {
+   "default": "0",
+   "fetch_from": "customer.is_internal_customer",
+   "fieldname": "is_internal_customer",
+   "fieldtype": "Check",
+   "label": "Is Internal Customer",
+   "read_only": 1
   }
  ],
  "icon": "fa fa-file-text",
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index d8344ea..ad3640c 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -1243,25 +1243,28 @@
 
 		precision = self.precision("outstanding_amount")
 		outstanding_amount = flt(self.outstanding_amount, precision)
+		due_date = getdate(self.due_date)
+		nowdate = getdate()
+		discountng_status = self.get_discounting_status()
 
 		if not status:
 			if self.docstatus == 2:
 				status = "Cancelled"
 			elif self.docstatus == 1:
-				if outstanding_amount > 0 and getdate(self.due_date) < getdate(nowdate()) and self.is_discounted and self.get_discounting_status()=='Disbursed':
+				if outstanding_amount > 0 and due_date < nowdate and self.is_discounted and discountng_status=='Disbursed':
 					self.status = "Overdue and Discounted"
-				elif outstanding_amount > 0 and getdate(self.due_date) < getdate(nowdate()):
+				elif outstanding_amount > 0 and due_date < nowdate:
 					self.status = "Overdue"
-				elif outstanding_amount > 0 and getdate(self.due_date) >= getdate(nowdate()) and self.is_discounted and self.get_discounting_status()=='Disbursed':
+				elif outstanding_amount > 0 and due_date >= nowdate and self.is_discounted and discountng_status=='Disbursed':
 					self.status = "Unpaid and Discounted"
-				elif outstanding_amount > 0 and getdate(self.due_date) >= getdate(nowdate()):
+				elif outstanding_amount > 0 and due_date >= nowdate:
 					self.status = "Unpaid"
 				#Check if outstanding amount is 0 due to credit note issued against invoice
 				elif outstanding_amount <= 0 and self.is_return == 0 and frappe.db.get_value('Sales Invoice', {'is_return': 1, 'return_against': self.name, 'docstatus': 1}):
 					self.status = "Credit Note Issued"
 				elif self.is_return == 1:
 					self.status = "Return"
-				elif outstanding_amount <=0:
+				elif outstanding_amount<=0:
 					self.status = "Paid"
 				else:
 					self.status = "Submitted"
@@ -1426,23 +1429,42 @@
 			data.account = get_bank_cash_account(data.mode_of_payment, self.company).get("account")
 
 def get_inter_company_details(doc, doctype):
-	if doctype in ["Sales Invoice", "Sales Order"]:
-		party = frappe.db.get_value("Supplier", {"disabled": 0, "is_internal_supplier": 1, "represents_company": doc.company}, "name")
+	if doctype in ["Sales Invoice", "Sales Order", "Delivery Note"]:
+		parties = frappe.db.get_all("Supplier", fields=["name"], filters={"disabled": 0, "is_internal_supplier": 1, "represents_company": doc.company})
 		company = frappe.get_cached_value("Customer", doc.customer, "represents_company")
+
+		party = get_internal_party(parties, "Supplier", doc)
 	else:
-		party = frappe.db.get_value("Customer", {"disabled": 0, "is_internal_customer": 1, "represents_company": doc.company}, "name")
+		parties = frappe.db.get_all("Customer", fields=["name"], filters={"disabled": 0, "is_internal_customer": 1, "represents_company": doc.company})
 		company = frappe.get_cached_value("Supplier", doc.supplier, "represents_company")
 
+		party = get_internal_party(parties, "Customer", doc)
+
 	return {
 		"party": party,
 		"company": company
 	}
 
+def get_internal_party(parties, link_doctype, doc):
+	if len(parties) == 1:
+			party = parties[0].name
+	else:
+		# If more than one Internal Supplier/Customer, get supplier/customer on basis of address
+		if doc.get('company_address') or doc.get('shipping_address'):
+			party = frappe.db.get_value("Dynamic Link", {"parent": doc.get('company_address') or doc.get('shipping_address'),
+			"parenttype": "Address", "link_doctype": link_doctype}, "link_name")
+
+			if not party:
+				party = parties[0].name
+		else:
+			party = parties[0].name
+
+	return party
 
 def validate_inter_company_transaction(doc, doctype):
 
 	details = get_inter_company_details(doc, doctype)
-	price_list = doc.selling_price_list if doctype in ["Sales Invoice", "Sales Order"] else doc.buying_price_list
+	price_list = doc.selling_price_list if doctype in ["Sales Invoice", "Sales Order", "Delivery Note"] else doc.buying_price_list
 	valid_price_list = frappe.db.get_value("Price List", {"name": price_list, "buying": 1, "selling": 1})
 	if not valid_price_list:
 		frappe.throw(_("Selected Price List should have buying and selling fields checked."))
diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py
index 156f218..422ace6 100644
--- a/erpnext/accounts/party.py
+++ b/erpnext/accounts/party.py
@@ -35,8 +35,7 @@
 
 def _get_party_details(party=None, account=None, party_type="Customer", company=None, posting_date=None,
 	bill_date=None, price_list=None, currency=None, doctype=None, ignore_permissions=False,
-	fetch_payment_terms_template=True, party_address=None, company_address=None,shipping_address=None, pos_profile=None):
-
+	fetch_payment_terms_template=True, party_address=None, company_address=None, shipping_address=None, pos_profile=None):
 	party_details = frappe._dict(set_account_and_due_date(party, account, party_type, company, posting_date, bill_date, doctype))
 	party = party_details[party_type.lower()]
 
diff --git a/erpnext/accounts/report/accounts_payable/accounts_payable.js b/erpnext/accounts/report/accounts_payable/accounts_payable.js
index b1f427c..df700ec 100644
--- a/erpnext/accounts/report/accounts_payable/accounts_payable.js
+++ b/erpnext/accounts/report/accounts_payable/accounts_payable.js
@@ -101,6 +101,11 @@
 			"options": "Supplier Group"
 		},
 		{
+			"fieldname": "group_by_party",
+			"label": __("Group By Supplier"),
+			"fieldtype": "Check"
+		},
+		{
 			"fieldname":"based_on_payment_terms",
 			"label": __("Based On Payment Terms"),
 			"fieldtype": "Check",
@@ -112,6 +117,16 @@
 			"hidden": 1
 		}
 	],
+
+	"formatter": function(value, row, column, data, default_formatter) {
+		value = default_formatter(value, row, column, data);
+		if (data && data.bold) {
+			value = value.bold();
+
+		}
+		return value;
+	},
+
 	onload: function(report) {
 		report.page.add_inner_button(__("Accounts Payable Summary"), function() {
 			var filters = report.get_values();
diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.js b/erpnext/accounts/report/accounts_receivable/accounts_receivable.js
index 9b4dda2..5d0154f 100644
--- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.js
+++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.js
@@ -87,7 +87,7 @@
 						frappe.query_report.set_filter_value('payment_terms', value["payment_terms"]);
 					});
 
-					frappe.db.get_value('Customer Credit Limit', {'parent': customer, 'company': company}, 
+					frappe.db.get_value('Customer Credit Limit', {'parent': customer, 'company': company},
 						["credit_limit"], function(value) {
 						if (value) {
 							frappe.query_report.set_filter_value('credit_limit', value["credit_limit"]);
@@ -132,6 +132,11 @@
 			"options": "Sales Person"
 		},
 		{
+			"fieldname": "group_by_party",
+			"label": __("Group By Customer"),
+			"fieldtype": "Check"
+		},
+		{
 			"fieldname":"based_on_payment_terms",
 			"label": __("Based On Payment Terms"),
 			"fieldtype": "Check",
@@ -177,6 +182,15 @@
 		}
 	],
 
+	"formatter": function(value, row, column, data, default_formatter) {
+		value = default_formatter(value, row, column, data);
+		if (data && data.bold) {
+			value = value.bold();
+
+		}
+		return value;
+	},
+
 	onload: function(report) {
 		report.page.add_inner_button(__("Accounts Receivable Summary"), function() {
 			var filters = report.get_values();
diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
index f82146a..0438f6d 100755
--- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
+++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
@@ -46,7 +46,7 @@
 		self.get_columns()
 		self.get_data()
 		self.get_chart_data()
-		return self.columns, self.data, None, self.chart
+		return self.columns, self.data, None, self.chart, None, self.skip_total_row
 
 	def set_defaults(self):
 		if not self.filters.get("company"):
@@ -57,6 +57,12 @@
 		self.party_type = self.filters.party_type
 		self.party_details = {}
 		self.invoices = set()
+		self.skip_total_row = 0
+
+		if self.filters.get('group_by_party'):
+			self.previous_party=''
+			self.total_row_map = {}
+			self.skip_total_row = 1
 
 	def get_data(self):
 		self.get_gl_entries()
@@ -102,6 +108,12 @@
 				)
 			self.get_invoices(gle)
 
+			if self.filters.get('group_by_party'):
+				self.init_subtotal_row(gle.party)
+
+		if self.filters.get('group_by_party'):
+			self.init_subtotal_row('Total')
+
 	def get_invoices(self, gle):
 		if gle.voucher_type in ('Sales Invoice', 'Purchase Invoice'):
 			if self.filters.get("sales_person"):
@@ -111,6 +123,20 @@
 			else:
 				self.invoices.add(gle.voucher_no)
 
+	def init_subtotal_row(self, party):
+		if not self.total_row_map.get(party):
+			self.total_row_map.setdefault(party, {
+				'party': party,
+				'bold': 1
+			})
+
+			for field in self.get_currency_fields():
+				self.total_row_map[party][field] = 0.0
+
+	def get_currency_fields(self):
+		return ['invoiced', 'paid', 'credit_note', 'outstanding', 'range1',
+			'range2', 'range3', 'range4', 'range5']
+
 	def update_voucher_balance(self, gle):
 		# get the row where this balance needs to be updated
 		# if its a payment, it will return the linked invoice or will be considered as advance
@@ -135,6 +161,18 @@
 				# advance / unlinked payment or other adjustment
 				row.paid -= gle_balance
 
+	def update_sub_total_row(self, row, party):
+		total_row = self.total_row_map.get(party)
+
+		for field in self.get_currency_fields():
+			total_row[field] += row.get(field, 0.0)
+
+	def append_subtotal_row(self, party):
+		sub_total_row = self.total_row_map.get(party)
+		self.data.append(sub_total_row)
+		self.data.append({})
+		self.update_sub_total_row(sub_total_row, 'Total')
+
 	def get_voucher_balance(self, gle):
 		if self.filters.get("sales_person"):
 			against_voucher = gle.against_voucher or gle.voucher_no
@@ -192,11 +230,22 @@
 				else:
 					self.append_row(row)
 
+		if self.filters.get('group_by_party'):
+			self.append_subtotal_row(self.previous_party)
+			self.data.append(self.total_row_map.get('Total'))
+
 	def append_row(self, row):
 		self.allocate_future_payments(row)
 		self.set_invoice_details(row)
 		self.set_party_details(row)
 		self.set_ageing(row)
+
+		if self.filters.get('group_by_party'):
+			self.update_sub_total_row(row, row.party)
+			if self.previous_party and (self.previous_party != row.party):
+				self.append_subtotal_row(self.previous_party)
+			self.previous_party = row.party
+
 		self.data.append(row)
 
 	def set_invoice_details(self, row):
@@ -503,6 +552,7 @@
 		# get all the GL entries filtered by the given filters
 
 		conditions, values = self.prepare_conditions()
+		order_by = self.get_order_by_condition()
 
 		if self.filters.get(scrub(self.party_type)):
 			select_fields = "debit_in_account_currency as debit, credit_in_account_currency as credit"
@@ -520,9 +570,8 @@
 				and party_type=%s
 				and (party is not null and party != '')
 				and posting_date <= %s
-				{1}
-			order by posting_date, party"""
-			.format(select_fields, conditions), values, as_dict=True)
+				{1} {2}"""
+			.format(select_fields, conditions, order_by), values, as_dict=True)
 
 	def get_sales_invoices_or_customers_based_on_sales_person(self):
 		if self.filters.get("sales_person"):
@@ -557,6 +606,12 @@
 
 		return " and ".join(conditions), values
 
+	def get_order_by_condition(self):
+		if self.filters.get('group_by_party'):
+			return "order by party, posting_date"
+		else:
+			return "order by posting_date, party"
+
 	def add_common_filters(self, conditions, values, party_type_field):
 		if self.filters.company:
 			conditions.append("company=%s")
@@ -736,11 +791,13 @@
 	def get_chart_data(self):
 		rows = []
 		for row in self.data:
-			values = [row.range1, row.range2, row.range3, row.range4, row.range5]
-			precision = cint(frappe.db.get_default("float_precision")) or 2
-			rows.append({
-				'values': [flt(val, precision) for val in values]
-			})
+			row = frappe._dict(row)
+			if not cint(row.bold):
+				values = [row.range1, row.range2, row.range3, row.range4, row.range5]
+				precision = cint(frappe.db.get_default("float_precision")) or 2
+				rows.append({
+					'values': [flt(val, precision) for val in values]
+				})
 
 		self.chart = {
 			"data": {
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js
index 7b1f135..a3264a4 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.js
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.js
@@ -180,10 +180,20 @@
 	get_items_from_open_material_requests: function() {
 		erpnext.utils.map_current_doc({
 			method: "erpnext.stock.doctype.material_request.material_request.make_purchase_order_based_on_supplier",
+			args: {
+				supplier: this.frm.doc.supplier
+			},
+			source_doctype: "Material Request",
 			source_name: this.frm.doc.supplier,
+			target: this.frm,
+			setters: {
+				company: me.frm.doc.company
+			},
 			get_query_filters: {
 				docstatus: ["!=", 2],
-			}
+				supplier: this.frm.doc.supplier
+			},
+			get_query_method: "erpnext.stock.doctype.material_request.material_request.get_material_requests_based_on_supplier"
 		});
 	},
 
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.json b/erpnext/buying/doctype/purchase_order/purchase_order.json
index d82e128..4d83690 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.json
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.json
@@ -12,8 +12,8 @@
   "supplier",
   "get_items_from_open_material_requests",
   "supplier_name",
-  "company",
   "column_break1",
+  "company",
   "transaction_date",
   "schedule_date",
   "order_confirmation_no",
@@ -170,6 +170,7 @@
    "search_index": 1
   },
   {
+   "description": "Fetch items based on Default Supplier.",
    "depends_on": "eval:doc.supplier && doc.docstatus===0 && (!(doc.items && doc.items.length) || (doc.items.length==1 && !doc.items[0].item_code))",
    "fieldname": "get_items_from_open_material_requests",
    "fieldtype": "Button",
diff --git a/erpnext/buying/doctype/supplier/supplier.json b/erpnext/buying/doctype/supplier/supplier.json
index b5f0366..1ab171a 100644
--- a/erpnext/buying/doctype/supplier/supplier.json
+++ b/erpnext/buying/doctype/supplier/supplier.json
@@ -1,1683 +1,439 @@
 {
- "allow_copy": 0, 
- "allow_events_in_timeline": 1, 
- "allow_guest_to_view": 0, 
- "allow_import": 1, 
- "allow_rename": 1, 
- "autoname": "naming_series:", 
- "beta": 0, 
- "creation": "2013-01-10 16:34:11", 
- "custom": 0, 
- "description": "Supplier of Goods or Services.", 
- "docstatus": 0, 
- "doctype": "DocType", 
- "document_type": "Setup", 
- "editable_grid": 0, 
- "engine": "InnoDB", 
+ "actions": [],
+ "allow_events_in_timeline": 1,
+ "allow_import": 1,
+ "allow_rename": 1,
+ "autoname": "naming_series:",
+ "creation": "2013-01-10 16:34:11",
+ "description": "Supplier of Goods or Services.",
+ "doctype": "DocType",
+ "document_type": "Setup",
+ "engine": "InnoDB",
+ "field_order": [
+  "basic_info",
+  "naming_series",
+  "supplier_name",
+  "country",
+  "default_bank_account",
+  "tax_id",
+  "tax_category",
+  "tax_withholding_category",
+  "is_transporter",
+  "is_internal_supplier",
+  "represents_company",
+  "image",
+  "column_break0",
+  "supplier_group",
+  "supplier_type",
+  "pan",
+  "language",
+  "disabled",
+  "warn_rfqs",
+  "warn_pos",
+  "prevent_rfqs",
+  "prevent_pos",
+  "allowed_to_transact_section",
+  "companies",
+  "section_break_7",
+  "default_currency",
+  "column_break_10",
+  "default_price_list",
+  "section_credit_limit",
+  "payment_terms",
+  "cb_21",
+  "on_hold",
+  "hold_type",
+  "release_date",
+  "address_contacts",
+  "address_html",
+  "column_break1",
+  "contact_html",
+  "default_payable_accounts",
+  "accounts",
+  "default_tax_withholding_config",
+  "column_break2",
+  "website",
+  "supplier_details",
+  "column_break_30",
+  "is_frozen"
+ ],
  "fields": [
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "basic_info", 
-   "fieldtype": "Section Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Name and Type", 
-   "length": 0, 
-   "no_copy": 0, 
-   "oldfieldtype": "Section Break", 
-   "options": "fa fa-user", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "basic_info",
+   "fieldtype": "Section Break",
+   "label": "Name and Type",
+   "oldfieldtype": "Section Break",
+   "options": "fa fa-user"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "default": "", 
-   "fieldname": "naming_series", 
-   "fieldtype": "Select", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Series", 
-   "length": 0, 
-   "no_copy": 1, 
-   "oldfieldname": "naming_series", 
-   "oldfieldtype": "Select", 
-   "options": "SUP-.YYYY.-", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 1, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "naming_series",
+   "fieldtype": "Select",
+   "label": "Series",
+   "no_copy": 1,
+   "oldfieldname": "naming_series",
+   "oldfieldtype": "Select",
+   "options": "SUP-.YYYY.-",
+   "set_only_once": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 1, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "supplier_name", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 1, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Supplier Name", 
-   "length": 0, 
-   "no_copy": 1, 
-   "oldfieldname": "supplier_name", 
-   "oldfieldtype": "Data", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "bold": 1,
+   "fieldname": "supplier_name",
+   "fieldtype": "Data",
+   "in_global_search": 1,
+   "label": "Supplier Name",
+   "no_copy": 1,
+   "oldfieldname": "supplier_name",
+   "oldfieldtype": "Data",
+   "reqd": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "country", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Country", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Country", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "country",
+   "fieldtype": "Link",
+   "label": "Country",
+   "options": "Country"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "default_bank_account", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Default Bank Account", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Bank Account", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "default_bank_account",
+   "fieldtype": "Link",
+   "label": "Default Bank Account",
+   "options": "Bank Account"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "tax_id", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Tax ID", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "tax_id",
+   "fieldtype": "Data",
+   "label": "Tax ID"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "tax_category", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Tax Category", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Tax Category", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "tax_category",
+   "fieldtype": "Link",
+   "label": "Tax Category",
+   "options": "Tax Category"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "tax_withholding_category", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Tax Withholding Category", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Tax Withholding Category", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "tax_withholding_category",
+   "fieldtype": "Link",
+   "label": "Tax Withholding Category",
+   "options": "Tax Withholding Category"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "is_transporter", 
-   "fieldtype": "Check", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Is Transporter", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "default": "0",
+   "fieldname": "is_transporter",
+   "fieldtype": "Check",
+   "label": "Is Transporter"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "default": "0", 
-   "fieldname": "is_internal_supplier", 
-   "fieldtype": "Check", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Is Internal Supplier", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "default": "0",
+   "fieldname": "is_internal_supplier",
+   "fieldtype": "Check",
+   "label": "Is Internal Supplier"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "is_internal_supplier", 
-   "fieldname": "represents_company", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 1, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Represents Company", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Company", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 1
-  }, 
+   "depends_on": "is_internal_supplier",
+   "fieldname": "represents_company",
+   "fieldtype": "Link",
+   "ignore_user_permissions": 1,
+   "label": "Represents Company",
+   "options": "Company"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "image", 
-   "fieldtype": "Attach Image", 
-   "hidden": 1, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Image", 
-   "length": 0, 
-   "no_copy": 1, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 1, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "image",
+   "fieldtype": "Attach Image",
+   "hidden": 1,
+   "label": "Image",
+   "no_copy": 1,
+   "print_hide": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "column_break0", 
-   "fieldtype": "Column Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0, 
+   "fieldname": "column_break0",
+   "fieldtype": "Column Break",
    "width": "50%"
-  }, 
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "supplier_group", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 1, 
-   "in_standard_filter": 1, 
-   "label": "Supplier Group", 
-   "length": 0, 
-   "no_copy": 0, 
-   "oldfieldname": "supplier_type", 
-   "oldfieldtype": "Link", 
-   "options": "Supplier Group", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "supplier_group",
+   "fieldtype": "Link",
+   "in_list_view": 1,
+   "in_standard_filter": 1,
+   "label": "Supplier Group",
+   "oldfieldname": "supplier_type",
+   "oldfieldtype": "Link",
+   "options": "Supplier Group",
+   "reqd": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "default": "Company", 
-   "fieldname": "supplier_type", 
-   "fieldtype": "Select", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Supplier Type", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Company\nIndividual", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "default": "Company",
+   "fieldname": "supplier_type",
+   "fieldtype": "Select",
+   "label": "Supplier Type",
+   "options": "Company\nIndividual",
+   "reqd": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "pan", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "PAN", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "pan",
+   "fieldtype": "Data",
+   "label": "PAN"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "language", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Print Language", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Language", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "language",
+   "fieldtype": "Link",
+   "label": "Print Language",
+   "options": "Language"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 1, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "default": "0", 
-   "fieldname": "disabled", 
-   "fieldtype": "Check", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Disabled", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "bold": 1,
+   "default": "0",
+   "fieldname": "disabled",
+   "fieldtype": "Check",
+   "label": "Disabled"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "warn_rfqs", 
-   "fieldtype": "Check", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Warn RFQs", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 1, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "default": "0",
+   "fieldname": "warn_rfqs",
+   "fieldtype": "Check",
+   "label": "Warn RFQs",
+   "read_only": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "warn_pos", 
-   "fieldtype": "Check", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Warn POs", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 1, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "default": "0",
+   "fieldname": "warn_pos",
+   "fieldtype": "Check",
+   "label": "Warn POs",
+   "read_only": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "prevent_rfqs", 
-   "fieldtype": "Check", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Prevent RFQs", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 1, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "default": "0",
+   "fieldname": "prevent_rfqs",
+   "fieldtype": "Check",
+   "label": "Prevent RFQs",
+   "read_only": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "prevent_pos", 
-   "fieldtype": "Check", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Prevent POs", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 1, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "default": "0",
+   "fieldname": "prevent_pos",
+   "fieldtype": "Check",
+   "label": "Prevent POs",
+   "read_only": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "represents_company", 
-   "fieldname": "allowed_to_transact_section", 
-   "fieldtype": "Section Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Allowed To Transact With", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "depends_on": "represents_company",
+   "fieldname": "allowed_to_transact_section",
+   "fieldtype": "Section Break",
+   "label": "Allowed To Transact With"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "represents_company", 
-   "fieldname": "companies", 
-   "fieldtype": "Table", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Allowed To Transact With", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Allowed To Transact With", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "depends_on": "represents_company",
+   "fieldname": "companies",
+   "fieldtype": "Table",
+   "label": "Allowed To Transact With",
+   "options": "Allowed To Transact With"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 1, 
-   "columns": 0, 
-   "fieldname": "section_break_7", 
-   "fieldtype": "Section Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Currency and Price List", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "collapsible": 1,
+   "fieldname": "section_break_7",
+   "fieldtype": "Section Break",
+   "label": "Currency and Price List"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "default_currency", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 1, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Billing Currency", 
-   "length": 0, 
-   "no_copy": 1, 
-   "options": "Currency", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "default_currency",
+   "fieldtype": "Link",
+   "ignore_user_permissions": 1,
+   "label": "Billing Currency",
+   "no_copy": 1,
+   "options": "Currency"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "column_break_10", 
-   "fieldtype": "Column Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "column_break_10",
+   "fieldtype": "Column Break"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "default_price_list", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 1, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Price List", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Price List", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "default_price_list",
+   "fieldtype": "Link",
+   "ignore_user_permissions": 1,
+   "label": "Price List",
+   "options": "Price List"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 1, 
-   "columns": 0, 
-   "fieldname": "section_credit_limit", 
-   "fieldtype": "Section Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Credit Limit", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "collapsible": 1,
+   "fieldname": "section_credit_limit",
+   "fieldtype": "Section Break",
+   "label": "Credit Limit"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "", 
-   "fieldname": "payment_terms", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Default Payment Terms Template", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Payment Terms Template", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "payment_terms",
+   "fieldtype": "Link",
+   "label": "Default Payment Terms Template",
+   "options": "Payment Terms Template"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "cb_21", 
-   "fieldtype": "Column Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "cb_21",
+   "fieldtype": "Column Break"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "default": "0", 
-   "fieldname": "on_hold", 
-   "fieldtype": "Check", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Block Supplier", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "default": "0",
+   "fieldname": "on_hold",
+   "fieldtype": "Check",
+   "label": "Block Supplier"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:doc.on_hold", 
-   "fieldname": "hold_type", 
-   "fieldtype": "Select", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Hold Type", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "\nAll\nInvoices\nPayments", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "depends_on": "eval:doc.on_hold",
+   "fieldname": "hold_type",
+   "fieldtype": "Select",
+   "label": "Hold Type",
+   "options": "\nAll\nInvoices\nPayments"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:doc.on_hold", 
-   "description": "Leave blank if the Supplier is blocked indefinitely", 
-   "fieldname": "release_date", 
-   "fieldtype": "Date", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Release Date", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "depends_on": "eval:doc.on_hold",
+   "description": "Leave blank if the Supplier is blocked indefinitely",
+   "fieldname": "release_date",
+   "fieldtype": "Date",
+   "label": "Release Date"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:!doc.__islocal", 
-   "fieldname": "address_contacts", 
-   "fieldtype": "Section Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Address and Contacts", 
-   "length": 0, 
-   "no_copy": 0, 
-   "oldfieldtype": "Column Break", 
-   "options": "fa fa-map-marker", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "depends_on": "eval:!doc.__islocal",
+   "fieldname": "address_contacts",
+   "fieldtype": "Section Break",
+   "label": "Address and Contacts",
+   "oldfieldtype": "Column Break",
+   "options": "fa fa-map-marker"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "address_html", 
-   "fieldtype": "HTML", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Address HTML", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 1, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "address_html",
+   "fieldtype": "HTML",
+   "label": "Address HTML",
+   "read_only": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "column_break1", 
-   "fieldtype": "Column Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0, 
+   "fieldname": "column_break1",
+   "fieldtype": "Column Break",
    "width": "50%"
-  }, 
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "contact_html", 
-   "fieldtype": "HTML", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Contact HTML", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 1, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "contact_html",
+   "fieldtype": "HTML",
+   "label": "Contact HTML",
+   "read_only": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 1, 
-   "collapsible_depends_on": "accounts", 
-   "columns": 0, 
-   "fieldname": "default_payable_accounts", 
-   "fieldtype": "Section Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Default Payable Accounts", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "collapsible": 1,
+   "collapsible_depends_on": "accounts",
+   "fieldname": "default_payable_accounts",
+   "fieldtype": "Section Break",
+   "label": "Default Payable Accounts"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "", 
-   "description": "Mention if non-standard payable account", 
-   "fieldname": "accounts", 
-   "fieldtype": "Table", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Accounts", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Party Account", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "description": "Mention if non-standard payable account",
+   "fieldname": "accounts",
+   "fieldtype": "Table",
+   "label": "Accounts",
+   "options": "Party Account"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 1, 
-   "columns": 0, 
-   "fieldname": "default_tax_withholding_config", 
-   "fieldtype": "Section Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Default Tax Withholding Config", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "collapsible": 1,
+   "fieldname": "default_tax_withholding_config",
+   "fieldtype": "Section Break",
+   "label": "Default Tax Withholding Config"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 1, 
-   "collapsible_depends_on": "supplier_details", 
-   "columns": 0, 
-   "fieldname": "column_break2", 
-   "fieldtype": "Section Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "More Information", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0, 
+   "collapsible": 1,
+   "collapsible_depends_on": "supplier_details",
+   "fieldname": "column_break2",
+   "fieldtype": "Section Break",
+   "label": "More Information",
    "width": "50%"
-  }, 
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "website", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Website", 
-   "length": 0, 
-   "no_copy": 0, 
-   "oldfieldname": "website", 
-   "oldfieldtype": "Data", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "website",
+   "fieldtype": "Data",
+   "label": "Website",
+   "oldfieldname": "website",
+   "oldfieldtype": "Data"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "description": "Statutory info and other general information about your Supplier", 
-   "fieldname": "supplier_details", 
-   "fieldtype": "Text", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Supplier Details", 
-   "length": 0, 
-   "no_copy": 0, 
-   "oldfieldname": "supplier_details", 
-   "oldfieldtype": "Code", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "description": "Statutory info and other general information about your Supplier",
+   "fieldname": "supplier_details",
+   "fieldtype": "Text",
+   "label": "Supplier Details",
+   "oldfieldname": "supplier_details",
+   "oldfieldtype": "Code"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "column_break_30", 
-   "fieldtype": "Column Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "column_break_30",
+   "fieldtype": "Column Break"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "is_frozen", 
-   "fieldtype": "Check", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Is Frozen", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
+   "default": "0",
+   "fieldname": "is_frozen",
+   "fieldtype": "Check",
+   "label": "Is Frozen"
   }
- ], 
- "has_web_view": 0, 
- "hide_heading": 0, 
- "hide_toolbar": 0, 
- "icon": "fa fa-user", 
- "idx": 370, 
- "image_field": "image", 
- "image_view": 0, 
- "in_create": 0, 
- "is_submittable": 0, 
- "issingle": 0, 
- "istable": 0, 
- "max_attachments": 0, 
- "modified": "2019-01-17 13:58:08.597793", 
- "modified_by": "Administrator", 
- "module": "Buying", 
- "name": "Supplier", 
- "name_case": "Title Case", 
- "owner": "Administrator", 
+ ],
+ "icon": "fa fa-user",
+ "idx": 370,
+ "image_field": "image",
+ "links": [],
+ "modified": "2019-12-19 18:17:16.614567",
+ "modified_by": "Administrator",
+ "module": "Buying",
+ "name": "Supplier",
+ "name_case": "Title Case",
+ "owner": "Administrator",
  "permissions": [
   {
-   "amend": 0, 
-   "cancel": 0, 
-   "create": 0, 
-   "delete": 0, 
-   "email": 1, 
-   "export": 0, 
-   "if_owner": 0, 
-   "import": 0, 
-   "permlevel": 0, 
-   "print": 1, 
-   "read": 1, 
-   "report": 1, 
-   "role": "Purchase User", 
-   "set_user_permissions": 0, 
-   "share": 0, 
-   "submit": 0, 
-   "write": 0
-  }, 
+   "email": 1,
+   "print": 1,
+   "read": 1,
+   "report": 1,
+   "role": "Purchase User"
+  },
   {
-   "amend": 0, 
-   "cancel": 0, 
-   "create": 0, 
-   "delete": 0, 
-   "email": 1, 
-   "export": 0, 
-   "if_owner": 0, 
-   "import": 0, 
-   "permlevel": 0, 
-   "print": 1, 
-   "read": 1, 
-   "report": 1, 
-   "role": "Purchase Manager", 
-   "set_user_permissions": 0, 
-   "share": 0, 
-   "submit": 0, 
+   "email": 1,
+   "print": 1,
+   "read": 1,
+   "report": 1,
+   "role": "Purchase Manager",
    "write": 1
-  }, 
+  },
   {
-   "amend": 0, 
-   "cancel": 0, 
-   "create": 1, 
-   "delete": 1, 
-   "email": 1, 
-   "export": 1, 
-   "if_owner": 0, 
-   "import": 1, 
-   "permlevel": 0, 
-   "print": 1, 
-   "read": 1, 
-   "report": 1, 
-   "role": "Purchase Master Manager", 
-   "set_user_permissions": 1, 
-   "share": 1, 
-   "submit": 0, 
+   "create": 1,
+   "delete": 1,
+   "email": 1,
+   "export": 1,
+   "import": 1,
+   "print": 1,
+   "read": 1,
+   "report": 1,
+   "role": "Purchase Master Manager",
+   "set_user_permissions": 1,
+   "share": 1,
    "write": 1
-  }, 
+  },
   {
-   "amend": 0, 
-   "cancel": 0, 
-   "create": 0, 
-   "delete": 0, 
-   "email": 0, 
-   "export": 0, 
-   "if_owner": 0, 
-   "import": 0, 
-   "permlevel": 0, 
-   "print": 0, 
-   "read": 1, 
-   "report": 0, 
-   "role": "Stock User", 
-   "set_user_permissions": 0, 
-   "share": 0, 
-   "submit": 0, 
-   "write": 0
-  }, 
+   "read": 1,
+   "role": "Stock User"
+  },
   {
-   "amend": 0, 
-   "cancel": 0, 
-   "create": 0, 
-   "delete": 0, 
-   "email": 1, 
-   "export": 0, 
-   "if_owner": 0, 
-   "import": 0, 
-   "permlevel": 0, 
-   "print": 1, 
-   "read": 1, 
-   "report": 1, 
-   "role": "Stock Manager", 
-   "set_user_permissions": 0, 
-   "share": 0, 
-   "submit": 0, 
-   "write": 0
-  }, 
+   "email": 1,
+   "print": 1,
+   "read": 1,
+   "report": 1,
+   "role": "Stock Manager"
+  },
   {
-   "amend": 0, 
-   "cancel": 0, 
-   "create": 0, 
-   "delete": 0, 
-   "email": 0, 
-   "export": 0, 
-   "if_owner": 0, 
-   "import": 0, 
-   "permlevel": 0, 
-   "print": 0, 
-   "read": 1, 
-   "report": 0, 
-   "role": "Accounts User", 
-   "set_user_permissions": 0, 
-   "share": 0, 
-   "submit": 0, 
-   "write": 0
-  }, 
+   "read": 1,
+   "role": "Accounts User"
+  },
   {
-   "amend": 0, 
-   "cancel": 0, 
-   "create": 0, 
-   "delete": 0, 
-   "email": 1, 
-   "export": 0, 
-   "if_owner": 0, 
-   "import": 0, 
-   "permlevel": 0, 
-   "print": 1, 
-   "read": 1, 
-   "report": 1, 
-   "role": "Accounts Manager", 
-   "set_user_permissions": 0, 
-   "share": 0, 
-   "submit": 0, 
-   "write": 0
+   "email": 1,
+   "print": 1,
+   "read": 1,
+   "report": 1,
+   "role": "Accounts Manager"
   }
- ], 
- "quick_entry": 1, 
- "read_only": 0, 
- "read_only_onload": 0, 
- "search_fields": "supplier_name, supplier_group", 
- "show_name_in_global_search": 1, 
- "sort_order": "ASC", 
- "title_field": "supplier_name", 
- "track_changes": 1, 
- "track_seen": 0, 
- "track_views": 0
-}
+ ],
+ "quick_entry": 1,
+ "search_fields": "supplier_name, supplier_group",
+ "show_name_in_global_search": 1,
+ "sort_field": "modified",
+ "sort_order": "ASC",
+ "title_field": "supplier_name",
+ "track_changes": 1
+}
\ No newline at end of file
diff --git a/erpnext/buying/doctype/supplier/supplier.py b/erpnext/buying/doctype/supplier/supplier.py
index 62a04f3..df143ee 100644
--- a/erpnext/buying/doctype/supplier/supplier.py
+++ b/erpnext/buying/doctype/supplier/supplier.py
@@ -58,7 +58,9 @@
 			frappe.db.set(self, "supplier_name", newdn)
 
 	def create_onboarding_docs(self, args):
-		defaults = frappe.defaults.get_defaults()
+		company = frappe.defaults.get_defaults().get('company') or \
+			frappe.db.get_single_value('Global Defaults', 'default_company')
+
 		for i in range(1, args.get('max_count')):
 			supplier = args.get('supplier_name_' + str(i))
 			if supplier:
@@ -67,7 +69,7 @@
 						'doctype': self.doctype,
 						'supplier_name': supplier,
 						'supplier_group': _('Local'),
-						'company': defaults.get('company')
+						'company': company
 					}).insert()
 
 					if args.get('supplier_email_' + str(i)):
diff --git a/erpnext/buying/doctype/supplier/supplier_dashboard.py b/erpnext/buying/doctype/supplier/supplier_dashboard.py
index 887a093..b3b294d 100644
--- a/erpnext/buying/doctype/supplier/supplier_dashboard.py
+++ b/erpnext/buying/doctype/supplier/supplier_dashboard.py
@@ -9,7 +9,8 @@
 		'heatmap_message': _('This is based on transactions against this Supplier. See timeline below for details'),
 		'fieldname': 'supplier',
 		'non_standard_fieldnames': {
-			'Payment Entry': 'party_name'
+			'Payment Entry': 'party_name',
+			'Bank Account': 'party'
 		},
 		'transactions': [
 			{
@@ -25,6 +26,10 @@
 				'items': ['Payment Entry']
 			},
 			{
+				'label': _('Bank'),
+				'items': ['Bank Account']
+			},
+			{
 				'label': _('Pricing'),
 				'items': ['Pricing Rule']
 			}
diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py
index 69caabd..8d3db8d 100644
--- a/erpnext/controllers/buying_controller.py
+++ b/erpnext/controllers/buying_controller.py
@@ -43,6 +43,7 @@
 		self.set_qty_as_per_stock_uom()
 		self.validate_stock_or_nonstock_items()
 		self.validate_warehouse()
+		self.validate_from_warehouse()
 		self.set_supplier_address()
 
 		if self.doctype=="Purchase Invoice":
@@ -115,6 +116,14 @@
 			if not d.cost_center and lc_voucher_data and lc_voucher_data[0][1]:
 				d.db_set('cost_center', lc_voucher_data[0][1])
 
+	def validate_from_warehouse(self):
+		for item in self.get('items'):
+			if item.get('from_warehouse') and (item.get('from_warehouse') == item.get('warehouse')):
+				frappe.throw(_("Row #{0}: Accepted Warehouse and Supplier Warehouse cannot be same").format(item.idx))
+
+			if item.get('from_warehouse') and self.get('is_subcontracted') == 'Yes':
+				frappe.throw(_("Row #{0}: Cannot select Supplier Warehouse while suppling raw materials to subcontractor").format(item.idx))
+
 	def set_supplier_address(self):
 		address_dict = {
 			'supplier_address': 'address_display',
@@ -521,6 +530,16 @@
 				pr_qty = flt(d.qty) * flt(d.conversion_factor)
 
 				if pr_qty:
+
+					if d.from_warehouse and ((not cint(self.is_return) and self.docstatus==1)
+						or (cint(self.is_return) and self.docstatus==2)):
+						from_warehouse_sle = self.get_sl_entries(d, {
+							"actual_qty": -1 * pr_qty,
+							"warehouse": d.from_warehouse
+						})
+
+						sl_entries.append(from_warehouse_sle)
+
 					sle = self.get_sl_entries(d, {
 						"actual_qty": flt(pr_qty),
 						"serial_no": cstr(d.serial_no).strip()
@@ -541,6 +560,15 @@
 						})
 					sl_entries.append(sle)
 
+					if d.from_warehouse and ((not cint(self.is_return) and self.docstatus==2)
+						or (cint(self.is_return) and self.docstatus==1)):
+						from_warehouse_sle = self.get_sl_entries(d, {
+							"actual_qty": -1 * pr_qty,
+							"warehouse": d.from_warehouse
+						})
+
+						sl_entries.append(from_warehouse_sle)
+
 				if flt(d.rejected_qty) != 0:
 					sl_entries.append(self.get_sl_entries(d, {
 						"warehouse": d.rejected_warehouse,
diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py
index 9a9f3d1..2b21ee8 100644
--- a/erpnext/controllers/selling_controller.py
+++ b/erpnext/controllers/selling_controller.py
@@ -180,7 +180,7 @@
 
 			last_purchase_rate, is_stock_item = frappe.get_cached_value("Item", it.item_code, ["last_purchase_rate", "is_stock_item"])
 			last_purchase_rate_in_sales_uom = last_purchase_rate / (it.conversion_factor or 1)
-			if flt(it.base_rate) < flt(last_purchase_rate_in_sales_uom):
+			if flt(it.base_rate) < flt(last_purchase_rate_in_sales_uom) and not self.get('is_internal_customer'):
 				throw_message(it.item_name, last_purchase_rate_in_sales_uom, "last purchase rate")
 
 			last_valuation_rate = frappe.db.sql("""
@@ -190,7 +190,8 @@
 				""", (it.item_code, it.warehouse))
 			if last_valuation_rate:
 				last_valuation_rate_in_sales_uom = last_valuation_rate[0][0] / (it.conversion_factor or 1)
-				if is_stock_item and flt(it.base_rate) < flt(last_valuation_rate_in_sales_uom):
+				if is_stock_item and flt(it.base_rate) < flt(last_valuation_rate_in_sales_uom) \
+					and not self.get('is_internal_customer'):
 					throw_message(it.name, last_valuation_rate_in_sales_uom, "valuation rate")
 
 
@@ -300,7 +301,7 @@
 					d.conversion_factor = get_conversion_factor(d.item_code, d.uom).get("conversion_factor") or 1.0
 				return_rate = 0
 				if cint(self.is_return) and self.return_against and self.docstatus==1:
-					return_rate = self.get_incoming_rate_for_sales_return(d.item_code, self.return_against)
+					return_rate = self.get_incoming_rate_for_return(d.item_code, self.return_against)
 
 				# On cancellation or if return entry submission, make stock ledger entry for
 				# target warehouse first, to update serial no values properly
diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py
index 14ee23b..57b4ddd 100644
--- a/erpnext/controllers/stock_controller.py
+++ b/erpnext/controllers/stock_controller.py
@@ -72,7 +72,7 @@
 			if sle_list:
 				for sle in sle_list:
 					if warehouse_account.get(sle.warehouse):
-						# from warehouse account
+						# from warehouse account/ target warehouse account
 
 						self.check_expense_account(item_row)
 
@@ -96,7 +96,7 @@
 							"is_opening": item_row.get("is_opening") or self.get("is_opening") or "No",
 						}, warehouse_account[sle.warehouse]["account_currency"], item=item_row))
 
-						# to target warehouse / expense account
+						# expense account
 						gl_list.append(self.get_gl_dict({
 							"account": item_row.expense_account,
 							"against": warehouse_account[sle.warehouse]["account"],
@@ -288,7 +288,7 @@
 
 		return serialized_items
 
-	def get_incoming_rate_for_sales_return(self, item_code, against_document):
+	def get_incoming_rate_for_return(self, item_code, against_document):
 		incoming_rate = 0.0
 		if against_document and item_code:
 			incoming_rate = frappe.db.sql("""select abs(stock_value_difference / actual_qty)
@@ -306,6 +306,16 @@
 		warehouses = list(set([d.warehouse for d in
 			self.get("items") if getattr(d, "warehouse", None)]))
 
+		target_warehouses = list(set([d.target_warehouse for d in
+			self.get("items") if getattr(d, "target_warehouse", None)]))
+
+		warehouses.extend(target_warehouses)
+
+		from_warehouse = list(set([d.from_warehouse for d in
+			self.get("items") if getattr(d, "from_warehouse", None)]))
+
+		warehouses.extend(from_warehouse)
+
 		for w in warehouses:
 			validate_warehouse_company(w, self.company)
 
diff --git a/erpnext/crm/doctype/opportunity/opportunity.js b/erpnext/crm/doctype/opportunity/opportunity.js
index c9b0433..0c9ba49 100644
--- a/erpnext/crm/doctype/opportunity/opportunity.js
+++ b/erpnext/crm/doctype/opportunity/opportunity.js
@@ -59,6 +59,7 @@
 	contact_person: erpnext.utils.get_contact_details,
 
 	opportunity_from: function(frm) {
+		frm.trigger('setup_queries');
 		frm.toggle_reqd("party_name", frm.doc.opportunity_from);
 		frm.trigger("set_dynamic_field_label");
 	},
diff --git a/erpnext/education/doctype/student/student.py b/erpnext/education/doctype/student/student.py
index 99c4c0e..ae8f3a2 100644
--- a/erpnext/education/doctype/student/student.py
+++ b/erpnext/education/doctype/student/student.py
@@ -25,6 +25,9 @@
 		if self.date_of_birth and getdate(self.date_of_birth) >= getdate(today()):
 			frappe.throw(_("Date of Birth cannot be greater than today."))
 
+		if self.date_of_birth and getdate(self.date_of_birth) >= getdate(self.joining_date):
+			frappe.throw(_("Date of Birth cannot be greater than Joining Date."))
+
 		if self.joining_date and self.date_of_leaving and getdate(self.joining_date) > getdate(self.date_of_leaving):
 			frappe.throw(_("Joining Date can not be greater than Leaving Date"))
 
diff --git a/erpnext/education/doctype/student_applicant/student_applicant.py b/erpnext/education/doctype/student_applicant/student_applicant.py
index 6d0957c..ab94780 100644
--- a/erpnext/education/doctype/student_applicant/student_applicant.py
+++ b/erpnext/education/doctype/student_applicant/student_applicant.py
@@ -29,10 +29,15 @@
 		set_name_by_naming_series(self)
 
 	def validate(self):
+		self.validate_dates()
 		self.title = " ".join(filter(None, [self.first_name, self.middle_name, self.last_name]))
 		if self.student_admission and self.program and self.date_of_birth:
 			self.validation_from_student_admission()
 
+	def validate_dates(self):
+		if self.date_of_birth and getdate(self.date_of_birth) >= getdate():
+			frappe.throw(_("Date of Birth cannot be greater than today."))
+
 	def on_update_after_submit(self):
 		student = frappe.get_list("Student",  filters= {"student_applicant": self.name})
 		if student:
diff --git a/erpnext/education/doctype/student_group/student_group.js b/erpnext/education/doctype/student_group/student_group.js
index 4165ce0..1372440 100644
--- a/erpnext/education/doctype/student_group/student_group.js
+++ b/erpnext/education/doctype/student_group/student_group.js
@@ -70,6 +70,16 @@
 	group_based_on: function(frm) {
 		if (frm.doc.group_based_on == "Batch") {
 			frm.doc.course = null;
+			frm.set_df_property('program', 'reqd', 1);
+			frm.set_df_property('course', 'reqd', 0);
+		}
+		else if (frm.doc.group_based_on == "Course") {
+			frm.set_df_property('program', 'reqd', 0);
+			frm.set_df_property('course', 'reqd', 1);
+		}
+		else if (frm.doc.group_based_on == "Activity") {
+			frm.set_df_property('program', 'reqd', 0);
+			frm.set_df_property('course', 'reqd', 0);
 		}
 	},
 
diff --git a/erpnext/education/doctype/student_group/student_group.py b/erpnext/education/doctype/student_group/student_group.py
index aa542dd..8b61c89 100644
--- a/erpnext/education/doctype/student_group/student_group.py
+++ b/erpnext/education/doctype/student_group/student_group.py
@@ -26,6 +26,8 @@
 			frappe.throw(_("Please select Program"))
 
 	def validate_strength(self):
+		if cint(self.max_strength) < 0:
+			frappe.throw(_("""Max strength cannot be less than zero."""))
 		if self.max_strength and len(self.students) > self.max_strength:
 			frappe.throw(_("""Cannot enroll more than {0} students for this student group.""").format(self.max_strength))
 
diff --git a/erpnext/education/doctype/student_group/test_records.json b/erpnext/education/doctype/student_group/test_records.json
index c36c9b2..4c4e042 100644
--- a/erpnext/education/doctype/student_group/test_records.json
+++ b/erpnext/education/doctype/student_group/test_records.json
@@ -5,26 +5,30 @@
 		"program": "_TP1",
 		"batch": "_Batch 1",
 		"academic_year": "2014-2015",
-		"academic_term": "2014-2015 (_Test Academic Term)"
+		"academic_term": "2014-2015 (_Test Academic Term)",
+		"max_strength": 0
 	},
 	{
 		"student_group_name": "Course-TC101-2014-2015 (_Test Academic Term)",
 		"group_based_on": "Course",
 		"course": "TC101",
 		"academic_year": "2014-2015",
-		"academic_term": "2014-2015 (_Test Academic Term)"
+		"academic_term": "2014-2015 (_Test Academic Term)",
+		"max_strength": 0
 	},
 	{
 		"student_group_name": "Course-TC102-2014-2015 (_Test Academic Term)",
 		"group_based_on": "Course",
 		"course": "TC102",
 		"academic_year": "2014-2015",
-		"academic_term": "2014-2015 (_Test Academic Term)"
+		"academic_term": "2014-2015 (_Test Academic Term)",
+		"max_strength": 0
 	},
 	{
 		"student_group_name": "Activity-2014-2015 (_Test Academic Term)",
 		"group_based_on": "Activity",
 		"academic_year": "2014-2015",
-		"academic_term": "2014-2015 (_Test Academic Term)"
+		"academic_term": "2014-2015 (_Test Academic Term)",
+		"max_strength": 0
 	}
 ]
\ No newline at end of file
diff --git a/erpnext/education/doctype/student_leave_application/student_leave_application.py b/erpnext/education/doctype/student_leave_application/student_leave_application.py
index b3e71a2..410f0cc 100644
--- a/erpnext/education/doctype/student_leave_application/student_leave_application.py
+++ b/erpnext/education/doctype/student_leave_application/student_leave_application.py
@@ -7,9 +7,11 @@
 from frappe import _
 from frappe.utils import get_link_to_form
 from frappe.model.document import Document
+from frappe import throw, _
 
 class StudentLeaveApplication(Document):
 	def validate(self):
+		self.validate_dates()
 		self.validate_duplicate()
 
 	def validate_duplicate(self):
@@ -29,4 +31,8 @@
 		if data:
 			link = get_link_to_form("Student Leave Application", data[0].name)
 			frappe.throw(_("Leave application {0} already exists against the student {1}")
-				.format(link, self.student))
\ No newline at end of file
+				.format(link, self.student))
+
+	def validate_dates(self):
+		if self.to_date < self.from_date :
+			throw(_("To Date cannot be less than From Date"))
\ No newline at end of file
diff --git a/erpnext/erpnext_integrations/connectors/woocommerce_connection.py b/erpnext/erpnext_integrations/connectors/woocommerce_connection.py
index 28c2ab9..4422d23 100644
--- a/erpnext/erpnext_integrations/connectors/woocommerce_connection.py
+++ b/erpnext/erpnext_integrations/connectors/woocommerce_connection.py
@@ -47,11 +47,12 @@
 		return "success"
 
 	if event == "created":
+		sys_lang = frappe.get_single("System Settings").language or 'en'
 		raw_billing_data = order.get("billing")
 		customer_name = raw_billing_data.get("first_name") + " " + raw_billing_data.get("last_name")
 		link_customer_and_address(raw_billing_data, customer_name)
-		link_items(order.get("line_items"), woocommerce_settings)
-		create_sales_order(order, woocommerce_settings, customer_name)
+		link_items(order.get("line_items"), woocommerce_settings, sys_lang)
+		create_sales_order(order, woocommerce_settings, customer_name, sys_lang)
 
 def link_customer_and_address(raw_billing_data, customer_name):
 	customer_woo_com_email = raw_billing_data.get("email")
@@ -100,7 +101,7 @@
 
 		frappe.rename_doc("Address", old_address_title, new_address_title)
 
-def link_items(items_list, woocommerce_settings):
+def link_items(items_list, woocommerce_settings, sys_lang):
 	for item_data in items_list:
 		item_woo_com_id = item_data.get("product_id")
 
@@ -112,14 +113,14 @@
 			item = frappe.new_doc("Item")
 	
 		item.item_name = item_data.get("name")
-		item.item_code = _("woocommerce - {0}").format(item_data.get("product_id"))
+		item.item_code = _("woocommerce - {0}", sys_lang).format(item_data.get("product_id"))
 		item.woocommerce_id = item_data.get("product_id")
-		item.item_group = _("WooCommerce Products")
-		item.stock_uom = woocommerce_settings.uom or _("Nos")
+		item.item_group = _("WooCommerce Products", sys_lang)
+		item.stock_uom = woocommerce_settings.uom or _("Nos", sys_lang)
 		item.flags.ignore_mandatory = True
 		item.save()
 
-def create_sales_order(order, woocommerce_settings, customer_name):	
+def create_sales_order(order, woocommerce_settings, customer_name, sys_lang):
 	new_sales_order = frappe.new_doc("Sales Order")
 	new_sales_order.customer = customer_name
 
@@ -133,14 +134,14 @@
 
 	new_sales_order.company = woocommerce_settings.company
 
-	set_items_in_sales_order(new_sales_order, woocommerce_settings, order)
+	set_items_in_sales_order(new_sales_order, woocommerce_settings, order, sys_lang)
 	new_sales_order.flags.ignore_mandatory = True
 	new_sales_order.insert()
 	new_sales_order.submit()
 
 	frappe.db.commit()
 
-def set_items_in_sales_order(new_sales_order, woocommerce_settings, order):
+def set_items_in_sales_order(new_sales_order, woocommerce_settings, order, sys_lang):
 	company_abbr = frappe.db.get_value('Company', woocommerce_settings.company, 'abbr')
 
 	for item in order.get("line_items"):
@@ -154,10 +155,10 @@
 			"item_name": found_item.item_name,
 			"description": found_item.item_name,
 			"delivery_date": new_sales_order.delivery_date,
-			"uom": woocommerce_settings.uom or _("Nos"),
+			"uom": woocommerce_settings.uom or _("Nos", sys_lang),
 			"qty": item.get("quantity"),
 			"rate": item.get("price"),
-			"warehouse": woocommerce_settings.warehouse or _("Stores - {0}").format(company_abbr)
+			"warehouse": woocommerce_settings.warehouse or _("Stores - {0}", sys_lang).format(company_abbr)
 			})
 
 		add_tax_details(new_sales_order, ordered_items_tax, "Ordered Item tax", woocommerce_settings.tax_account)
diff --git a/erpnext/erpnext_integrations/doctype/amazon_mws_settings/amazon_methods.py b/erpnext/erpnext_integrations/doctype/amazon_mws_settings/amazon_methods.py
index 2f39dc5..3bc8db5 100644
--- a/erpnext/erpnext_integrations/doctype/amazon_mws_settings/amazon_methods.py
+++ b/erpnext/erpnext_integrations/doctype/amazon_mws_settings/amazon_methods.py
@@ -165,6 +165,9 @@
 	return item.name
 
 def create_manufacturer(amazon_item_json):
+	if not amazon_item_json.Product.AttributeSets.ItemAttributes.Manufacturer:
+		return None
+
 	existing_manufacturer = frappe.db.get_value("Manufacturer",
 		filters={"short_name":amazon_item_json.Product.AttributeSets.ItemAttributes.Manufacturer})
 
@@ -177,6 +180,9 @@
 		return existing_manufacturer
 
 def create_brand(amazon_item_json):
+	if not amazon_item_json.Product.AttributeSets.ItemAttributes.Brand:
+		return None
+
 	existing_brand = frappe.db.get_value("Brand",
 		filters={"brand":amazon_item_json.Product.AttributeSets.ItemAttributes.Brand})
 	if not existing_brand:
diff --git a/erpnext/erpnext_integrations/doctype/amazon_mws_settings/amazon_mws_settings.py b/erpnext/erpnext_integrations/doctype/amazon_mws_settings/amazon_mws_settings.py
index 249a73f..c222afb 100644
--- a/erpnext/erpnext_integrations/doctype/amazon_mws_settings/amazon_mws_settings.py
+++ b/erpnext/erpnext_integrations/doctype/amazon_mws_settings/amazon_mws_settings.py
@@ -7,7 +7,6 @@
 from frappe.model.document import Document
 import dateutil
 from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
-from erpnext.erpnext_integrations.doctype.amazon_mws_settings.amazon_methods import get_products_details, get_orders
 
 class AmazonMWSSettings(Document):
 	def validate(self):
@@ -19,12 +18,12 @@
 
 	def get_products_details(self):
 		if self.enable_amazon == 1:
-			get_products_details()
+			frappe.enqueue('erpnext.erpnext_integrations.doctype.amazon_mws_settings.amazon_methods.get_products_details')
 
 	def get_order_details(self):
 		if self.enable_amazon == 1:
 			after_date = dateutil.parser.parse(self.after_date).strftime("%Y-%m-%d")
-			get_orders(after_date = after_date)
+			frappe.enqueue('erpnext.erpnext_integrations.doctype.amazon_mws_settings.amazon_methods.get_orders', after_date=after_date)
 
 def schedule_get_order_details():
 	mws_settings = frappe.get_doc("Amazon MWS Settings")
diff --git a/erpnext/erpnext_integrations/doctype/amazon_mws_settings/xml_utils.py b/erpnext/erpnext_integrations/doctype/amazon_mws_settings/xml_utils.py
index 58db669..a25a29f 100644
--- a/erpnext/erpnext_integrations/doctype/amazon_mws_settings/xml_utils.py
+++ b/erpnext/erpnext_integrations/doctype/amazon_mws_settings/xml_utils.py
@@ -33,7 +33,10 @@
 
 	def __getattr__(self, item):
 
-		d = self.__getitem__(item)
+		try:
+			d = self.__getitem__(item)
+		except KeyError:
+			return None
 
 		if isinstance(d, dict) and 'value' in d and len(d) == 1:
 			return d['value']
diff --git a/erpnext/erpnext_integrations/doctype/plaid_settings/plaid_settings.json b/erpnext/erpnext_integrations/doctype/plaid_settings/plaid_settings.json
index df77ad8..d8203d7 100644
--- a/erpnext/erpnext_integrations/doctype/plaid_settings/plaid_settings.json
+++ b/erpnext/erpnext_integrations/doctype/plaid_settings/plaid_settings.json
@@ -49,9 +49,10 @@
   },
   {
    "fieldname": "plaid_env",
-   "fieldtype": "Data",
+   "fieldtype": "Select",
    "in_list_view": 1,
-   "label": "Plaid Environment"
+   "label": "Plaid Environment",
+   "options": "sandbox\ndevelopment\nproduction"
   },
   {
    "fieldname": "column_break_2",
@@ -69,7 +70,7 @@
  ],
  "issingle": 1,
  "links": [],
- "modified": "2020-01-05 10:00:22.137832",
+ "modified": "2020-02-07 15:21:11.616231",
  "modified_by": "Administrator",
  "module": "ERPNext Integrations",
  "name": "Plaid Settings",
diff --git a/erpnext/erpnext_integrations/doctype/plaid_settings/plaid_settings.py b/erpnext/erpnext_integrations/doctype/plaid_settings/plaid_settings.py
index 9211133..7083950 100644
--- a/erpnext/erpnext_integrations/doctype/plaid_settings/plaid_settings.py
+++ b/erpnext/erpnext_integrations/doctype/plaid_settings/plaid_settings.py
@@ -10,6 +10,7 @@
 from erpnext.accounts.doctype.journal_entry.journal_entry import get_default_bank_cash_account
 from erpnext.erpnext_integrations.doctype.plaid_settings.plaid_connector import PlaidConnector
 from frappe.utils import getdate, formatdate, today, add_months
+from frappe.desk.doctype.tag.tag import add_tag
 
 class PlaidSettings(Document):
 	pass
@@ -133,10 +134,13 @@
 
 	try:
 		transactions = get_transactions(bank=bank, bank_account=bank_account, start_date=start_date, end_date=end_date)
+
 		result = []
-		if transactions:
-			for transaction in transactions:
-				result.append(new_bank_transaction(transaction))
+		for transaction in reversed(transactions):
+			result += new_bank_transaction(transaction)
+
+		frappe.logger().info("Plaid added {} new Bank Transactions from '{}' between {} and {}".format(
+			len(result), bank_account, start_date, end_date))
 
 		frappe.db.set_value("Bank Account", bank_account, "last_integration_date", getdate(end_date))
 
@@ -175,6 +179,13 @@
 
 	status = "Pending" if transaction["pending"] == "True" else "Settled"
 
+	try:
+		tags  = []
+		tags += transaction["category"]
+		tags += ["Plaid Cat. {}".format(transaction["category_id"])]
+	except KeyError:
+		pass
+
 	if not frappe.db.exists("Bank Transaction", dict(transaction_id=transaction["transaction_id"])):
 		try:
 			new_transaction = frappe.get_doc({
@@ -185,11 +196,16 @@
 				"debit": debit,
 				"credit": credit,
 				"currency": transaction["iso_currency_code"],
+				"transaction_id": transaction["transaction_id"],
+				"reference_number": transaction["payment_meta"]["reference_number"],
 				"description": transaction["name"]
 			})
 			new_transaction.insert()
 			new_transaction.submit()
 
+			for tag in tags:
+				add_tag(tag, "Bank Transaction", new_transaction.name)
+
 			result.append(new_transaction.name)
 
 		except Exception:
@@ -201,7 +217,7 @@
 	settings = frappe.get_doc("Plaid Settings", "Plaid Settings")
 
 	if settings.enabled == 1 and settings.automatic_sync == 1:
-		plaid_accounts = frappe.get_all("Bank Account", filter={"integration_id": ["!=", ""]}, fields=["name", "bank"])
+		plaid_accounts = frappe.get_all("Bank Account", filters={"integration_id": ["!=", ""]}, fields=["name", "bank"])
 
 		for plaid_account in plaid_accounts:
 			frappe.enqueue("erpnext.erpnext_integrations.doctype.plaid_settings.plaid_settings.sync_transactions", bank=plaid_account.bank, bank_account=plaid_account.name)
diff --git a/erpnext/hr/doctype/additional_salary/additional_salary.js b/erpnext/hr/doctype/additional_salary/additional_salary.js
index d0f64ab..18f6b8b 100644
--- a/erpnext/hr/doctype/additional_salary/additional_salary.js
+++ b/erpnext/hr/doctype/additional_salary/additional_salary.js
@@ -8,7 +8,8 @@
 		frm.set_query("employee", function() {
 			return {
 				filters: {
-					company: frm.doc.company
+					company: frm.doc.company,
+					status:  "Active"
 				}
 			};
 		});
diff --git a/erpnext/hr/doctype/attendance/attendance.json b/erpnext/hr/doctype/attendance/attendance.json
index ab2dc4a..eaca9f6 100644
--- a/erpnext/hr/doctype/attendance/attendance.json
+++ b/erpnext/hr/doctype/attendance/attendance.json
@@ -58,11 +58,12 @@
   {
    "fetch_from": "employee.employee_name",
    "fieldname": "employee_name",
-   "fieldtype": "Read Only",
+   "fieldtype": "Data",
    "in_global_search": 1,
    "label": "Employee Name",
    "oldfieldname": "employee_name",
-   "oldfieldtype": "Data"
+   "oldfieldtype": "Data",
+   "read_only": 1
   },
   {
    "depends_on": "working_hours",
@@ -174,8 +175,7 @@
  "icon": "fa fa-ok",
  "idx": 1,
  "is_submittable": 1,
- "links": [],
- "modified": "2020-01-27 20:25:29.572281",
+ "modified": "2020-02-19 14:25:32.945842",
  "modified_by": "Administrator",
  "module": "HR",
  "name": "Attendance",
diff --git a/erpnext/hr/doctype/department/department.js b/erpnext/hr/doctype/department/department.js
index 963f361..7db8cfb 100644
--- a/erpnext/hr/doctype/department/department.js
+++ b/erpnext/hr/doctype/department/department.js
@@ -2,6 +2,11 @@
 // For license information, please see license.txt
 
 frappe.ui.form.on('Department', {
+	onload: function(frm) {
+		frm.set_query("parent_department", function(){
+			return {"filters": [["Department", "is_group", "=", 1]]};
+		});
+	},
 	refresh: function(frm) {
 		// read-only for root department
 		if(!frm.doc.parent_department && !frm.is_new()) {
diff --git a/erpnext/hr/doctype/leave_application/test_leave_application.py b/erpnext/hr/doctype/leave_application/test_leave_application.py
index b621642..6e909c3 100644
--- a/erpnext/hr/doctype/leave_application/test_leave_application.py
+++ b/erpnext/hr/doctype/leave_application/test_leave_application.py
@@ -409,7 +409,7 @@
 
 		self.assertEqual(get_leave_balance_on(employee.name, leave_type.name, nowdate(), add_days(nowdate(), 8)), 21)
 
-	def test_earned_leave(self):
+	def test_earned_leaves_creation(self):
 		leave_period = get_leave_period()
 		employee = get_employee()
 		leave_type = 'Test Earned Leave Type'
@@ -437,6 +437,14 @@
 			i += 1
 		self.assertEqual(get_leave_balance_on(employee.name, leave_type, nowdate()), 6)
 
+		# validate earned leaves creation without maximum leaves
+		frappe.db.set_value('Leave Type', leave_type, 'max_leaves_allowed', 0)
+		i = 0
+		while(i<6):
+			allocate_earned_leaves()
+			i += 1
+		self.assertEqual(get_leave_balance_on(employee.name, leave_type, nowdate()), 9)
+
 	# test to not consider current leave in leave balance while submitting
 	def test_current_leave_on_submit(self):
 		employee = get_employee()
diff --git a/erpnext/hr/doctype/vehicle_log/test_vehicle_log.py b/erpnext/hr/doctype/vehicle_log/test_vehicle_log.py
index 35400b0..3770da7 100644
--- a/erpnext/hr/doctype/vehicle_log/test_vehicle_log.py
+++ b/erpnext/hr/doctype/vehicle_log/test_vehicle_log.py
@@ -8,25 +8,9 @@
 from frappe.utils import nowdate,flt, cstr,random_string
 # test_records = frappe.get_test_records('Vehicle Log')
 class TestVehicleLog(unittest.TestCase):
-	def test_make_vehicle_log(self):
-		license_plate=random_string(10).upper()
+	def test_make_vehicle_log_and_syncing_of_odometer_value(self):
 		employee_id=frappe.db.sql("""select name from `tabEmployee` order by modified desc limit 1""")[0][0]
-		vehicle = frappe.get_doc({
-			"doctype": "Vehicle",
-			"license_plate": cstr(license_plate),
-			"make": "Maruti",
-			"model": "PCM",
-			"last_odometer":5000,
-			"acquisition_date":frappe.utils.nowdate(),
-			"location": "Mumbai",
-			"chassis_no": "1234ABCD",
-			"uom": "Litre",
-			"vehicle_value":frappe.utils.flt(500000)
-		})
-		try:
-			vehicle.insert()
-		except frappe.DuplicateEntryError:
-			pass
+		license_plate = get_vehicle(employee_id)
 		vehicle_log = frappe.get_doc({
 			"doctype": "Vehicle Log",
 			"license_plate": cstr(license_plate),
@@ -36,5 +20,41 @@
 			"fuel_qty":frappe.utils.flt(50),
 			"price": frappe.utils.flt(500)
 		})
-		vehicle_log.insert()
-		vehicle_log.submit()
\ No newline at end of file
+		vehicle_log.save()
+		vehicle_log.submit()
+
+		#checking value of vehicle odometer value on submit.
+		vehicle = frappe.get_doc("Vehicle", license_plate)
+		self.assertEqual(vehicle.last_odometer, vehicle_log.odometer)
+
+		#checking value vehicle odometer on vehicle log cancellation.
+		last_odometer = vehicle_log.last_odometer
+		current_odometer = vehicle_log.odometer
+		distance_travelled = current_odometer - last_odometer
+
+		vehicle_log.cancel()
+		vehicle.reload()
+
+		self.assertEqual(vehicle.last_odometer, current_odometer - distance_travelled)
+
+
+def get_vehicle(employee_id):
+	license_plate=random_string(10).upper()
+	vehicle = frappe.get_doc({
+			"doctype": "Vehicle",
+			"license_plate": cstr(license_plate),
+			"make": "Maruti",
+			"model": "PCM",
+			"employee": employee_id,
+			"last_odometer":5000,
+			"acquisition_date":frappe.utils.nowdate(),
+			"location": "Mumbai",
+			"chassis_no": "1234ABCD",
+			"uom": "Litre",
+			"vehicle_value":frappe.utils.flt(500000)
+		})
+	try:
+		vehicle.insert()
+	except frappe.DuplicateEntryError:
+		pass
+	return license_plate
\ No newline at end of file
diff --git a/erpnext/hr/doctype/vehicle_log/vehicle_log.js b/erpnext/hr/doctype/vehicle_log/vehicle_log.js
index 7694cfe..bdb37d2 100644
--- a/erpnext/hr/doctype/vehicle_log/vehicle_log.js
+++ b/erpnext/hr/doctype/vehicle_log/vehicle_log.js
@@ -2,29 +2,41 @@
 // For license information, please see license.txt
 
 frappe.ui.form.on("Vehicle Log", {
-	refresh: function(frm,cdt,cdn) {
-		var vehicle_log=frappe.model.get_doc(cdt,cdn);
-		if (vehicle_log.license_plate) {
-			frappe.call({
-				method: "erpnext.hr.doctype.vehicle_log.vehicle_log.get_make_model",
-				args: {
-					license_plate: vehicle_log.license_plate
-				},
-				callback: function(r) {
-					frappe.model.set_value(cdt, cdn, ("model"), r.message[0]);
-					frappe.model.set_value(cdt, cdn, ("make"), r.message[1]);
-				}
-			})
+	refresh: function(frm) {
+
+		if(frm.doc.license_plate && frm.doc.__islocal){
+			frm.events.set_vehicle_details(frm);
 		}
 
 		if(frm.doc.docstatus == 1) {
 			frm.add_custom_button(__('Expense Claim'), function() {
-				frm.events.expense_claim(frm)
+				frm.events.expense_claim(frm);
 			}, __('Create'));
 			frm.page.set_inner_btn_group_as_primary(__('Create'));
 		}
 	},
 
+	license_plate: function(frm) {
+		if(frm.doc.license_plate){
+			frm.events.set_vehicle_details(frm);
+		}
+	},
+
+	set_vehicle_details: function(frm) {
+		frappe.call({
+			method: "erpnext.hr.doctype.vehicle_log.vehicle_log.get_make_model",
+			args: {
+				license_plate: frm.doc.license_plate
+			},
+			callback: function(r) {
+				frappe.model.set_value(cur_frm.doctype, cur_frm.docname, "make", r.message[0]);
+				frappe.model.set_value(cur_frm.doctype, cur_frm.docname, "model", r.message[1]);
+				frappe.model.set_value(cur_frm.doctype, cur_frm.docname, "last_odometer", r.message[2]);
+				frappe.model.set_value(cur_frm.doctype, cur_frm.docname, "employee", r.message[3]);
+			}
+		});
+	},
+
 	expense_claim: function(frm){
 		frappe.call({
 			method: "erpnext.hr.doctype.vehicle_log.vehicle_log.make_expense_claim",
diff --git a/erpnext/hr/doctype/vehicle_log/vehicle_log.json b/erpnext/hr/doctype/vehicle_log/vehicle_log.json
index cde39e7..52effff 100644
--- a/erpnext/hr/doctype/vehicle_log/vehicle_log.json
+++ b/erpnext/hr/doctype/vehicle_log/vehicle_log.json
@@ -1,706 +1,192 @@
 {
- "allow_copy": 0, 
- "allow_guest_to_view": 0, 
- "allow_import": 0, 
- "allow_rename": 0, 
- "autoname": "naming_series:", 
- "beta": 0, 
- "creation": "2016-09-03 14:14:51.788550", 
- "custom": 0, 
- "docstatus": 0, 
- "doctype": "DocType", 
- "document_type": "Document", 
- "editable_grid": 1, 
+ "actions": [],
+ "autoname": "naming_series:",
+ "creation": "2016-09-03 14:14:51.788550",
+ "doctype": "DocType",
+ "document_type": "Document",
+ "editable_grid": 1,
+ "engine": "InnoDB",
+ "field_order": [
+  "vehicle_section",
+  "naming_series",
+  "license_plate",
+  "employee",
+  "column_break_4",
+  "column_break_7",
+  "model",
+  "make",
+  "odometer_reading",
+  "date",
+  "odometer",
+  "column_break_12",
+  "last_odometer",
+  "refuelling_details",
+  "fuel_qty",
+  "price",
+  "column_break_15",
+  "supplier",
+  "invoice",
+  "service_details",
+  "service_detail",
+  "amended_from"
+ ],
  "fields": [
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "vehicle_section", 
-   "fieldtype": "Section Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "fa fa-user", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "vehicle_section",
+   "fieldtype": "Section Break",
+   "options": "fa fa-user"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "default": "", 
-   "fieldname": "naming_series", 
-   "fieldtype": "Select", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Series", 
-   "length": 0, 
-   "no_copy": 1, 
-   "options": "HR-VLOG-.YYYY.-", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 1, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 1, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "naming_series",
+   "fieldtype": "Select",
+   "label": "Series",
+   "no_copy": 1,
+   "options": "HR-VLOG-.YYYY.-",
+   "print_hide": 1,
+   "reqd": 1,
+   "set_only_once": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "license_plate", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 1, 
-   "in_list_view": 1, 
-   "in_standard_filter": 0, 
-   "label": "License Plate", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Vehicle", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "license_plate",
+   "fieldtype": "Link",
+   "in_global_search": 1,
+   "in_list_view": 1,
+   "label": "License Plate",
+   "options": "Vehicle",
+   "reqd": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "employee", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 1, 
-   "in_standard_filter": 1, 
-   "label": "Employee", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Employee", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "employee",
+   "fieldtype": "Link",
+   "in_list_view": 1,
+   "in_standard_filter": 1,
+   "label": "Employee",
+   "options": "Employee",
+   "reqd": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "column_break_4", 
-   "fieldtype": "Column Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "column_break_4",
+   "fieldtype": "Column Break"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "column_break_7", 
-   "fieldtype": "Column Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "column_break_7",
+   "fieldtype": "Column Break"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "model", 
-   "fieldtype": "Read Only", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Model", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "model",
+   "fieldtype": "Read Only",
+   "label": "Model"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "make", 
-   "fieldtype": "Read Only", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Make", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "make",
+   "fieldtype": "Read Only",
+   "label": "Make"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "odometer_reading", 
-   "fieldtype": "Section Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Odometer Reading", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "odometer_reading",
+   "fieldtype": "Section Break",
+   "label": "Odometer Reading"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "date", 
-   "fieldtype": "Date", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Date", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "date",
+   "fieldtype": "Date",
+   "label": "Date",
+   "reqd": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "odometer", 
-   "fieldtype": "Int", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Odometer", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "odometer",
+   "fieldtype": "Int",
+   "label": "Current Odometer value ",
+   "reqd": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 1, 
-   "columns": 0, 
-   "fieldname": "refuelling_details", 
-   "fieldtype": "Section Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Refuelling Details", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "collapsible": 1,
+   "fieldname": "refuelling_details",
+   "fieldtype": "Section Break",
+   "label": "Refuelling Details"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "fuel_qty", 
-   "fieldtype": "Float", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Fuel Qty", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "fuel_qty",
+   "fieldtype": "Float",
+   "label": "Fuel Qty"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "price", 
-   "fieldtype": "Currency", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Fuel Price", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "price",
+   "fieldtype": "Currency",
+   "label": "Fuel Price"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "column_break_15", 
-   "fieldtype": "Column Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "column_break_15",
+   "fieldtype": "Column Break"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "supplier", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Supplier", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Supplier", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "supplier",
+   "fieldtype": "Link",
+   "label": "Supplier",
+   "options": "Supplier"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "invoice", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Invoice Ref", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "invoice",
+   "fieldtype": "Data",
+   "label": "Invoice Ref"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 1, 
-   "columns": 0, 
-   "fieldname": "service_details", 
-   "fieldtype": "Section Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Service Details", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "collapsible": 1,
+   "fieldname": "service_details",
+   "fieldtype": "Section Break",
+   "label": "Service Details"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "service_detail", 
-   "fieldtype": "Table", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Service Detail", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Vehicle Service", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "service_detail",
+   "fieldtype": "Table",
+   "label": "Service Detail",
+   "options": "Vehicle Service"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "amended_from", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Amended From", 
-   "length": 0, 
-   "no_copy": 1, 
-   "options": "Vehicle Log", 
-   "permlevel": 0, 
-   "print_hide": 1, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 1, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
+   "fieldname": "amended_from",
+   "fieldtype": "Link",
+   "label": "Amended From",
+   "no_copy": 1,
+   "options": "Vehicle Log",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "fieldname": "last_odometer",
+   "fieldtype": "Int",
+   "label": "last Odometer Value ",
+   "read_only": 1,
+   "reqd": 1
+  },
+  {
+   "fieldname": "column_break_12",
+   "fieldtype": "Column Break"
   }
- ], 
- "has_web_view": 0, 
- "hide_heading": 0, 
- "hide_toolbar": 0, 
- "idx": 0, 
- "image_view": 0, 
- "in_create": 0, 
- "is_submittable": 1, 
- "issingle": 0, 
- "istable": 0, 
- "max_attachments": 0, 
- "modified": "2018-08-21 14:44:51.131186", 
- "modified_by": "Administrator", 
- "module": "HR", 
- "name": "Vehicle Log", 
- "name_case": "", 
- "owner": "Administrator", 
+ ],
+ "is_submittable": 1,
+ "links": [],
+ "modified": "2020-01-28 12:43:34.419647",
+ "modified_by": "Administrator",
+ "module": "HR",
+ "name": "Vehicle Log",
+ "owner": "Administrator",
  "permissions": [
   {
-   "amend": 0, 
-   "cancel": 1, 
-   "create": 1, 
-   "delete": 1, 
-   "email": 1, 
-   "export": 1, 
-   "if_owner": 0, 
-   "import": 0, 
-   "permlevel": 0, 
-   "print": 1, 
-   "read": 1, 
-   "report": 1, 
-   "role": "Fleet Manager", 
-   "set_user_permissions": 0, 
-   "share": 1, 
-   "submit": 1, 
+   "cancel": 1,
+   "create": 1,
+   "delete": 1,
+   "email": 1,
+   "export": 1,
+   "print": 1,
+   "read": 1,
+   "report": 1,
+   "role": "Fleet Manager",
+   "share": 1,
+   "submit": 1,
    "write": 1
   }
- ], 
- "quick_entry": 1, 
- "read_only": 0, 
- "read_only_onload": 0, 
- "show_name_in_global_search": 0, 
- "sort_field": "modified", 
- "sort_order": "DESC", 
- "title_field": "", 
- "track_changes": 1, 
- "track_seen": 0, 
- "track_views": 0
+ ],
+ "sort_field": "modified",
+ "sort_order": "DESC",
+ "track_changes": 1
 }
\ No newline at end of file
diff --git a/erpnext/hr/doctype/vehicle_log/vehicle_log.py b/erpnext/hr/doctype/vehicle_log/vehicle_log.py
index df63361..12cc1dd 100644
--- a/erpnext/hr/doctype/vehicle_log/vehicle_log.py
+++ b/erpnext/hr/doctype/vehicle_log/vehicle_log.py
@@ -11,22 +11,33 @@
 
 class VehicleLog(Document):
 	def validate(self):
-		last_odometer=frappe.db.get_value("Vehicle", self.license_plate, "last_odometer")
-		if flt(self.odometer) < flt(last_odometer):
-			frappe.throw(_("Current Odometer reading entered should be greater than initial Vehicle Odometer {0}").format(last_odometer))
+		if flt(self.odometer) < flt(self.last_odometer):
+			frappe.throw(_("Current Odometer reading entered should be greater than initial Vehicle Odometer {0}").format(self.last_odometer))
 		for service_detail in self.service_detail:
 			if (service_detail.service_item or service_detail.type or service_detail.frequency or service_detail.expense_amount):
 					if not (service_detail.service_item and service_detail.type and service_detail.frequency and service_detail.expense_amount):
 							frappe.throw(_("Service Item,Type,frequency and expense amount are required"))
 
+	def before_insert(self):
+		model_details = get_make_model(self.license_plate)
+		self.make = model_details[0]
+		self.model = model_details[1]
+		self.last_odometer = model_details[2]
+		self.employee = model_details[3]
+
 	def on_submit(self):
-		frappe.db.sql("update `tabVehicle` set last_odometer=%s where license_plate=%s",
-			(self.odometer, self.license_plate))
+		frappe.db.set_value("Vehicle", self.license_plate, "last_odometer", self.odometer)
+
+	def on_cancel(self):
+		distance_travelled = self.odometer - self.last_odometer
+		if(distance_travelled > 0):
+			updated_odometer_value = int(frappe.db.get_value("Vehicle", self.license_plate, "last_odometer")) - distance_travelled
+			frappe.db.set_value("Vehicle", self.license_plate, "last_odometer", updated_odometer_value)
 
 @frappe.whitelist()
 def get_make_model(license_plate):
 	vehicle=frappe.get_doc("Vehicle",license_plate)
-	return (vehicle.make,vehicle.model)
+	return (vehicle.make, vehicle.model, vehicle.last_odometer, vehicle.employee)
 
 @frappe.whitelist()
 def make_expense_claim(docname):
diff --git a/erpnext/hr/utils.py b/erpnext/hr/utils.py
index c3e8d27..ef27600 100644
--- a/erpnext/hr/utils.py
+++ b/erpnext/hr/utils.py
@@ -316,7 +316,9 @@
 
 				allocation = frappe.get_doc('Leave Allocation', allocation.name)
 				new_allocation = flt(allocation.total_leaves_allocated) + flt(earned_leaves)
-				new_allocation = new_allocation if new_allocation <= e_leave_type.max_leaves_allowed else e_leave_type.max_leaves_allowed
+
+				if new_allocation > e_leave_type.max_leaves_allowed and e_leave_type.max_leaves_allowed > 0:
+					new_allocation = e_leave_type.max_leaves_allowed
 
 				if new_allocation == allocation.total_leaves_allocated:
 					continue
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index a893840..42d537a 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -652,8 +652,10 @@
 erpnext.patches.v12_0.set_employee_preferred_emails
 erpnext.patches.v12_0.set_against_blanket_order_in_sales_and_purchase_order
 erpnext.patches.v12_0.set_cost_center_in_child_table_of_expense_claim
+erpnext.patches.v12_0.add_eway_bill_in_delivery_note
 erpnext.patches.v12_0.set_lead_title_field
 erpnext.patches.v12_0.set_permission_einvoicing
 erpnext.patches.v12_0.set_published_in_hub_tracked_item
 erpnext.patches.v12_0.set_job_offer_applicant_email
-erpnext.patches.v12_0.create_irs_1099_field_united_states
\ No newline at end of file
+erpnext.patches.v12_0.create_irs_1099_field_united_states
+erpnext.patches.v12_0.rename_bank_reconciliation_fields # 2020-01-22
diff --git a/erpnext/patches/v12_0/add_eway_bill_in_delivery_note.py b/erpnext/patches/v12_0/add_eway_bill_in_delivery_note.py
new file mode 100644
index 0000000..bb4b038
--- /dev/null
+++ b/erpnext/patches/v12_0/add_eway_bill_in_delivery_note.py
@@ -0,0 +1,19 @@
+import frappe
+from frappe.custom.doctype.custom_field.custom_field import create_custom_field
+
+def execute():
+    company = frappe.get_all('Company', filters = {'country': 'India'})
+
+    if not company:
+        return
+
+    create_custom_field('Delivery Note', {
+        'fieldname': 'ewaybill',
+        'label': 'E-Way Bill No.',
+        'fieldtype': 'Data',
+        'depends_on': 'eval:(doc.docstatus === 1)',
+        'allow_on_submit': 1,
+        'insert_after': 'customer_name_in_arabic',
+        'translatable': 0,
+        'owner': 'Administrator'
+    })
\ No newline at end of file
diff --git a/erpnext/patches/v12_0/rename_bank_reconciliation_fields.py b/erpnext/patches/v12_0/rename_bank_reconciliation_fields.py
new file mode 100644
index 0000000..caeda8a
--- /dev/null
+++ b/erpnext/patches/v12_0/rename_bank_reconciliation_fields.py
@@ -0,0 +1,14 @@
+# Copyright (c) 2020, Frappe and Contributors
+# License: GNU General Public License v3. See license.txt
+
+import frappe
+
+def _rename_single_field(**kwargs):
+	count = frappe.db.sql("SELECT COUNT(*) FROM tabSingles WHERE doctype='{doctype}' AND field='{new_name}';".format(**kwargs))[0][0] #nosec
+	if count == 0:
+		frappe.db.sql("UPDATE tabSingles SET field='{new_name}' WHERE doctype='{doctype}' AND field='{old_name}';".format(**kwargs)) #nosec
+
+def execute():
+	_rename_single_field(doctype = "Bank Reconciliation", old_name = "bank_account" , new_name = "account")
+	_rename_single_field(doctype = "Bank Reconciliation", old_name = "bank_account_no", new_name = "bank_account")
+	frappe.reload_doc("Accounts", "doctype", "Bank Reconciliation")
diff --git a/erpnext/projects/doctype/project_user/project_user.json b/erpnext/projects/doctype/project_user/project_user.json
index f0a70dd..2f452cc 100644
--- a/erpnext/projects/doctype/project_user/project_user.json
+++ b/erpnext/projects/doctype/project_user/project_user.json
@@ -1,4 +1,5 @@
 {
+ "actions": [],
  "creation": "2016-03-25 02:52:19.283003",
  "doctype": "DocType",
  "editable_grid": 1,
@@ -46,6 +47,7 @@
    "fetch_from": "user.full_name",
    "fieldname": "full_name",
    "fieldtype": "Read Only",
+   "in_list_view": 1,
    "label": "Full Name"
   },
   {
@@ -55,7 +57,7 @@
    "label": "Welcome email sent"
   },
   {
-   "columns": 1,
+   "columns": 2,
    "default": "0",
    "fieldname": "view_attachments",
    "fieldtype": "Check",
@@ -74,7 +76,8 @@
   }
  ],
  "istable": 1,
- "modified": "2019-07-15 19:37:26.942294",
+ "links": [],
+ "modified": "2020-02-09 23:26:50.321417",
  "modified_by": "Administrator",
  "module": "Projects",
  "name": "Project User",
diff --git a/erpnext/public/js/conf.js b/erpnext/public/js/conf.js
index 0f88f13..615f6a4 100644
--- a/erpnext/public/js/conf.js
+++ b/erpnext/public/js/conf.js
@@ -29,19 +29,6 @@
 
 });
 
-
-
-// doctypes created via tree
-$.extend(frappe.create_routes, {
-	"Customer Group": "Tree/Customer Group",
-	"Territory": "Tree/Territory",
-	"Item Group": "Tree/Item Group",
-	"Sales Person": "Tree/Sales Person",
-	"Account": "Tree/Account",
-	"Cost Center": "Tree/Cost Center",
-	"Department": "Tree/Department",
-});
-
 // preferred modules for breadcrumbs
 $.extend(frappe.breadcrumbs.preferred, {
 	"Item Group": "Stock",
diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js
index 28fb649..a51c2f0 100644
--- a/erpnext/public/js/controllers/taxes_and_totals.js
+++ b/erpnext/public/js/controllers/taxes_and_totals.js
@@ -3,6 +3,7 @@
 
 erpnext.taxes_and_totals = erpnext.payments.extend({
 	setup: function() {},
+
 	apply_pricing_rule_on_item: function(item){
 		let effective_item_rate = item.price_list_rate;
 		if (item.parenttype === "Sales Order" && item.blanket_order_rate) {
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index 51ab48a..fea2d5e 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -490,7 +490,7 @@
 							cost_center: item.cost_center,
 							tax_category: me.frm.doc.tax_category,
 							item_tax_template: item.item_tax_template,
-							child_docname: item.name,
+							child_docname: item.name
 						}
 					},
 
@@ -504,7 +504,20 @@
 										me.apply_product_discount(d.free_item_data);
 									}
 								},
-								() => me.frm.script_manager.trigger("price_list_rate", cdt, cdn),
+								() => {
+									// for internal customer instead of pricing rule directly apply valuation rate on item
+									if (me.frm.doc.is_internal_customer || me.frm.doc.is_internal_supplier) {
+										me.get_incoming_rate(item, me.frm.posting_date, me.frm.posting_time,
+											me.frm.doc.doctype, me.frm.doc.company);
+									} else {
+										me.frm.script_manager.trigger("price_list_rate", cdt, cdn);
+									}
+								},
+								() => {
+									if (me.frm.doc.is_internal_customer || me.frm.doc.is_internal_supplier) {
+										me.calculate_taxes_and_totals();
+									}
+								},
 								() => me.toggle_conversion_factor(item),
 								() => {
 									if(show_batch_dialog && !frappe.flags.hide_serial_batch_dialog) {
@@ -528,6 +541,31 @@
 		}
 	},
 
+	get_incoming_rate: function(item, posting_date, posting_time, voucher_type, company) {
+
+		let item_args = {
+			'item_code': item.item_code,
+			'warehouse': in_list('Purchase Receipt', 'Purchase Invoice') ? item.from_warehouse : item.warehouse,
+			'posting_date': posting_date,
+			'posting_time': posting_time,
+			'qty': item.qty * item.conversion_factor,
+			'serial_no': item.serial_no,
+			'voucher_type': voucher_type,
+			'company': company,
+			'allow_zero_valuation_rate': item.allow_zero_valuation_rate
+		}
+
+		frappe.call({
+			method: 'erpnext.stock.utils.get_incoming_rate',
+			args: {
+				args: item_args
+			},
+			callback: function(r) {
+				frappe.model.set_value(item.doctype, item.name, 'rate', r.message);
+			}
+		});
+	},
+
 	add_taxes_from_item_tax_template: function(item_tax_map) {
 		let me = this;
 
@@ -941,15 +979,19 @@
 	},
 
 	conversion_factor: function(doc, cdt, cdn, dont_fetch_price_list_rate) {
-		if(doc.doctype != 'Material Request' && frappe.meta.get_docfield(cdt, "stock_qty", cdn)) {
+		if(frappe.meta.get_docfield(cdt, "stock_qty", cdn)) {
 			var item = frappe.get_doc(cdt, cdn);
 			frappe.model.round_floats_in(item, ["qty", "conversion_factor"]);
 			item.stock_qty = flt(item.qty * item.conversion_factor, precision("stock_qty", item));
-			item.total_weight = flt(item.stock_qty * item.weight_per_unit);
 			refresh_field("stock_qty", item.name, item.parentfield);
-			refresh_field("total_weight", item.name, item.parentfield);
 			this.toggle_conversion_factor(item);
-			this.calculate_net_weight();
+
+			if(doc.doctype != "Material Request") {
+				item.total_weight = flt(item.stock_qty * item.weight_per_unit);
+				refresh_field("total_weight", item.name, item.parentfield);
+				this.calculate_net_weight();
+			}
+
 			if (!dont_fetch_price_list_rate &&
 				frappe.meta.has_field(doc.doctype, "price_list_currency")) {
 				this.apply_price_list(item, true);
diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js
index 3f444f8..35dc842 100755
--- a/erpnext/public/js/utils.js
+++ b/erpnext/public/js/utils.js
@@ -514,9 +514,18 @@
 }
 
 erpnext.utils.map_current_doc = function(opts) {
-	if(opts.get_query_filters) {
-		opts.get_query = function() {
-			return {filters: opts.get_query_filters};
+	let query_args = {};
+	if (opts.get_query_filters) {
+		query_args.filters = opts.get_query_filters;
+	}
+
+	if (opts.get_query_method) {
+		query_args.query = opts.get_query_method;
+	}
+
+	if (query_args.filters || query_args.query) {
+		opts.get_query = () => {
+			return query_args;
 		}
 	}
 	var _map = function() {
@@ -582,7 +591,7 @@
 				"method": opts.method,
 				"source_names": opts.source_name,
 				"target_doc": cur_frm.doc,
-				'args': opts.args
+				"args": opts.args
 			},
 			callback: function(r) {
 				if(!r.exc) {
diff --git a/erpnext/quality_management/doctype/quality_procedure/quality_procedure_tree.js b/erpnext/quality_management/doctype/quality_procedure/quality_procedure_tree.js
index dbdbbab..6df6f65 100644
--- a/erpnext/quality_management/doctype/quality_procedure/quality_procedure_tree.js
+++ b/erpnext/quality_management/doctype/quality_procedure/quality_procedure_tree.js
@@ -4,7 +4,7 @@
 	add_tree_node: 'erpnext.quality_management.doctype.quality_procedure.quality_procedure.add_node',
 	filters: [
 		{
-			fieldname: "quality_procedure",
+			fieldname: "parent_quality_procedure",
 			fieldtype: "Link",
 			options: "Quality Procedure",
 			label: __("Quality Procedure"),
diff --git a/erpnext/regional/doctype/gstr_3b_report/test_gstr_3b_report.py b/erpnext/regional/doctype/gstr_3b_report/test_gstr_3b_report.py
index fa6fb70..8174da2 100644
--- a/erpnext/regional/doctype/gstr_3b_report/test_gstr_3b_report.py
+++ b/erpnext/regional/doctype/gstr_3b_report/test_gstr_3b_report.py
@@ -152,6 +152,7 @@
 			currency = 'INR',
 			warehouse = 'Finished Goods - _GST',
 			cost_center = 'Main - _GST',
+			expense_account = 'Cost of Goods Sold - _GST',
 			do_not_save=1,
 		)
 
@@ -181,6 +182,7 @@
 			currency = 'INR',
 			warehouse = 'Finished Goods - _GST',
 			cost_center = 'Main - _GST',
+			expense_account = 'Cost of Goods Sold - _GST',
 			item = "Milk",
 			do_not_save=1
 		)
diff --git a/erpnext/regional/india/setup.py b/erpnext/regional/india/setup.py
index cabfde4..970a831 100644
--- a/erpnext/regional/india/setup.py
+++ b/erpnext/regional/india/setup.py
@@ -245,7 +245,16 @@
 			'insert_after': 'lr_date',
 			'print_hide': 1,
 			'translatable': 0
-		}
+		},
+		{
+			'fieldname': 'ewaybill',
+			'label': 'E-Way Bill No.',
+			'fieldtype': 'Data',
+			'depends_on': 'eval:(doc.docstatus === 1)',
+			'allow_on_submit': 1,
+			'insert_after': 'customer_name_in_arabic',
+			'translatable': 0,
+    	}
 	]
 
 	si_ewaybill_fields = [
@@ -361,7 +370,7 @@
 		},
 		{
 			'fieldname': 'ewaybill',
-			'label': 'e-Way Bill No.',
+			'label': 'E-Way Bill No.',
 			'fieldtype': 'Data',
 			'depends_on': 'eval:(doc.docstatus === 1)',
 			'allow_on_submit': 1,
diff --git a/erpnext/regional/india/taxes.js b/erpnext/regional/india/taxes.js
index 1e59032..4d36cff 100644
--- a/erpnext/regional/india/taxes.js
+++ b/erpnext/regional/india/taxes.js
@@ -32,6 +32,9 @@
 				callback: function(r) {
 					if(r.message) {
 						frm.set_value('taxes_and_charges', r.message.taxes_and_charges);
+					} else if (frm.doc.is_internal_supplier || frm.doc.is_internal_customer) {
+						frm.set_value('taxes_and_charges', '');
+						frm.set_value('taxes', []);
 					}
 				}
 			});
diff --git a/erpnext/regional/india/utils.py b/erpnext/regional/india/utils.py
index 266affb..f37b0e4 100644
--- a/erpnext/regional/india/utils.py
+++ b/erpnext/regional/india/utils.py
@@ -141,18 +141,24 @@
 		address_name = party_details.shipping_address or party_details.supplier_address
 
 	if address_name:
-		address = frappe.db.get_value("Address", address_name, ["gst_state", "gst_state_number"], as_dict=1)
+		address = frappe.db.get_value("Address", address_name, ["gst_state", "gst_state_number", "gstin"], as_dict=1)
 		if address and address.gst_state and address.gst_state_number:
+			party_details.gstin = address.gstin
 			return cstr(address.gst_state_number) + "-" + cstr(address.gst_state)
 
 @frappe.whitelist()
 def get_regional_address_details(party_details, doctype, company, return_taxes=None):
-
 	if isinstance(party_details, string_types):
 		party_details = json.loads(party_details)
 		party_details = frappe._dict(party_details)
 
 	party_details.place_of_supply = get_place_of_supply(party_details, doctype)
+
+	if is_internal_transfer(party_details, doctype):
+		party_details.taxes_and_charges = ''
+		party_details.taxes = ''
+		return
+
 	if doctype in ("Sales Invoice", "Delivery Note", "Sales Order"):
 		master_doctype = "Sales Taxes and Charges Template"
 
@@ -167,7 +173,6 @@
 
 	elif doctype in ("Purchase Invoice", "Purchase Order", "Purchase Receipt"):
 		master_doctype = "Purchase Taxes and Charges Template"
-
 		get_tax_template_for_sez(party_details, master_doctype, company, 'Supplier')
 		get_tax_template_based_on_category(master_doctype, company, party_details)
 
@@ -196,6 +201,17 @@
 	if return_taxes:
 		return party_details
 
+def is_internal_transfer(party_details, doctype):
+	if doctype in ("Sales Invoice", "Delivery Note", "Sales Order"):
+		destination_gstin = party_details.company_gstin
+	elif doctype in ("Purchase Invoice", "Purchase Order", "Purchase Receipt"):
+		destination_gstin = party_details.supplier_gstin
+
+	if party_details.gstin == destination_gstin:
+		return True
+	else:
+		False
+
 def get_tax_template_based_on_category(master_doctype, company, party_details):
 	if not party_details.get('tax_category'):
 		return
@@ -218,7 +234,6 @@
 	 		(not default_tax and not tax_category.gst_state):
 			default_tax = frappe.db.get_value(master_doctype,
 				{'disabled': 0, 'tax_category': tax_category.name}, 'name')
-
 	return default_tax
 
 def get_tax_template_for_sez(party_details, master_doctype, company, party_type):
@@ -357,16 +372,13 @@
 		return exemptions
 
 def get_ewb_data(dt, dn):
-	if dt != 'Sales Invoice':
-		frappe.throw(_('E-Way Bill JSON can only be generated from Sales Invoice'))
-
 	dn = dn.split(',')
 
 	ewaybills = []
 	for doc_name in dn:
 		doc = frappe.get_doc(dt, doc_name)
 
-		validate_sales_invoice(doc)
+		validate_doc(doc)
 
 		data = frappe._dict({
 			"transporterId": "",
@@ -376,7 +388,9 @@
 		data.userGstin = data.fromGstin = doc.company_gstin
 		data.supplyType = 'O'
 
-		if doc.gst_category in ['Registered Regular', 'SEZ']:
+		if dt == 'Delivery Note':
+			data.subSupplyType = 1
+		elif doc.gst_category in ['Registered Regular', 'SEZ']:
 			data.subSupplyType = 1
 		elif doc.gst_category in ['Overseas', 'Deemed Export']:
 			data.subSupplyType = 3
@@ -535,7 +549,7 @@
 
 	return data
 
-def validate_sales_invoice(doc):
+def validate_doc(doc):
 	if doc.docstatus != 1:
 		frappe.throw(_('E-Way Bill JSON can only be generated from submitted document'))
 
diff --git a/erpnext/regional/report/datev/datev.py b/erpnext/regional/report/datev/datev.py
index bd70639..7ceaf50 100644
--- a/erpnext/regional/report/datev/datev.py
+++ b/erpnext/regional/report/datev/datev.py
@@ -72,17 +72,16 @@
 			case gl.debit when 0 then 'H' else 'S' end as 'Soll/Haben-Kennzeichen',
 
 			/* account number or, if empty, party account number */
-			coalesce(acc.account_number, acc_pa.account_number) as 'Kontonummer',
+			coalesce(acc.account_number, acc_pa.account_number) as 'Konto',
 
 			/* against number or, if empty, party against number */
 			coalesce(acc_against.account_number, acc_against_pa.account_number) as 'Gegenkonto (ohne BU-Schlüssel)',
 			
 			gl.posting_date as 'Belegdatum',
+			gl.voucher_no as 'Belegfeld 1',
 			gl.remarks as 'Buchungstext',
-			gl.voucher_type as 'Beleginfo - Art 1',
-			gl.voucher_no as 'Beleginfo - Inhalt 1',
-			gl.against_voucher_type as 'Beleginfo - Art 2',
-			gl.against_voucher as 'Beleginfo - Inhalt 2'
+			gl.against_voucher_type as 'Beleginfo - Art 1',
+			gl.against_voucher as 'Beleginfo - Inhalt 1'
 
 		FROM `tabGL Entry` gl
 
@@ -240,8 +239,6 @@
 	filters -- dict
 	csv_class -- defines DATA_CATEGORY, FORMAT_NAME and COLUMNS
 	"""
-	header = get_header(filters, csv_class)
-
 	empty_df = pd.DataFrame(columns=csv_class.COLUMNS)
 	data_df = pd.DataFrame.from_records(data)
 
@@ -253,7 +250,6 @@
 	if csv_class.DATA_CATEGORY == DataCategory.ACCOUNT_NAMES:
 		result['Sprach-ID'] = 'de-DE'
 
-	header = ';'.join(header).encode('latin_1')
 	data = result.to_csv(
 		# Reason for str(';'): https://github.com/pandas-dev/pandas/issues/6035
 		sep=str(';'),
@@ -274,66 +270,91 @@
 	if not six.PY2:
 		data = data.encode('latin_1')
 
+	header = get_header(filters, csv_class)
+	header = ';'.join(header).encode('latin_1')
+
+	# 1st Row: Header with meta data
+	# 2nd Row: Data heading (Überschrift der Nutzdaten), included in `data` here.
+	# 3rd - nth Row: Data (Nutzdaten)
 	return header + b'\r\n' + data
 
 
 def get_header(filters, csv_class):
+	coa = frappe.get_value("Company", filters.get("company"), "chart_of_accounts")
+	coa_used = "SKR04" if "SKR04" in coa else ("SKR03" if "SKR03" in coa else "")
+
 	header = [
-		# A = DATEV format
-		#   DTVF = created by DATEV software,
-		#   EXTF = created by other software
-		"EXTF",
-		# B = version of the DATEV format
+		# DATEV format
+		#   "DTVF" = created by DATEV software,
+		#   "EXTF" = created by other software
+		'"EXTF"',
+		# version of the DATEV format
 		#   141 = 1.41, 
 		#   510 = 5.10,
 		#   720 = 7.20
-		"510",
+		'700',
 		csv_class.DATA_CATEGORY,
-		csv_class.FORMAT_NAME,
-		# E = Format version (regarding format name)
-		"",
-		# F = Generated on
-		datetime.datetime.now().strftime("%Y%m%d"),
-		# G = Imported on -- stays empty
-		"",
-		# H = Origin (SV = other (?), RE = KARE)
-		"SV",
+		'"%s"' % csv_class.FORMAT_NAME,
+		# Format version (regarding format name)
+		csv_class.FORMAT_VERSION,
+		# Generated on
+		datetime.datetime.now().strftime("%Y%m%d%H%M%S"),
+		# Imported on -- stays empty
+		'',
+		# Origin. Any two symbols, will be replaced by "SV" on import.
+		'"EN"',
 		# I = Exported by
-		frappe.session.user,
+		'"%s"' % frappe.session.user,
 		# J = Imported by -- stays empty
-		"",
+		'',
 		# K = Tax consultant number (Beraternummer)
-		frappe.get_value("DATEV Settings", filters.get("company"), "consultant_number") or "",
-		"",
+		frappe.get_value("DATEV Settings", filters.get("company"), "consultant_number"),
 		# L = Tax client number (Mandantennummer)
-		frappe.get_value("DATEV Settings", filters.get("company"), "client_number") or "",
-		"",
+		frappe.get_value("DATEV Settings", filters.get("company"), "client_number"),
 		# M = Start of the fiscal year (Wirtschaftsjahresbeginn)
 		frappe.utils.formatdate(frappe.defaults.get_user_default("year_start_date"), "yyyyMMdd"),
 		# N = Length of account numbers (Sachkontenlänge)
-		"4",
+		'4',
 		# O = Transaction batch start date (YYYYMMDD)
 		frappe.utils.formatdate(filters.get('from_date'), "yyyyMMdd"),
 		# P = Transaction batch end date (YYYYMMDD)
 		frappe.utils.formatdate(filters.get('to_date'), "yyyyMMdd"),
 		# Q = Description (for example, "January - February 2019 Transactions")
-		"{} - {} {}".format(
+		'"{} - {} {}"'.format(
 				frappe.utils.formatdate(filters.get('from_date'), "MMMM yyyy"),
 				frappe.utils.formatdate(filters.get('to_date'), "MMMM yyyy"),
 				csv_class.FORMAT_NAME
 		),
 		# R = Diktatkürzel
-		"",
+		'',
 		# S = Buchungstyp
-		#   1 = Transaction batch (Buchungsstapel),
+		#   1 = Transaction batch (Finanzbuchführung),
 		#   2 = Annual financial statement (Jahresabschluss)
-		"1" if csv_class.DATA_CATEGORY == DataCategory.TRANSACTIONS else "",
+		'1' if csv_class.DATA_CATEGORY == DataCategory.TRANSACTIONS else '',
 		# T = Rechnungslegungszweck
-		"",
+		'',
 		# U = Festschreibung
-		"",
-		# V = Kontoführungs-Währungskennzeichen des Geldkontos
-		frappe.get_value("Company", filters.get("company"), "default_currency")
+		'',
+		# V = Default currency, for example, "EUR"
+		'"%s"' % frappe.get_value("Company", filters.get("company"), "default_currency"),
+		# reserviert
+		'',
+		# Derivatskennzeichen
+		'',
+		# reserviert
+		'',
+		# reserviert
+		'',
+		# SKR
+		'"%s"' % coa_used,
+		# Branchen-Lösungs-ID
+		'',
+		# reserviert
+		'',
+		# reserviert
+		'',
+		# Anwendungsinformation (Verarbeitungskennzeichen der abgebenden Anwendung)
+		''
 	]
 	return header
 
diff --git a/erpnext/regional/report/datev/datev_constants.py b/erpnext/regional/report/datev/datev_constants.py
index 1c9bd23..a4cd5fc 100644
--- a/erpnext/regional/report/datev/datev_constants.py
+++ b/erpnext/regional/report/datev/datev_constants.py
@@ -13,24 +13,27 @@
 	"Basis-Umsatz",
 	"WKZ Basis-Umsatz",
 	# Konto/Gegenkonto
-	"Kontonummer",
+	"Konto",
 	"Gegenkonto (ohne BU-Schlüssel)",
 	"BU-Schlüssel",
 	# Datum
 	"Belegdatum",
-	# Belegfelder
+	# Rechnungs- / Belegnummer
 	"Belegfeld 1",
+	# z.B. Fälligkeitsdatum Format: TTMMJJ
 	"Belegfeld 2",
-	# Weitere Felder
+	# Skonto-Betrag / -Abzug (Der Wert 0 ist unzulässig)
 	"Skonto",
+	# Beschreibung des Buchungssatzes
 	"Buchungstext",
-	# OPOS-Informationen
+	# Mahn- / Zahl-Sperre (1 = Postensperre)
 	"Postensperre",
 	"Diverse Adressnummer",
 	"Geschäftspartnerbank",
 	"Sachverhalt",
+	# Keine Mahnzinsen
 	"Zinssperre",
-	# Digitaler Beleg
+	# Link auf den Buchungsbeleg (Programmkürzel + GUID)
 	"Beleglink",
 	# Beleginfo
 	"Beleginfo - Art 1",
@@ -49,22 +52,30 @@
 	"Beleginfo - Inhalt 7",
 	"Beleginfo - Art 8",
 	"Beleginfo - Inhalt 8",
-	# Kostenrechnung
-	"Kost 1 - Kostenstelle",
-	"Kost 2 - Kostenstelle",
-	"Kost-Menge",
-	# Steuerrechnung
-	"EU-Land u. UStID",
+	# Zuordnung des Geschäftsvorfalls für die Kostenrechnung
+	"KOST1 - Kostenstelle",
+	"KOST2 - Kostenstelle",
+	"KOST-Menge",
+	# USt-ID-Nummer (Beispiel: DE133546770)
+	"EU-Mitgliedstaat u. USt-IdNr.",
+	# Der im EU-Bestimmungsland gültige Steuersatz
 	"EU-Steuersatz",
+	# I = Ist-Versteuerung,
+	# K = keine Umsatzsteuerrechnung
+	# P = Pauschalierung (z. B. für Land- und Forstwirtschaft),
+	# S = Soll-Versteuerung
 	"Abw. Versteuerungsart",
-	# L+L Sachverhalt
+	# Sachverhalte gem. § 13b Abs. 1 Satz 1 Nrn. 1.-5. UStG
 	"Sachverhalt L+L",
+	# Steuersatz / Funktion zum L+L-Sachverhalt (Beispiel: Wert 190 für 19%)
 	"Funktionsergänzung L+L",
-	# Funktion Steuerschlüssel 49
+	# Bei Verwendung des BU-Schlüssels 49 für „andere Steuersätze“ muss der
+	# steuerliche Sachverhalt mitgegeben werden
 	"BU 49 Hauptfunktionstyp",
 	"BU 49 Hauptfunktionsnummer",
 	"BU 49 Funktionsergänzung",
-	# Zusatzinformationen
+	# Zusatzinformationen, besitzen den Charakter eines Notizzettels und können
+	# frei erfasst werden.
 	"Zusatzinformation - Art 1",
 	"Zusatzinformation - Inhalt 1",
 	"Zusatzinformation - Art 2",
@@ -105,54 +116,76 @@
 	"Zusatzinformation - Inhalt 19",
 	"Zusatzinformation - Art 20",
 	"Zusatzinformation - Inhalt 20",
-	# Mengenfelder LuF
+	# Wirkt sich nur bei Sachverhalt mit SKR 14 Land- und Forstwirtschaft aus,
+	# für andere SKR werden die Felder beim Import / Export überlesen bzw.
+	# leer exportiert.
 	"Stück",
 	"Gewicht",
-	# Forderungsart
+	# 1 = Lastschrift
+	# 2 = Mahnung
+	# 3 = Zahlung
 	"Zahlweise",
 	"Forderungsart",
+	# JJJJ
 	"Veranlagungsjahr",
+	# TTMMJJJJ
 	"Zugeordnete Fälligkeit",
-	# Weitere Felder
+	# 1 = Einkauf von Waren
+	# 2 = Erwerb von Roh-Hilfs- und Betriebsstoffen
 	"Skontotyp",
-	# Anzahlungen
+	# Allgemeine Bezeichnung, des Auftrags / Projekts.
 	"Auftragsnummer",
+	# AA = Angeforderte Anzahlung / Abschlagsrechnung
+	# AG = Erhaltene Anzahlung (Geldeingang)
+	# AV = Erhaltene Anzahlung (Verbindlichkeit)
+	# SR = Schlussrechnung
+	# SU = Schlussrechnung (Umbuchung)
+	# SG = Schlussrechnung (Geldeingang)
+	# SO = Sonstige
 	"Buchungstyp",
 	"USt-Schlüssel (Anzahlungen)",
-	"EU-Land (Anzahlungen)",
+	"EU-Mitgliedstaat (Anzahlungen)",
 	"Sachverhalt L+L (Anzahlungen)",
 	"EU-Steuersatz (Anzahlungen)",
 	"Erlöskonto (Anzahlungen)",
-	# Stapelinformationen
+	# Wird beim Import durch SV (Stapelverarbeitung) ersetzt.
 	"Herkunft-Kz",
-	# Technische Identifikation
-	"Buchungs GUID",
-	# Kostenrechnung
-	"Kost-Datum",
-	# OPOS-Informationen
+	# Wird von DATEV verwendet.
+	"Leerfeld",
+	# Format TTMMJJJJ
+	"KOST-Datum",
+	# Vom Zahlungsempfänger individuell vergebenes Kennzeichen eines Mandats
+	# (z.B. Rechnungs- oder Kundennummer).
 	"SEPA-Mandatsreferenz",
+	# 1 = Skontosperre
+	# 0 = Keine Skontosperre
 	"Skontosperre",
 	# Gesellschafter und Sonderbilanzsachverhalt
 	"Gesellschaftername",
+	# Amtliche Nummer aus der Feststellungserklärung
 	"Beteiligtennummer",
 	"Identifikationsnummer",
 	"Zeichnernummer",
-	# OPOS-Informationen
+	# Format TTMMJJJJ
 	"Postensperre bis",
 	# Gesellschafter und Sonderbilanzsachverhalt
 	"Bezeichnung SoBil-Sachverhalt",
 	"Kennzeichen SoBil-Buchung",
-	# Stapelinformationen
+	# 0 = keine Festschreibung
+	# 1 = Festschreibung
 	"Festschreibung",
-	# Datum
+	# Format TTMMJJJJ
 	"Leistungsdatum",
+	# Format TTMMJJJJ
 	"Datum Zuord. Steuerperiode",
-	# OPOS-Informationen
+	# OPOS-Informationen, Format TTMMJJJJ
 	"Fälligkeit",
-	# Konto/Gegenkonto
+	# G oder 1 = Generalumkehr
+	# 0 = keine Generalumkehr
 	"Generalumkehr (GU)",
 	# Steuersatz für Steuerschlüssel
 	"Steuersatz",
+	# Beispiel: DE für Deutschland
 	"Land"
 ]
 
@@ -439,8 +472,8 @@
 		"fieldtype": "Data",
 	},
 	{
-		"label": "Kontonummer",
-		"fieldname": "Kontonummer",
+		"label": "Konto",
+		"fieldname": "Konto",
 		"fieldtype": "Data",
 	},
 	{
@@ -454,27 +487,22 @@
 		"fieldtype": "Date",
 	},
 	{
+		"label": "Belegfeld 1",
+		"fieldname": "Belegfeld 1",
+		"fieldtype": "Data",
+	},
+	{
 		"label": "Buchungstext",
 		"fieldname": "Buchungstext",
 		"fieldtype": "Text",
 	},
 	{
 		"label": "Beleginfo - Art 1",
-		"fieldname": "Beleginfo - Art 1",
-		"fieldtype": "Data",
-	},
-	{
-		"label": "Beleginfo - Inhalt 1",
-		"fieldname": "Beleginfo - Inhalt 1",
-		"fieldtype": "Data",
-	},
-	{
-		"label": "Beleginfo - Art 2",
 		"fieldname": "Beleginfo - Art 2",
 		"fieldtype": "Data",
 	},
 	{
-		"label": "Beleginfo - Inhalt 2",
+		"label": "Beleginfo - Inhalt 1",
 		"fieldname": "Beleginfo - Inhalt 2",
 		"fieldtype": "Data",
 	}
@@ -499,14 +527,17 @@
 class Transactions():
 	DATA_CATEGORY = DataCategory.TRANSACTIONS
 	FORMAT_NAME = FormatName.TRANSACTIONS
+	FORMAT_VERSION = "9"
 	COLUMNS = TRANSACTION_COLUMNS
 
 class DebtorsCreditors():
 	DATA_CATEGORY = DataCategory.DEBTORS_CREDITORS
 	FORMAT_NAME = FormatName.DEBTORS_CREDITORS
+	FORMAT_VERSION = "5"
 	COLUMNS = DEBTOR_CREDITOR_COLUMNS
 
 class AccountNames():
 	DATA_CATEGORY = DataCategory.ACCOUNT_NAMES
 	FORMAT_NAME = FormatName.ACCOUNT_NAMES
+	FORMAT_VERSION = "2"
 	COLUMNS = ACCOUNT_NAME_COLUMNS
diff --git a/erpnext/selling/doctype/customer/customer.json b/erpnext/selling/doctype/customer/customer.json
index 89ce325..df563ee 100644
--- a/erpnext/selling/doctype/customer/customer.json
+++ b/erpnext/selling/doctype/customer/customer.json
@@ -208,8 +208,7 @@
    "fieldtype": "Link",
    "ignore_user_permissions": 1,
    "label": "Represents Company",
-   "options": "Company",
-   "unique": 1
+   "options": "Company"
   },
   {
    "depends_on": "represents_company",
diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py
index 7f2fe60..9261289 100644
--- a/erpnext/selling/doctype/customer/customer.py
+++ b/erpnext/selling/doctype/customer/customer.py
@@ -213,6 +213,9 @@
 
 	def create_onboarding_docs(self, args):
 		defaults = frappe.defaults.get_defaults()
+		company = defaults.get('company') or \
+			frappe.db.get_single_value('Global Defaults', 'default_company')
+
 		for i in range(1, args.get('max_count')):
 			customer = args.get('customer_name_' + str(i))
 			if customer:
@@ -223,7 +226,7 @@
 						'customer_type': 'Company',
 						'customer_group': _('Commercial'),
 						'territory': defaults.get('country'),
-						'company': defaults.get('company')
+						'company': company
 					}).insert()
 
 					if args.get('customer_email_' + str(i)):
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.js b/erpnext/stock/doctype/delivery_note/delivery_note.js
index 67e8bd2..f8608d8 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.js
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.js
@@ -92,6 +92,15 @@
 			}, __('Create'));
 			frm.page.set_inner_btn_group_as_primary(__('Create'));
 		}
+
+		if (frm.doc.docstatus === 1 && frm.doc.is_internal_customer && !frm.doc.inter_company_reference) {
+			frm.add_custom_button(__('Purchase Receipt'), function() {
+				frappe.model.open_mapped_doc({
+					method: 'erpnext.stock.doctype.delivery_note.delivery_note.make_inter_company_purchase_receipt',
+					frm: frm,
+				})
+			}, __('Create'));
+		}
 	},
 
 	to_warehouse: function(frm) {
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.json b/erpnext/stock/doctype/delivery_note/delivery_note.json
index 86200ba..6f9d83d 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.json
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.json
@@ -115,6 +115,8 @@
   "campaign",
   "source",
   "column_break5",
+  "is_internal_customer",
+  "inter_company_reference",
   "per_billed",
   "customer_group",
   "territory",
@@ -1234,13 +1236,27 @@
   {
    "fieldname": "section_break_18",
    "fieldtype": "Section Break"
+  },
+  {
+   "default": "0",
+   "fetch_from": "customer.is_internal_customer",
+   "fieldname": "is_internal_customer",
+   "fieldtype": "Check",
+   "label": "Is Internal Customer",
+   "read_only": 1
+  },
+  {
+   "fieldname": "inter_company_reference",
+   "fieldtype": "Link",
+   "label": "Inter Company Reference",
+   "options": "Purchase Receipt"
   }
  ],
  "icon": "fa fa-truck",
  "idx": 146,
  "is_submittable": 1,
  "links": [],
- "modified": "2019-12-30 19:17:13.122644",
+ "modified": "2019-12-31 19:17:13.122644",
  "modified_by": "Administrator",
  "module": "Stock",
  "name": "Delivery Note",
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py
index 013d50a..ea94c7b 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.py
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.py
@@ -14,6 +14,7 @@
 from frappe.model.mapper import get_mapped_doc
 from frappe.model.utils import get_fetch_values
 from frappe.utils import cint, flt
+from erpnext.controllers.accounts_controller import get_taxes_and_charges
 
 form_grid_templates = {
 	"items": "templates/form_grid/item_grid.html"
@@ -587,3 +588,77 @@
 def update_delivery_note_status(docname, status):
 	dn = frappe.get_doc("Delivery Note", docname)
 	dn.update_status(status)
+
+@frappe.whitelist()
+def make_inter_company_purchase_receipt(source_name, target_doc=None):
+	return make_inter_company_transaction("Delivery Note", source_name, target_doc)
+
+def make_inter_company_transaction(doctype, source_name, target_doc=None):
+	from erpnext.accounts.doctype.sales_invoice.sales_invoice import validate_inter_company_transaction, get_inter_company_details
+
+	if doctype == 'Delivery Note':
+		source_doc = frappe.get_doc(doctype, source_name)
+		target_doctype = "Purchase Receipt"
+		source_document_warehouse_field = 'target_warehouse'
+		target_document_warehouse_field = 'from_warehouse'
+	else:
+		source_doc = frappe.get_doc(doctype, source_name)
+		target_doctype = 'Delivery Note'
+		source_document_warehouse_field = 'from_warehouse'
+		target_document_warehouse_field = 'target_warehouse'
+
+	validate_inter_company_transaction(source_doc, doctype)
+	details = get_inter_company_details(source_doc, doctype)
+
+	def set_missing_values(source, target):
+		target.run_method("set_missing_values")
+
+		if target.doctype == 'Purchase Receipt':
+			master_doctype = 'Purchase Taxes and Charges Template'
+		else:
+			master_doctype = 'Sales Taxes and Charges Template'
+
+		if not target.get('taxes') and target.get('taxes_and_charges'):
+			for tax in get_taxes_and_charges(master_doctype, target.get('taxes_and_charges')):
+				target.append('taxes', tax)
+
+	def update_details(source_doc, target_doc, source_parent):
+		target_doc.inter_company_invoice_reference = source_doc.name
+		if target_doc.doctype == 'Purchase Receipt':
+			target_doc.company = details.get("company")
+			target_doc.supplier = details.get("party")
+			target_doc.supplier_address = source_doc.company_address
+			target_doc.shipping_address = source_doc.shipping_address_name or source_doc.customer_address
+			target_doc.buying_price_list = source_doc.selling_price_list
+			target_doc.is_internal_supplier = 1
+			target_doc.inter_company_reference = source_doc.name
+		else:
+			target_doc.company = details.get("company")
+			target_doc.customer = details.get("party")
+			target_doc.company_address = source_doc.supplier_address
+			target_doc.shipping_address_name = source_doc.shipping_address
+			target_doc.selling_price_list = source_doc.buying_price_list
+			target_doc.is_internal_customer = 1
+			target_doc.inter_company_reference = source_doc.name
+
+	doclist = get_mapped_doc(doctype, source_name,	{
+		doctype: {
+			"doctype": target_doctype,
+			"postprocess": update_details,
+			"field_no_map": [
+				"taxes_and_charges"
+			]
+		},
+		doctype +" Item": {
+			"doctype": target_doctype + " Item",
+			"field_map": {
+				source_document_warehouse_field: target_document_warehouse_field
+			},
+			"field_no_map": [
+				"warehouse"
+			]
+		}
+
+	}, target_doc, set_missing_values)
+
+	return doclist
diff --git a/erpnext/stock/doctype/delivery_note/regional/india.js b/erpnext/stock/doctype/delivery_note/regional/india.js
index 22f4716..0c1ca5c 100644
--- a/erpnext/stock/doctype/delivery_note/regional/india.js
+++ b/erpnext/stock/doctype/delivery_note/regional/india.js
@@ -2,3 +2,22 @@
 
 erpnext.setup_auto_gst_taxation('Delivery Note');
 
+frappe.ui.form.on('Delivery Note', {
+    refresh: function(frm) {
+        if(frm.doc.docstatus == 1 && !frm.is_dirty() && !frm.doc.ewaybill) {
+			frm.add_custom_button('E-Way Bill JSON', () => {
+				var w = window.open(
+					frappe.urllib.get_full_url(
+						"/api/method/erpnext.regional.india.utils.generate_ewb_json?"
+						+ "dt=" + encodeURIComponent(frm.doc.doctype)
+						+ "&dn=" + encodeURIComponent(frm.doc.name)
+					)
+				);
+				if (!w) {
+					frappe.msgprint(__("Please enable pop-ups")); return;
+				}
+			}, __("Create"));
+		}
+    }
+})
+
diff --git a/erpnext/stock/doctype/item/item.js b/erpnext/stock/doctype/item/item.js
index dd3248b..735f35f 100644
--- a/erpnext/stock/doctype/item/item.js
+++ b/erpnext/stock/doctype/item/item.js
@@ -137,7 +137,7 @@
 	},
 
 	gst_hsn_code: function(frm) {
-		if(!frm.doc.taxes || !frm.doc.taxes.length) {
+		if((!frm.doc.taxes || !frm.doc.taxes.length) && frm.doc.gst_hsn_code) {
 			frappe.db.get_doc("GST HSN Code", frm.doc.gst_hsn_code).then(hsn_doc => {
 				$.each(hsn_doc.taxes || [], function(i, tax) {
 					let a = frappe.model.add_child(cur_frm.doc, 'Item Tax', 'taxes');
diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py
index d036a0a..a2a913a 100644
--- a/erpnext/stock/doctype/item/item.py
+++ b/erpnext/stock/doctype/item/item.py
@@ -877,14 +877,16 @@
 				frappe.msgprint(msg=_("You have to enable auto re-order in Stock Settings to maintain re-order levels."), title=_("Enable Auto Re-Order"), indicator="orange")
 
 	def create_onboarding_docs(self, args):
-		defaults = frappe.defaults.get_defaults()
+		company = frappe.defaults.get_defaults().get('company') or \
+			frappe.db.get_single_value('Global Defaults', 'default_company')
+
 		for i in range(1, args.get('max_count')):
 			item = args.get('item_' + str(i))
 			if item:
 				default_warehouse = ''
 				default_warehouse = frappe.db.get_value('Warehouse', filters={
 					'warehouse_name': _('Finished Goods'),
-					'company': defaults.get('company_name')
+					'company': company
 				})
 
 				try:
@@ -901,7 +903,7 @@
 						'stock_uom': _(args.get('item_uom_' + str(i))),
 						'item_defaults': [{
 							'default_warehouse': default_warehouse,
-							'company': defaults.get('company_name')
+							'company': company
 						}]
 					}).insert()
 
@@ -909,7 +911,7 @@
 					pass
 				else:
 					if args.get('item_price_' + str(i)):
-						item_price = flt(args.get('tem_price_' + str(i)))
+						item_price = flt(args.get('item_price_' + str(i)))
 
 						price_list_name = frappe.db.get_value('Price List', {'selling': 1})
 						make_item_price(item, price_list_name, item_price)
diff --git a/erpnext/stock/doctype/material_request/material_request.py b/erpnext/stock/doctype/material_request/material_request.py
index 941f904..4542847 100644
--- a/erpnext/stock/doctype/material_request/material_request.py
+++ b/erpnext/stock/doctype/material_request/material_request.py
@@ -6,6 +6,7 @@
 
 from __future__ import unicode_literals
 import frappe
+import json
 
 from frappe.utils import cstr, flt, getdate, new_line_sep, nowdate, add_days
 from frappe import msgprint, _
@@ -329,17 +330,13 @@
 	return doclist
 
 @frappe.whitelist()
-def make_purchase_order_based_on_supplier(source_name, target_doc=None):
-	if target_doc:
-		if isinstance(target_doc, string_types):
-			import json
-			target_doc = frappe.get_doc(json.loads(target_doc))
-		target_doc.set("items", [])
+def make_purchase_order_based_on_supplier(source_name, target_doc=None, args=None):
+	mr = source_name
 
-	material_requests, supplier_items = get_material_requests_based_on_supplier(source_name)
+	supplier_items = get_items_based_on_default_supplier(args.get("supplier"))
 
 	def postprocess(source, target_doc):
-		target_doc.supplier = source_name
+		target_doc.supplier = args.get("supplier")
 		if getdate(target_doc.schedule_date) < getdate(nowdate()):
 			target_doc.schedule_date = None
 		target_doc.set("items", [d for d in target_doc.get("items")
@@ -347,44 +344,64 @@
 
 		set_missing_values(source, target_doc)
 
-	for mr in material_requests:
-		target_doc = get_mapped_doc("Material Request", mr, 	{
-			"Material Request": {
-				"doctype": "Purchase Order",
-			},
-			"Material Request Item": {
-				"doctype": "Purchase Order Item",
-				"field_map": [
-					["name", "material_request_item"],
-					["parent", "material_request"],
-					["uom", "stock_uom"],
-					["uom", "uom"]
-				],
-				"postprocess": update_item,
-				"condition": lambda doc: doc.ordered_qty < doc.qty
-			}
-		}, target_doc, postprocess)
+	target_doc = get_mapped_doc("Material Request", mr, {
+		"Material Request": {
+			"doctype": "Purchase Order",
+		},
+		"Material Request Item": {
+			"doctype": "Purchase Order Item",
+			"field_map": [
+				["name", "material_request_item"],
+				["parent", "material_request"],
+				["uom", "stock_uom"],
+				["uom", "uom"]
+			],
+			"postprocess": update_item,
+			"condition": lambda doc: doc.ordered_qty < doc.qty
+		}
+	}, target_doc, postprocess)
 
 	return target_doc
 
-def get_material_requests_based_on_supplier(supplier):
+@frappe.whitelist()
+def get_items_based_on_default_supplier(supplier):
 	supplier_items = [d.parent for d in frappe.db.get_all("Item Default",
-		{"default_supplier": supplier}, 'parent')]
+		{"default_supplier": supplier, "parenttype": "Item"}, 'parent')]
+
+	return supplier_items
+
+@frappe.whitelist()
+def get_material_requests_based_on_supplier(doctype, txt, searchfield, start, page_len, filters):
+	conditions = ""
+	if txt:
+		conditions += "and mr.name like '%%"+txt+"%%' "
+
+	if filters.get("transaction_date"):
+		date = filters.get("transaction_date")[1]
+		conditions += "and mr.transaction_date between '{0}' and '{1}' ".format(date[0], date[1])
+
+	supplier = filters.get("supplier")
+	supplier_items = get_items_based_on_default_supplier(supplier)
+
 	if not supplier_items:
 		frappe.throw(_("{0} is not the default supplier for any items.").format(supplier))
 
-	material_requests = frappe.db.sql_list("""select distinct mr.name
+	material_requests = frappe.db.sql("""select distinct mr.name, transaction_date,company
 		from `tabMaterial Request` mr, `tabMaterial Request Item` mr_item
 		where mr.name = mr_item.parent
-			and mr_item.item_code in (%s)
+			and mr_item.item_code in ({0})
 			and mr.material_request_type = 'Purchase'
 			and mr.per_ordered < 99.99
 			and mr.docstatus = 1
 			and mr.status != 'Stopped'
-		order by mr_item.item_code ASC""" % ', '.join(['%s']*len(supplier_items)),
-		tuple(supplier_items))
+			and mr.company = '{1}'
+			{2}
+		order by mr_item.item_code ASC
+		limit {3} offset {4} """ \
+		.format(', '.join(['%s']*len(supplier_items)), filters.get("company"), conditions, page_len, start),
+		tuple(supplier_items), as_dict=1)
 
-	return material_requests, supplier_items
+	return material_requests
 
 def get_default_supplier_query(doctype, txt, searchfield, start, page_len, filters):
 	doc = frappe.get_doc("Material Request", filters.get("doc"))
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js
index 6b5e40e..f3020e0 100644
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js
@@ -22,7 +22,7 @@
 				frappe.set_route("Form", lcv.doctype, lcv.name);
 			},
 		}
-		
+
 		frm.custom_make_buttons = {
 			'Stock Entry': 'Return',
 			'Purchase Invoice': 'Invoice'
@@ -40,7 +40,7 @@
 				filters: {'company': frm.doc.company }
 			}
 		});
-		
+
 	},
 	onload: function(frm) {
 		erpnext.queries.setup_queries(frm, "Warehouse", function() {
@@ -62,6 +62,15 @@
 			}, __('Create'));
 			frm.page.set_inner_btn_group_as_primary(__('Create'));
 		}
+
+		if (frm.doc.docstatus === 1 && frm.doc.is_internal_supplier && !frm.doc.inter_company_reference) {
+			frm.add_custom_button(__('Delivery Note'), function() {
+				frappe.model.open_mapped_doc({
+					method: 'erpnext.stock.doctype.purchase_receipt.purchase_receipt.make_inter_company_delivery_note',
+					frm: cur_frm,
+				})
+			}, __('Create'));
+		}
 	},
 
 	company: function(frm) {
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json
index 63ef7ca..35446ec 100755
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json
@@ -106,6 +106,8 @@
   "range",
   "column_break4",
   "per_billed",
+  "is_internal_supplier",
+  "inter_company_reference",
   "subscription_detail",
   "auto_repeat",
   "printing_settings",
@@ -1053,6 +1055,21 @@
    "oldfieldtype": "Date",
    "print_width": "100px",
    "width": "100px"
+  },
+  {
+   "default": "0",
+   "fetch_from": "supplier.is_internal_supplier",
+   "fieldname": "is_internal_supplier",
+   "fieldtype": "Check",
+   "label": "Is Internal Supplier",
+   "read_only": 1
+  },
+  {
+   "fieldname": "inter_company_reference",
+   "fieldtype": "Link",
+   "label": "Inter Company Reference",
+   "options": "Delivery Note",
+   "read_only": 1
   }
  ],
  "icon": "fa fa-truck",
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
index fb123b9..3b43690 100644
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
@@ -17,6 +17,7 @@
 from erpnext.assets.doctype.asset.asset import get_asset_account, is_cwip_accounting_enabled
 from erpnext.assets.doctype.asset_category.asset_category import get_asset_category_account
 from six import iteritems
+from erpnext.stock.doctype.delivery_note.delivery_note import make_inter_company_transaction
 
 form_grid_templates = {
 	"items": "templates/form_grid/item_grid.html"
@@ -223,6 +224,7 @@
 
 					if not stock_value_diff:
 						continue
+
 					gl_entries.append(self.get_gl_dict({
 						"account": warehouse_account[d.warehouse]["account"],
 						"against": stock_rbnb,
@@ -231,17 +233,23 @@
 						"debit": stock_value_diff
 					}, warehouse_account[d.warehouse]["account_currency"], item=d))
 
-					# stock received but not billed
-					stock_rbnb_currency = get_account_currency(stock_rbnb)
+					# GL Entry for from warehouse or Stock Received but not billed
+					# Intentionally passed negative debit amount to avoid incorrect GL Entry validation
+					credit_currency = get_account_currency(warehouse_account[d.from_warehouse]['account']) \
+						if d.from_warehouse else get_account_currency(stock_rbnb)
+
+					credit_amount = flt(d.base_net_amount, d.precision("base_net_amount")) \
+						if credit_currency == self.company_currency else flt(d.net_amount, d.precision("net_amount"))
+
 					gl_entries.append(self.get_gl_dict({
-						"account": stock_rbnb,
+						"account":  warehouse_account[d.from_warehouse]['account'] \
+							if d.from_warehouse else stock_rbnb,
 						"against": warehouse_account[d.warehouse]["account"],
 						"cost_center": d.cost_center,
 						"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
-						"credit": flt(d.base_net_amount, d.precision("base_net_amount")),
-						"credit_in_account_currency": flt(d.base_net_amount, d.precision("base_net_amount")) \
-							if stock_rbnb_currency==self.company_currency else flt(d.net_amount, d.precision("net_amount"))
-					}, stock_rbnb_currency, item=d))
+						"debit": -1 * flt(d.base_net_amount, d.precision("base_net_amount")),
+						"debit_in_account_currency": -1 * credit_amount
+					}, credit_currency, item=d))
 
 					negative_expense_to_be_booked += flt(d.item_tax_amount)
 
@@ -287,7 +295,7 @@
 							"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
 							"debit": divisional_loss,
 							"project": d.project
-						}, stock_rbnb_currency, item=d))
+						}, credit_currency, item=d))
 
 				elif d.warehouse not in warehouse_with_no_account or \
 					d.rejected_warehouse not in warehouse_with_no_account:
@@ -610,6 +618,10 @@
 
 	return doclist
 
+@frappe.whitelist()
+def make_inter_company_delivery_note(source_name, target_doc=None):
+	return make_inter_company_transaction("Purchase Receipt", source_name, target_doc)
+
 def get_item_account_wise_additional_cost(purchase_document):
 	landed_cost_vouchers = frappe.get_all("Landed Cost Purchase Receipt", fields=["parent"],
 		filters = {"receipt_document": purchase_document, "docstatus": 1})
diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
index 6113ee6..253d5f0 100644
--- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
+++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
@@ -450,6 +450,83 @@
 		self.assertEquals(pi2.items[0].qty, 2)
 		self.assertEquals(pi2.items[1].qty, 1)
 
+	def test_stock_transfer_from_purchase_receipt(self):
+		set_perpetual_inventory(1)
+		pr = make_purchase_receipt(do_not_save=1)
+		pr.supplier_warehouse = ''
+		pr.items[0].from_warehouse = '_Test Warehouse 2 - _TC'
+
+		pr.submit()
+
+		gl_entries = get_gl_entries('Purchase Receipt', pr.name)
+		sl_entries = get_sl_entries('Purchase Receipt', pr.name)
+
+		self.assertFalse(gl_entries)
+
+		expected_sle = {
+			'_Test Warehouse 2 - _TC': -5,
+			'_Test Warehouse - _TC': 5
+		}
+
+		for sle in sl_entries:
+			self.assertEqual(expected_sle[sle.warehouse], sle.actual_qty)
+
+		set_perpetual_inventory(0)
+
+	def test_stock_transfer_from_purchase_receipt_with_valuation(self):
+		set_perpetual_inventory(1)
+		warehouse = frappe.get_doc('Warehouse', '_Test Warehouse 2 - _TC')
+		warehouse.account = '_Test Account Stock In Hand - _TC'
+		warehouse.save()
+
+		pr = make_purchase_receipt(do_not_save=1)
+		pr.items[0].from_warehouse = '_Test Warehouse 2 - _TC'
+		pr.supplier_warehouse = ''
+
+
+		pr.append('taxes', {
+			'charge_type': 'On Net Total',
+			'account_head': '_Test Account Shipping Charges - _TC',
+			'category': 'Valuation and Total',
+			'cost_center': 'Main - _TC',
+			'description': 'Test',
+			'rate': 9
+		})
+
+		pr.submit()
+
+		gl_entries = get_gl_entries('Purchase Receipt', pr.name)
+		sl_entries = get_sl_entries('Purchase Receipt', pr.name)
+
+		expected_gle = [
+			['Stock In Hand - _TC', 272.5, 0.0],
+			['_Test Account Stock In Hand - _TC', 0.0, 250.0],
+			['_Test Account Shipping Charges - _TC', 0.0, 22.5]
+		]
+
+		expected_sle = {
+			'_Test Warehouse 2 - _TC': -5,
+			'_Test Warehouse - _TC': 5
+		}
+
+		for sle in sl_entries:
+			self.assertEqual(expected_sle[sle.warehouse], sle.actual_qty)
+
+		for i, gle in enumerate(gl_entries):
+			self.assertEqual(gle.account, expected_gle[i][0])
+			self.assertEqual(gle.debit, expected_gle[i][1])
+			self.assertEqual(gle.credit, expected_gle[i][2])
+
+		warehouse.account = ''
+		warehouse.save()
+		set_perpetual_inventory(0)
+
+
+def get_sl_entries(voucher_type, voucher_no):
+	return frappe.db.sql(""" select actual_qty, warehouse, stock_value_difference
+		from `tabStock Ledger Entry` where voucher_type=%s and voucher_no=%s
+		order by posting_time desc""", (voucher_type, voucher_no), as_dict=1)
+
 def get_gl_entries(voucher_type, voucher_no):
 	return frappe.db.sql("""select account, debit, credit, cost_center
 		from `tabGL Entry` where voucher_type=%s and voucher_no=%s
diff --git a/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json b/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json
index 16ec8db..bfb7577 100644
--- a/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json
+++ b/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json
@@ -1,4 +1,5 @@
 {
+ "actions": [],
  "autoname": "hash",
  "creation": "2013-05-24 19:29:10",
  "doctype": "DocType",
@@ -67,6 +68,7 @@
   "warehouse_and_reference",
   "warehouse",
   "rejected_warehouse",
+  "from_warehouse",
   "purchase_order",
   "material_request",
   "column_break_40",
@@ -815,15 +817,23 @@
    "fetch_from": "item_code.asset_category",
    "fieldname": "asset_category",
    "fieldtype": "Link",
-   "in_preview": 1,
    "label": "Asset Category",
    "options": "Asset Category",
    "read_only": 1
+  },
+  {
+   "fieldname": "from_warehouse",
+   "fieldtype": "Link",
+   "hidden": 1,
+   "ignore_user_permissions": 1,
+   "label": "Supplier Warehouse",
+   "options": "Warehouse"
   }
  ],
  "idx": 1,
  "istable": 1,
- "modified": "2019-10-14 16:03:25.499557",
+ "links": [],
+ "modified": "2020-01-13 16:03:34.879827",
  "modified_by": "Administrator",
  "module": "Stock",
  "name": "Purchase Receipt Item",
diff --git a/erpnext/stock/doctype/stock_settings/stock_settings.js b/erpnext/stock/doctype/stock_settings/stock_settings.js
index 49ce3d8..cc0e2cf 100644
--- a/erpnext/stock/doctype/stock_settings/stock_settings.js
+++ b/erpnext/stock/doctype/stock_settings/stock_settings.js
@@ -3,6 +3,15 @@
 
 frappe.ui.form.on('Stock Settings', {
 	refresh: function(frm) {
+		let filters = function() {
+			return {
+				filters : {
+					is_group : 0
+				}
+			};
+		};
 
+		frm.set_query("default_warehouse", filters);
+		frm.set_query("sample_retention_warehouse", filters);
 	}
 });
diff --git a/erpnext/stock/doctype/stock_settings/stock_settings.py b/erpnext/stock/doctype/stock_settings/stock_settings.py
index 65de2e5..93b5eee 100644
--- a/erpnext/stock/doctype/stock_settings/stock_settings.py
+++ b/erpnext/stock/doctype/stock_settings/stock_settings.py
@@ -30,9 +30,17 @@
 			frappe.make_property_setter({'fieldname': name, 'property': 'hidden',
 				'value': 0 if self.show_barcode_field else 1})
 
+		self.validate_warehouses()
 		self.cant_change_valuation_method()
 		self.validate_clean_description_html()
 
+	def validate_warehouses(self):
+		warehouse_fields = ["default_warehouse", "sample_retention_warehouse"]
+		for field in warehouse_fields:
+			if frappe.db.get_value("Warehouse", self.get(field), "is_group"):
+				frappe.throw(_("Group Warehouses cannot be used in transactions. Please change the value of {0}") \
+					.format(frappe.bold(self.meta.get_field(field).label)), title =_("Incorrect Warehouse"))
+
 	def cant_change_valuation_method(self):
 		db_valuation_method = frappe.db.get_single_value("Stock Settings", "valuation_method")
 
diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py
index d0efaa2..53964f2 100644
--- a/erpnext/stock/get_item_details.py
+++ b/erpnext/stock/get_item_details.py
@@ -973,6 +973,7 @@
 		if bom:
 			return bom
 
+@frappe.whitelist()
 def get_valuation_rate(item_code, company, warehouse=None):
 	item = get_item_defaults(item_code, company)
 	item_group = get_item_group_defaults(item_code, company)
diff --git a/erpnext/support/doctype/issue/issue.json b/erpnext/support/doctype/issue/issue.json
index 222554b..53af80c 100644
--- a/erpnext/support/doctype/issue/issue.json
+++ b/erpnext/support/doctype/issue/issue.json
@@ -1,4 +1,5 @@
 {
+ "actions": [],
  "allow_import": 1,
  "allow_rename": 1,
  "autoname": "naming_series:",
@@ -119,6 +120,7 @@
    "default": "Medium",
    "fieldname": "priority",
    "fieldtype": "Link",
+   "in_list_view": 1,
    "in_standard_filter": 1,
    "label": "Priority",
    "options": "Issue Priority"
@@ -363,8 +365,9 @@
  ],
  "icon": "fa fa-ticket",
  "idx": 7,
- "modified": "2019-09-11 09:03:57.465623",
- "modified_by": "himanshu@erpnext.com",
+ "links": [],
+ "modified": "2020-02-18 21:26:35.636013",
+ "modified_by": "Administrator",
  "module": "Support",
  "name": "Issue",
  "owner": "Administrator",
diff --git a/erpnext/templates/includes/projects/project_row.html b/erpnext/templates/includes/projects/project_row.html
index 55b02e2..73c83ef 100644
--- a/erpnext/templates/includes/projects/project_row.html
+++ b/erpnext/templates/includes/projects/project_row.html
@@ -1,6 +1,6 @@
 {% if doc.status=="Open" %}
 <div class="web-list-item">
-	<a class="no-decoration" href="/projects?project={{ doc.name }}">
+	<a class="no-decoration" href="/projects?project={{ doc.name | urlencode }}">
 		<div class="row">
 			<div class="col-xs-6">
 
diff --git a/erpnext/utilities/product.py b/erpnext/utilities/product.py
index 1c0d4c3..c23c1f7 100644
--- a/erpnext/utilities/product.py
+++ b/erpnext/utilities/product.py
@@ -129,6 +129,7 @@
 #if item belongs to product bundle, check if bundle items are in stock
 	if frappe.db.exists("Product Bundle", item_code):
 		items = frappe.get_doc("Product Bundle", item_code).get_all_children()
-		return all([ get_qty_in_stock(d.item_code, item_warehouse_field).in_stock for d in items ])
+		bundle_warehouse = frappe.db.get_value('Item', item_code, item_warehouse_field)
+		return all([ get_qty_in_stock(d.item_code, item_warehouse_field, bundle_warehouse).in_stock for d in items ])
 	else:
 		return 1
diff --git a/package.json b/package.json
index 13fcc0f..1b2dc9e 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,21 @@
 {
-  "devdependencies": {
+  "name": "erpnext",
+  "description": "Open Source ERP System powered by the Frappe Framework",
+  "repository": {
+    "type": "git",
+    "url": "git+https://github.com/frappe/erpnext.git"
+  },
+  "homepage": "https://erpnext.com",
+  "author": "Frappe Technologies Pvt. Ltd.",
+  "license": "GPL-3.0",
+  "bugs": {
+    "url": "https://github.com/frappe/erpnext/issues"
+  },
+  "devDependencies": {
     "snyk": "^1.290.1"
   },
+  "dependencies": {
+  },
   "scripts": {
     "snyk-protect": "snyk protect",
     "prepare": "yarn run snyk-protect"