Merge pull request #14093 from manassolanki/poc-fixes-1

[ui] more fields in the list view of assets
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index 84367de..5d26d8a 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -352,6 +352,7 @@
 
 		self.make_supplier_gl_entry(gl_entries)
 		self.make_item_gl_entries(gl_entries)
+		self.get_asset_gl_entry(gl_entries)
 		self.make_tax_gl_entries(gl_entries)
 
 		gl_entries = merge_similar_entries(gl_entries)
@@ -389,10 +390,10 @@
 		warehouse_account = get_warehouse_account_map()
 
 		for item in self.get("items"):
-			if flt(item.base_net_amount):
+			if flt(item.base_net_amount) and item.item_code in stock_items:
 				account_currency = get_account_currency(item.expense_account)
 
-				if self.update_stock and self.auto_accounting_for_stock and item.item_code in stock_items:
+				if self.update_stock and self.auto_accounting_for_stock:
 					val_rate_db_precision = 6 if cint(item.precision("valuation_rate")) <= 6 else 9
 
 					# warehouse account
@@ -434,50 +435,6 @@
 							"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
 							"credit": flt(item.rm_supp_cost)
 						}, warehouse_account[self.supplier_warehouse]["account_currency"]))
-
-				elif item.is_fixed_asset:
-					asset_accounts = self.get_company_default(["asset_received_but_not_billed",
-						"expenses_included_in_asset_valuation", "capital_work_in_progress_account"])
-
-					asset_amount = flt(item.net_amount) + flt(item.item_tax_amount/self.conversion_rate)
-					base_asset_amount = flt(item.base_net_amount + item.item_tax_amount)
-
-					if not self.update_stock:
-						asset_rbnb_currency = get_account_currency(asset_accounts[0])
-						gl_entries.append(self.get_gl_dict({
-							"account": asset_accounts[0],
-							"against": self.supplier,
-							"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
-							"debit": base_asset_amount,
-							"debit_in_account_currency": (base_asset_amount
-								if asset_rbnb_currency == self.company_currency else asset_amount)
-						}))
-					else:
-						cwip_account = get_asset_category_account(item.asset,
-							'capital_work_in_progress_account') or asset_accounts[2]
-
-						cwip_account_currency = get_account_currency(cwip_account)
-						gl_entries.append(self.get_gl_dict({
-							"account": cwip_account,
-							"against": self.supplier,
-							"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
-							"debit": base_asset_amount,
-							"debit_in_account_currency": (base_asset_amount
-								if cwip_account_currency == self.company_currency else asset_amount)
-						}))
-
-					if item.item_tax_amount:
-						asset_eiiav_currency = get_account_currency(asset_accounts[0])
-						gl_entries.append(self.get_gl_dict({
-							"account": asset_accounts[1],
-							"against": self.supplier,
-							"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
-							"cost_center": item.cost_center,
-							"credit": item.item_tax_amount,
-							"credit_in_account_currency": (item.item_tax_amount
-								if asset_eiiav_currency == self.company_currency else
-									item.item_tax_amount / self.conversion_rate)
-						}))
 				else:
 					gl_entries.append(
 						self.get_gl_dict({
@@ -513,6 +470,67 @@
 							self.negative_expense_to_be_booked += flt(item.item_tax_amount, \
 								item.precision("item_tax_amount"))
 
+	def get_asset_gl_entry(self, gl_entries):
+		for item in self.get("items"):
+			if item.is_fixed_asset:
+				asset_accounts = self.get_company_default(["asset_received_but_not_billed",
+					"expenses_included_in_asset_valuation", "capital_work_in_progress_account"])
+
+				asset_amount = flt(item.net_amount) + flt(item.item_tax_amount/self.conversion_rate)
+				base_asset_amount = flt(item.base_net_amount + item.item_tax_amount)
+
+				if not self.update_stock:
+					asset_rbnb_currency = get_account_currency(asset_accounts[0])
+					gl_entries.append(self.get_gl_dict({
+						"account": asset_accounts[0],
+						"against": self.supplier,
+						"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
+						"debit": base_asset_amount,
+						"debit_in_account_currency": (base_asset_amount
+							if asset_rbnb_currency == self.company_currency else asset_amount)
+					}))
+
+					if item.item_tax_amount:
+						asset_eiiav_currency = get_account_currency(asset_accounts[0])
+						gl_entries.append(self.get_gl_dict({
+							"account": asset_accounts[1],
+							"against": self.supplier,
+							"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
+							"cost_center": item.cost_center,
+							"credit": item.item_tax_amount,
+							"credit_in_account_currency": (item.item_tax_amount
+								if asset_eiiav_currency == self.company_currency else
+									item.item_tax_amount / self.conversion_rate)
+						}))
+				else:
+					cwip_account = get_asset_category_account(item.asset,
+						'capital_work_in_progress_account') or asset_accounts[2]
+
+					cwip_account_currency = get_account_currency(cwip_account)
+					gl_entries.append(self.get_gl_dict({
+						"account": cwip_account,
+						"against": self.supplier,
+						"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
+						"debit": base_asset_amount,
+						"debit_in_account_currency": (base_asset_amount
+							if cwip_account_currency == self.company_currency else asset_amount)
+					}))
+
+					if item.item_tax_amount and not cint(erpnext.is_perpetual_inventory_enabled(self.company)):
+						asset_eiiav_currency = get_account_currency(asset_accounts[0])
+						gl_entries.append(self.get_gl_dict({
+							"account": asset_accounts[1],
+							"against": self.supplier,
+							"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
+							"cost_center": item.cost_center,
+							"credit": item.item_tax_amount,
+							"credit_in_account_currency": (item.item_tax_amount
+								if asset_eiiav_currency == self.company_currency else
+									item.item_tax_amount / self.conversion_rate)
+						}))
+
+		return gl_entries
+
 	def make_tax_gl_entries(self, gl_entries):
 		# tax table gl entries
 		valuation_tax = {}
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 ef9b2f6..eb77024 100755
--- a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
+++ b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
@@ -2033,6 +2033,39 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "depends_on": "is_fixed_asset", 
+   "fieldname": "asset_location", 
+   "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": "Asset Location", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Location", 
+   "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
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "po_detail", 
    "fieldtype": "Data", 
    "hidden": 1, 
@@ -2258,7 +2291,7 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2018-04-23 14:07:33.576495", 
+ "modified": "2018-05-16 17:50:21.957780", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Purchase Invoice Item", 
diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py
index 55a29bc..e37038a 100644
--- a/erpnext/assets/doctype/asset/asset.py
+++ b/erpnext/assets/doctype/asset/asset.py
@@ -28,6 +28,7 @@
 			self.validate_expected_value_after_useful_life()
 
 	def on_submit(self):
+		self.validate_in_use_date()
 		self.set_status()
 		self.update_stock_movement()
 
@@ -48,6 +49,10 @@
 		elif item.is_stock_item:
 			frappe.throw(_("Item {0} must be a non-stock item").format(self.item_code))
 
+	def validate_in_use_date(self):
+		if not self.available_for_use_date:
+			frappe.throw(_("Available for use data is required"))
+
 	def set_missing_values(self):
 		if not self.asset_category:
 			self.asset_category = frappe.db.get_value("Item", self.item_code, "asset_category")
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index 4802e02..a16047c 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -639,10 +639,10 @@
 						frappe.throw(_("Row #{0}: Asset {1} must be submitted").format(d.idx, d.asset))
 
 					elif self.doctype == "Purchase Invoice":
-						if asset.status != "Submitted":
-							frappe.throw(_("Row #{0}: Asset {1} is already {2}")
-								.format(d.idx, d.asset, asset.status))
-						elif getdate(asset.purchase_date) != getdate(self.posting_date):
+						# if asset.status != "Submitted":
+# 							frappe.throw(_("Row #{0}: Asset {1} is already {2}")
+# 								.format(d.idx, d.asset, asset.status))
+						if getdate(asset.purchase_date) != getdate(self.posting_date):
 							frappe.throw(_("Row #{0}: Posting Date must be same as purchase date {1} of asset {2}").format(d.idx, asset.purchase_date, d.asset))
 						elif asset.is_existing_asset:
 							frappe.throw(_("Row #{0}: Purchase Invoice cannot be made against an existing asset {1}").format(d.idx, d.asset))
diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py
index 8b0ea3e..31c034d 100644
--- a/erpnext/controllers/stock_controller.py
+++ b/erpnext/controllers/stock_controller.py
@@ -33,6 +33,10 @@
 				items, warehouses = self.get_items_and_warehouses()
 				update_gl_entries_after(self.posting_date, self.posting_time, warehouses, items,
 					warehouse_account)
+		elif self.doctype in ['Purchase Receipt', 'Purchase Invoice']:
+			gl_entries = []
+			gl_entries = self.get_asset_gl_entry(gl_entries)
+			make_gl_entries(gl_entries, from_repost=from_repost)
 
 	def get_gl_entries(self, warehouse_account=None, default_expense_account=None,
 			default_cost_center=None):
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js
index c55013e..1a73ae5 100644
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js
@@ -62,9 +62,8 @@
 		this._super();
 		if(this.frm.doc.docstatus===1) {
 			this.show_stock_ledger();
-			if (erpnext.is_perpetual_inventory_enabled(this.frm.doc.company)) {
-				this.show_general_ledger();
-			}
+			//removed for temporary
+			this.show_general_ledger();
 
 			this.frm.add_custom_button(__('Asset'), function() {
 				frappe.route_options = {
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
index 573f7ed..a91d39f 100644
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
@@ -254,40 +254,7 @@
 					d.rejected_warehouse not in warehouse_with_no_account:
 						warehouse_with_no_account.append(d.warehouse)
 
-			elif d.is_fixed_asset:
-				asset_accounts = self.get_company_default(["capital_work_in_progress_account",
-					"asset_received_but_not_billed"])
-
-				# CWIP entry
-				cwip_account = get_asset_category_account(d.asset,
-					'capital_work_in_progress_account') or asset_accounts[0]
-
-				asset_amount = flt(d.net_amount) + flt(d.item_tax_amount/self.conversion_rate)
-				base_asset_amount = flt(d.base_net_amount + d.item_tax_amount)
-
-				cwip_account_currency = get_account_currency(cwip_account)
-				gl_entries.append(self.get_gl_dict({
-					"account": cwip_account,
-					"against": asset_accounts[1],
-					"cost_center": d.cost_center,
-					"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
-					"debit": base_asset_amount,
-					"debit_in_account_currency": (base_asset_amount
-						if cwip_account_currency == self.company_currency else asset_amount)
-				}))
-
-				# Asset received but not billed
-				asset_rbnb_currency = get_account_currency(asset_accounts[1])
-				gl_entries.append(self.get_gl_dict({
-					"account": asset_accounts[1],
-					"against": asset_accounts[0],
-					"cost_center": d.cost_center,
-					"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
-					"credit": base_asset_amount,
-					"credit_in_account_currency": (base_asset_amount
-						if asset_rbnb_currency == self.company_currency else asset_amount)
-				}))
-
+		self.get_asset_gl_entry(gl_entries)
 		# Cost center-wise amount breakup for other charges included for valuation
 		valuation_tax = {}
 		for tax in self.get("taxes"):
@@ -340,6 +307,44 @@
 				"\n".join(warehouse_with_no_account))
 
 		return process_gl_map(gl_entries)
+		
+	def get_asset_gl_entry(self, gl_entries):
+		for d in self.get("items"):
+			if d.is_fixed_asset:
+				asset_accounts = self.get_company_default(["capital_work_in_progress_account",
+					"asset_received_but_not_billed"])
+
+				# CWIP entry
+				cwip_account = get_asset_category_account(d.asset,
+					'capital_work_in_progress_account') or asset_accounts[0]
+
+				asset_amount = flt(d.net_amount) + flt(d.item_tax_amount/self.conversion_rate)
+				base_asset_amount = flt(d.base_net_amount + d.item_tax_amount)
+
+				cwip_account_currency = get_account_currency(cwip_account)
+				gl_entries.append(self.get_gl_dict({
+					"account": cwip_account,
+					"against": asset_accounts[1],
+					"cost_center": d.cost_center,
+					"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
+					"debit": base_asset_amount,
+					"debit_in_account_currency": (base_asset_amount
+						if cwip_account_currency == self.company_currency else asset_amount)
+				}))
+
+				# Asset received but not billed
+				asset_rbnb_currency = get_account_currency(asset_accounts[1])
+				gl_entries.append(self.get_gl_dict({
+					"account": asset_accounts[1],
+					"against": asset_accounts[0],
+					"cost_center": d.cost_center,
+					"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
+					"credit": base_asset_amount,
+					"credit_in_account_currency": (base_asset_amount
+						if asset_rbnb_currency == self.company_currency else asset_amount)
+				}))
+
+		return gl_entries
 
 	def update_status(self, status):
 		self.set_status(update=True, status = status)