Merge pull request #5340 from rohitwaghchaure/support_week_new

[Fix] Sales Invoice shows default date while no default mentioned
diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
index 91d3ae4..5dacb9b 100644
--- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
@@ -6,7 +6,7 @@
 import unittest
 import frappe
 import frappe.model
-from frappe.utils import cint, flt
+from frappe.utils import cint, flt, today
 import frappe.defaults
 from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory, \
 	test_records as pr_test_records
@@ -412,8 +412,7 @@
 def make_purchase_invoice(**args):
 	pi = frappe.new_doc("Purchase Invoice")
 	args = frappe._dict(args)
-	if args.posting_date:
-		pi.posting_date = args.posting_date
+	pi.posting_date = args.posting_date or today()
 	if args.posting_time:
 		pi.posting_time = args.posting_time
 	if args.update_stock:
diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
index 7208c2a..abc4083 100644
--- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
@@ -955,8 +955,7 @@
 def create_sales_invoice(**args):
 	si = frappe.new_doc("Sales Invoice")
 	args = frappe._dict(args)
-	if args.posting_date:
-		si.posting_date = args.posting_date or nowdate()
+	si.posting_date = args.posting_date or nowdate()
 
 	si.company = args.company or "_Test Company"
 	si.customer = args.customer or "_Test Customer"
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index 2ede901..e6d0ee9 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -81,10 +81,11 @@
 			convert_to_recurring(self, self.get("posting_date") or self.get("transaction_date"))
 
 	def set_missing_values(self, for_validate=False):
-		for fieldname in ["posting_date", "transaction_date"]:
-			if not self.get(fieldname) and self.meta.get_field(fieldname):
-				self.set(fieldname, today())
-				break
+		if frappe.flags.in_test:
+			for fieldname in ["posting_date","transaction_date"]:
+				if self.meta.get_field(fieldname) and not self.get(fieldname):
+					self.set(fieldname, today())
+					break
 
 	def calculate_taxes_and_totals(self):
 		from erpnext.controllers.taxes_and_totals import calculate_taxes_and_totals
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index af651c9..ac266f5 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -87,15 +87,7 @@
 			var today = get_today(),
 				currency = frappe.defaults.get_user_default("currency");
 
-			$.each(["posting_date", "transaction_date"], function(i, fieldname) {
-				if (me.frm.fields_dict[fieldname] && !me.frm.doc[fieldname] && me.frm[fieldname]) {
-					me.frm.set_value(fieldname, me.frm[fieldname]);
-				}
-			});
-
 			$.each({
-				posting_date: today,
-				transaction_date: today,
 				currency: currency,
 				price_list_currency: currency,
 				status: "Draft",
diff --git a/erpnext/stock/doctype/delivery_note/test_delivery_note.py b/erpnext/stock/doctype/delivery_note/test_delivery_note.py
index 699d8b6..f10b981 100644
--- a/erpnext/stock/doctype/delivery_note/test_delivery_note.py
+++ b/erpnext/stock/doctype/delivery_note/test_delivery_note.py
@@ -7,7 +7,7 @@
 import frappe
 import json
 import frappe.defaults
-from frappe.utils import cint, nowdate, nowtime, cstr, add_days, flt
+from frappe.utils import cint, nowdate, nowtime, cstr, add_days, flt, today
 from erpnext.stock.stock_ledger import get_previous_sle
 from erpnext.accounts.utils import get_balance_on
 from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt \
@@ -516,8 +516,7 @@
 def create_delivery_note(**args):
 	dn = frappe.new_doc("Delivery Note")
 	args = frappe._dict(args)
-	if args.posting_date:
-		dn.posting_date = args.posting_date
+	dn.posting_date = args.posting_date or today()
 	if args.posting_time:
 		dn.posting_time = args.posting_time
 
diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
index dc81405..eba9201 100644
--- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
+++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
@@ -6,7 +6,7 @@
 import unittest
 import frappe
 import frappe.defaults
-from frappe.utils import cint, flt, cstr
+from frappe.utils import cint, flt, cstr, today
 from erpnext.stock.doctype.purchase_receipt.purchase_receipt import make_purchase_invoice
 
 class TestPurchaseReceipt(unittest.TestCase):
@@ -193,6 +193,7 @@
 		po = create_purchase_order()
 		
 		pr1 = make_purchase_receipt(po.name)
+		pr1.posting_date = today()
 		pr1.posting_time = "10:00"
 		pr1.get("items")[0].received_qty = 2
 		pr1.get("items")[0].qty = 2
@@ -209,6 +210,7 @@
 		pi2.submit()
 		
 		pr2 = make_purchase_receipt(po.name)
+		pr2.posting_date = today()
 		pr2.posting_time = "08:00"
 		pr2.get("items")[0].received_qty = 5
 		pr2.get("items")[0].qty = 5
@@ -236,8 +238,7 @@
 def make_purchase_receipt(**args):
 	pr = frappe.new_doc("Purchase Receipt")
 	args = frappe._dict(args)
-	if args.posting_date:
-		pr.posting_date = args.posting_date
+	pr.posting_date = args.posting_date or today()
 	if args.posting_time:
 		pr.posting_time = args.posting_time
 	pr.company = args.company or "_Test Company"