Merge pull request #6782 from KanchanChauhan/customerreport-from-crm

[Fix] Customer Addresses and Contacts report fixed for CRM module
diff --git a/erpnext/__init__.py b/erpnext/__init__.py
index fc52f5a..58b7955 100644
--- a/erpnext/__init__.py
+++ b/erpnext/__init__.py
@@ -2,7 +2,7 @@
 from __future__ import unicode_literals
 import frappe
 
-__version__ = '7.1.1'
+__version__ = '7.1.4'
 
 def get_default_company(user=None):
 	'''Get default company for user'''
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py
index 083ba6f..145ed81 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -763,7 +763,8 @@
 	return {
 		"account": account,
 		"balance": account_balance,
-		"party_balance": party_balance
+		"party_balance": party_balance,
+		"account_currency": frappe.db.get_value("Account", account, "account_currency")
 	}
 
 @frappe.whitelist()
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index 1c9bcbc..22de07f 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -305,25 +305,8 @@
 		if not self.grand_total:
 			return
 		
-		self.auto_accounting_for_stock = \
-			cint(frappe.defaults.get_global_default("auto_accounting_for_stock"))
-
-		self.stock_received_but_not_billed = self.get_company_default("stock_received_but_not_billed")
-		self.expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation")
-		self.negative_expense_to_be_booked = 0.0
-		gl_entries = []
-
-
-		self.make_supplier_gl_entry(gl_entries)
-		self.make_item_gl_entries(gl_entries)
-		self.make_tax_gl_entries(gl_entries)
-
-		gl_entries = merge_similar_entries(gl_entries)
-
-		self.make_payment_gl_entries(gl_entries)
-
-		self.make_write_off_gl_entry(gl_entries)
-
+		gl_entries = self.get_gl_entries()
+		
 		if gl_entries:
 			update_outstanding = "No" if (cint(self.is_paid) or self.write_off_account) else "Yes"
 
@@ -342,6 +325,26 @@
 		elif self.docstatus == 2 and cint(self.update_stock) and self.auto_accounting_for_stock:
 			delete_gl_entries(voucher_type=self.doctype, voucher_no=self.name)
 
+	def get_gl_entries(self, warehouse_account=None):
+		self.auto_accounting_for_stock = \
+			cint(frappe.defaults.get_global_default("auto_accounting_for_stock"))
+
+		self.stock_received_but_not_billed = self.get_company_default("stock_received_but_not_billed")
+		self.expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation")
+		self.negative_expense_to_be_booked = 0.0
+		gl_entries = []
+
+
+		self.make_supplier_gl_entry(gl_entries)
+		self.make_item_gl_entries(gl_entries)
+		self.make_tax_gl_entries(gl_entries)
+
+		gl_entries = merge_similar_entries(gl_entries)
+
+		self.make_payment_gl_entries(gl_entries)
+		self.make_write_off_gl_entry(gl_entries)
+		
+		return gl_entries
 
 	def make_supplier_gl_entry(self, gl_entries):
 		if self.grand_total:
diff --git a/erpnext/accounts/page/pos/pos.js b/erpnext/accounts/page/pos/pos.js
index f43a436..4c13fe3 100644
--- a/erpnext/accounts/page/pos/pos.js
+++ b/erpnext/accounts/page/pos/pos.js
@@ -392,7 +392,7 @@
 				if(index < 30){
 					$(frappe.render_template("pos_item", {
 						item_code: obj.name,
-						item_price: format_currency(obj.price_list_rate, obj.currency),
+						item_price: format_currency(obj.price_list_rate, me.frm.doc.currency),
 						item_name: obj.name===obj.item_name ? "" : obj.item_name,
 						item_image: obj.image ? "url('" + obj.image + "')" : null,
 						color: frappe.get_palette(obj.item_name),
diff --git a/erpnext/demo/setup/manufacture.py b/erpnext/demo/setup/manufacture.py
index 8ac2039..24ffd92 100644
--- a/erpnext/demo/setup/manufacture.py
+++ b/erpnext/demo/setup/manufacture.py
@@ -63,7 +63,10 @@
 	for i in items:
 		item = frappe.new_doc('Item')
 		item.update(i)
-		item.default_warehouse = frappe.get_all('Warehouse', filters={'warehouse_name': item.default_warehouse}, limit=1)[0].name
+		if item.default_warehouse:
+			warehouse = frappe.get_all('Warehouse', filters={'warehouse_name': item.default_warehouse}, limit=1)
+			if warehouse:
+				item.default_warehouse = warehouse[0].name
 		item.insert()
 
 def setup_product_bundle():
diff --git a/erpnext/docs/assets/img/accounts/balance_sheet_report.png b/erpnext/docs/assets/img/accounts/balance_sheet_report.png
new file mode 100644
index 0000000..4d6ffdc
--- /dev/null
+++ b/erpnext/docs/assets/img/accounts/balance_sheet_report.png
Binary files differ
diff --git a/erpnext/docs/assets/img/accounts/cash_flow_report.png b/erpnext/docs/assets/img/accounts/cash_flow_report.png
new file mode 100644
index 0000000..33079da
--- /dev/null
+++ b/erpnext/docs/assets/img/accounts/cash_flow_report.png
Binary files differ
diff --git a/erpnext/docs/assets/img/accounts/change-amount.png b/erpnext/docs/assets/img/accounts/change-amount.png
new file mode 100644
index 0000000..33f9c88
--- /dev/null
+++ b/erpnext/docs/assets/img/accounts/change-amount.png
Binary files differ
diff --git a/erpnext/docs/assets/img/accounts/offline-records.png b/erpnext/docs/assets/img/accounts/offline-records.png
new file mode 100644
index 0000000..78bb730
--- /dev/null
+++ b/erpnext/docs/assets/img/accounts/offline-records.png
Binary files differ
diff --git a/erpnext/docs/assets/img/accounts/pos-item.png b/erpnext/docs/assets/img/accounts/pos-item.png
index fb6c1f8..321e8dc 100644
--- a/erpnext/docs/assets/img/accounts/pos-item.png
+++ b/erpnext/docs/assets/img/accounts/pos-item.png
Binary files differ
diff --git a/erpnext/docs/assets/img/accounts/pos-payment.png b/erpnext/docs/assets/img/accounts/pos-payment.png
index 0a0d37f..187e82c 100644
--- a/erpnext/docs/assets/img/accounts/pos-payment.png
+++ b/erpnext/docs/assets/img/accounts/pos-payment.png
Binary files differ
diff --git a/erpnext/docs/assets/img/accounts/profit_n_loss_report.png b/erpnext/docs/assets/img/accounts/profit_n_loss_report.png
new file mode 100644
index 0000000..de2a75f
--- /dev/null
+++ b/erpnext/docs/assets/img/accounts/profit_n_loss_report.png
Binary files differ
diff --git a/erpnext/docs/assets/img/accounts/write-off.png b/erpnext/docs/assets/img/accounts/write-off.png
new file mode 100644
index 0000000..c6896ea
--- /dev/null
+++ b/erpnext/docs/assets/img/accounts/write-off.png
Binary files differ
diff --git a/erpnext/docs/assets/img/articles/price-list.png b/erpnext/docs/assets/img/articles/price-list.png
new file mode 100644
index 0000000..a6982f9
--- /dev/null
+++ b/erpnext/docs/assets/img/articles/price-list.png
Binary files differ
diff --git a/erpnext/docs/assets/img/articles/pricing-rule-invoice.png b/erpnext/docs/assets/img/articles/pricing-rule-invoice.png
new file mode 100644
index 0000000..79d7fa7
--- /dev/null
+++ b/erpnext/docs/assets/img/articles/pricing-rule-invoice.png
Binary files differ
diff --git a/erpnext/docs/assets/img/articles/pricing-rule-margin.png b/erpnext/docs/assets/img/articles/pricing-rule-margin.png
new file mode 100644
index 0000000..66f6050
--- /dev/null
+++ b/erpnext/docs/assets/img/articles/pricing-rule-margin.png
Binary files differ
diff --git a/erpnext/docs/user/manual/en/accounts/chart-of-accounts.md b/erpnext/docs/user/manual/en/accounts/chart-of-accounts.md
index 99760e7..ae6847e 100644
--- a/erpnext/docs/user/manual/en/accounts/chart-of-accounts.md
+++ b/erpnext/docs/user/manual/en/accounts/chart-of-accounts.md
@@ -19,10 +19,19 @@
 be worth the effort. You can also take the help of your accountant to setup
 your Chart of Accounts.
 
-Financial statement of your company is easily viewable in ERPNext. An Example
-of a financial statement is given below:
+Financial statements for your company are easily viewable in ERPNext. You can view financial statements
+such as  Balance Sheet, Profit and Loss statement and Cash flow statement.
 
-<img class="screenshot" alt="Financial Analytics Balance Sheet" src="{{docs_base_url}}/assets/img/accounts/financial-analytics-bl.png">
+An Example of various financial statement are given below:
+
+#### Cash Flow Report
+<img class="screenshot" alt="Cash Flow Report" src="{{docs_base_url}}/assets/img/accounts/cash_flow_report.png">
+
+#### Profit and Loss Report
+<img class="screenshot" alt="Profit and Loss Report" src="{{docs_base_url}}/assets/img/accounts/profit_n_loss_report.png">
+
+#### Balance Sheet Report
+<img class="screenshot" alt="Balance Sheet Report" src="{{docs_base_url}}/assets/img/accounts/balance_sheet_report.png">
 
 To edit your Chart of Accounts in ERPNext go to:
 
diff --git a/erpnext/docs/user/manual/en/accounts/point-of-sale-pos-invoice.md b/erpnext/docs/user/manual/en/accounts/point-of-sale-pos-invoice.md
index 6a697b1..64fa22c 100644
--- a/erpnext/docs/user/manual/en/accounts/point-of-sale-pos-invoice.md
+++ b/erpnext/docs/user/manual/en/accounts/point-of-sale-pos-invoice.md
@@ -69,6 +69,25 @@
 Submit the document to finalise the record. After the document is submitted,
 you can either print or email it directly to the customer.
 
+### Write off Amount
+
+Outstanding amount can be write off from the POS, user has to enter the amount under write off field on the payment screen.
+
+<img class="screenshot" alt="POS Payment" src="{{docs_base_url}}/assets/img/accounts/write-off.png">
+
+System books the write off amount into the ledger which has selected on the POS Profile.
+
+### Change Amount
+
+POS calculate the extra amount paid by the customer, which user can return from the cash account. User has to set the account for the change amount on the POS profile.
+
+<img class="screenshot" alt="POS Payment" src="{{docs_base_url}}/assets/img/accounts/change-amount.png">
+
+### Offline Records
+All the records from the POS stores into the browser's local storegae and sync submitted records after every minute of the interval if system is connected to internet. User can view the offline records by clicking on Menu > View Offline Records
+
+<img class="screenshot" alt="POS Payment" src="{{docs_base_url}}/assets/img/accounts/offline-records.png">
+
 #### Accounting entries (GL Entry) for a Point of Sale:
 
 Debits:
@@ -82,6 +101,7 @@
   * Taxes (liabilities to be paid to the government)
   * Customer (payment)
   * Write Off (optional)
+  * Account for Change Amount (optional)
 
 To see entries after “Submit”, click on “View Ledger”.
 
diff --git a/erpnext/docs/user/manual/en/accounts/pricing-rule.md b/erpnext/docs/user/manual/en/accounts/pricing-rule.md
index 7afcbea..bd3c51a 100644
--- a/erpnext/docs/user/manual/en/accounts/pricing-rule.md
+++ b/erpnext/docs/user/manual/en/accounts/pricing-rule.md
@@ -79,4 +79,31 @@
 
 <img alt="Disable" class="screenshot" src="{{docs_base_url}}/assets/img/articles/pricing-rule-disable.png">
 
+### Add Margin
+
+Using pricing rule user can add margin on the sales transactions
+
+For example :  User want to add 10% margin on the supplier price list at the time of sales
+
+####1. Make Price List
+
+Create price list for supllier and create item price against the price list.
+
+<img alt="Disable" class="screenshot" src="{{docs_base_url}}/assets/img/articles/price-list.png">
+
+
+####2. Make Pricing Rule 
+
+Create pricing rule for the item against which supplier rate has created
+
+<img alt="Disable" class="screenshot" src="{{docs_base_url}}/assets/img/articles/pricing-rule-margin.png">
+
+####2. Make Invoice
+
+System apply the margin rate on the item price on selection of an item.
+
+<img alt="Disable" class="screenshot" src="{{docs_base_url}}/assets/img/articles/pricing-rule-invoice.png">
+
+For more details about pricing rule [Click Here]({{docs_base_url}}/user/manual/en/selling/articles/adding-margin.html)
+
 <!-- markdown -->
\ No newline at end of file
diff --git a/erpnext/docs/user/manual/en/selling/articles/adding-margin.md b/erpnext/docs/user/manual/en/selling/articles/adding-margin.md
index 2a9ddfa..2b2fb09 100644
--- a/erpnext/docs/user/manual/en/selling/articles/adding-margin.md
+++ b/erpnext/docs/user/manual/en/selling/articles/adding-margin.md
@@ -9,7 +9,7 @@
 
 ####Adding Margin in Pricing Rule
 
-<img alt="Adding Margin in Pricing Rule" class="screenshot"  src="{{docs_base_url}}/assets/img/articles/margin-pricing-rule.png">
+<img alt="Adding Margin in Pricing Rule" class="screenshot"  src="{{docs_base_url}}/assets/img/selling/margin-pricing-rule.png">
 
 Total Margin is calculated as follows:
 `Rate = Price List Rate + Margin Rate`
@@ -22,7 +22,7 @@
 
 ####Adding Item Price
 
-<img alt="Adding Margin in Pricing Rule" class="screenshot"  src="{{docs_base_url}}/assets/img/articles/margin-item-price-list.png">
+<img alt="Adding Margin in Pricing Rule" class="screenshot"  src="{{docs_base_url}}/assets/img/selling/margin-item-price-list.png">
 
 2) Apply margin direct on Item: If user wants to apply the margin without pricing rule, they can use this option. In Quotation Item and Sales Order Item, user can select the margin type and rate or amount. The system will calculate the margin and apply it on price list rate to calculate the rate of the product.
 
@@ -34,4 +34,4 @@
 
 ####Adding Margin in Quotation
 
-<img alt="Adding Margin in Quotation" class="screenshot"  src="{{docs_base_url}}/assets/img/articles/margin-quotation-item.png">
+<img alt="Adding Margin in Quotation" class="screenshot"  src="{{docs_base_url}}/assets/img/selling/margin-quotation-item.png">
diff --git a/erpnext/docs/user/videos/index.md b/erpnext/docs/user/videos/index.md
index 071dedb..9a82db5 100644
--- a/erpnext/docs/user/videos/index.md
+++ b/erpnext/docs/user/videos/index.md
@@ -18,7 +18,7 @@
 ---
 
 <h3>
-	<a class="no-decoration" href="https://conf.erpnext.com/2014/videos">Conference Vidoes</a>
+	<a class="no-decoration" href="https://conf.erpnext.com/2014/videos">Conference Videos</a>
 </h3>
 
 <div class="row">
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index e7c9e7c..0414af9 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -342,4 +342,5 @@
 erpnext.patches.v7_1.set_prefered_contact_email
 execute:frappe.db.sql("update `tabSingles` set value = 1 where field = 'unlink_payment_on_cancellation_of_invoice' and doctype = 'Accounts Settings'")
 execute:frappe.db.sql("update `tabStock Entry` set total_amount = null where purpose in('Repack', 'Manufacture')")
-erpnext.patches.v7_1.save_stock_settings
\ No newline at end of file
+erpnext.patches.v7_1.save_stock_settings
+erpnext.patches.v7_0.repost_gle_for_pi_with_update_stock #2016-11-01
\ No newline at end of file
diff --git a/erpnext/patches/v7_0/repost_gle_for_pi_with_update_stock.py b/erpnext/patches/v7_0/repost_gle_for_pi_with_update_stock.py
new file mode 100644
index 0000000..2883a8a
--- /dev/null
+++ b/erpnext/patches/v7_0/repost_gle_for_pi_with_update_stock.py
@@ -0,0 +1,20 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe.utils import cint
+
+def execute():
+	if not cint(frappe.defaults.get_global_default("auto_accounting_for_stock")):
+		return
+
+	for pi in frappe.db.sql("""select name from `tabPurchase Invoice` 
+		where update_stock=1 and docstatus=1  order by posting_date asc""", as_dict=1):
+		
+			frappe.db.sql("""delete from `tabGL Entry` 
+				where voucher_type = 'Purchase Invoice' and voucher_no = %s""", pi.name)
+				
+			pi_doc = frappe.get_doc("Purchase Invoice", pi.name)
+			pi_doc.make_gl_entries(repost_future_gle=False)
+			frappe.db.commit()
\ No newline at end of file
diff --git a/erpnext/projects/doctype/timesheet/timesheet.py b/erpnext/projects/doctype/timesheet/timesheet.py
index 60435bc..9e32b52 100644
--- a/erpnext/projects/doctype/timesheet/timesheet.py
+++ b/erpnext/projects/doctype/timesheet/timesheet.py
@@ -369,7 +369,7 @@
 	conditions = get_conditions(filters)
 	return frappe.db.sql("""select `tabTimesheet Detail`.name as name, 
 			`tabTimesheet Detail`.docstatus as status, `tabTimesheet Detail`.parent as parent,
-			from_time, hours, activity_type, project, to_time 
+			from_time as start_date, hours, activity_type, project, to_time as end_date
 		from `tabTimesheet Detail`, `tabTimesheet` 
 		where `tabTimesheet Detail`.parent = `tabTimesheet`.name 
 			and `tabTimesheet`.docstatus < 2 
diff --git a/erpnext/setup/setup_wizard/data/country_wise_tax.json b/erpnext/setup/setup_wizard/data/country_wise_tax.json
index 06f7f09..780b88f 100644
--- a/erpnext/setup/setup_wizard/data/country_wise_tax.json
+++ b/erpnext/setup/setup_wizard/data/country_wise_tax.json
@@ -1039,7 +1039,7 @@
 		}
 	},
 
-	"Russia": {
+	"Russian Federation": {
 		"Russia VAT 18%": {
 			"account_name": "VAT 18%",
 			"tax_rate": 18.00,
diff --git a/erpnext/setup/setup_wizard/setup_wizard.py b/erpnext/setup/setup_wizard/setup_wizard.py
index 7c65f88..66000cd 100644
--- a/erpnext/setup/setup_wizard/setup_wizard.py
+++ b/erpnext/setup/setup_wizard/setup_wizard.py
@@ -247,7 +247,7 @@
 	
 def create_sales_tax(args):
 	country_wise_tax = get_country_wise_tax(args.get("country"))
-	if len(country_wise_tax)>0:
+	if country_wise_tax and len(country_wise_tax) > 0:
 		for sales_tax, tax_data in country_wise_tax.items():
 			make_tax_account_and_template(args.get("company_name").strip(), 
 				tax_data.get('account_name'), tax_data.get('tax_rate'), sales_tax)
diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py
index e9d4cb3..ced6a64 100644
--- a/erpnext/stock/doctype/item/item.py
+++ b/erpnext/stock/doctype/item/item.py
@@ -567,7 +567,7 @@
 		existing_allow_negative_stock = frappe.db.get_value("Stock Settings", None, "allow_negative_stock")
 		frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1)
 
-		for warehouse in frappe.db.sql("select name from `tabWarehouse` where is_group = 0"):
+		for warehouse in frappe.db.sql("select warehouse from `tabBin` where item_code=%s", new_name):
 			repost_stock(new_name, warehouse[0])
 
 		frappe.db.set_value("Stock Settings", None, "allow_negative_stock", existing_allow_negative_stock)
diff --git a/erpnext/stock/report/serial_no_status/serial_no_status.json b/erpnext/stock/report/serial_no_status/serial_no_status.json
index dfc7afc..e021a5d 100644
--- a/erpnext/stock/report/serial_no_status/serial_no_status.json
+++ b/erpnext/stock/report/serial_no_status/serial_no_status.json
@@ -7,8 +7,8 @@
  "doctype": "Report", 
  "idx": 1, 
  "is_standard": "Yes", 
- "json": "{\"filters\":[],\"columns\":[[\"name\",\"Serial No\"],[\"item_code\",\"Serial No\"],[\"warehouse\",\"Serial No\"],[\"item_name\",\"Serial No\"],[\"description\",\"Serial No\"],[\"item_group\",\"Serial No\"],[\"brand\",\"Serial No\"],[\"purchase_document_no\",\"Serial No\"],[\"purchase_date\",\"Serial No\"],[\"customer\",\"Serial No\"],[\"customer_name\",\"Serial No\"],[\"purchase_rate\",\"Serial No\"],[\"delivery_document_no\",\"Serial No\"],[\"delivery_date\",\"Serial No\"],[\"supplier\",\"Serial No\"],[\"supplier_name\",\"Serial No\"]],\"sort_by\":\"Serial No.name\",\"sort_order\":\"desc\",\"sort_by_next\":null,\"sort_order_next\":\"desc\"}", 
- "modified": "2015-10-22 14:49:29.491790", 
+ "json": "{\"filters\":[],\"columns\":[[\"name\",\"Serial No\"],[\"item_code\",\"Serial No\"],[\"warehouse\",\"Serial No\"],[\"item_name\",\"Serial No\"],[\"description\",\"Serial No\"],[\"item_group\",\"Serial No\"],[\"brand\",\"Serial No\"],[\"purchase_document_type\",\"Serial No\"],[\"purchase_document_no\",\"Serial No\"],[\"purchase_date\",\"Serial No\"],[\"customer\",\"Serial No\"],[\"customer_name\",\"Serial No\"],[\"purchase_rate\",\"Serial No\"],[\"delivery_document_no\",\"Serial No\"],[\"delivery_date\",\"Serial No\"],[\"supplier\",\"Serial No\"],[\"supplier_name\",\"Serial No\"]],\"sort_by\":\"Serial No.name\",\"sort_order\":\"desc\",\"sort_by_next\":null,\"sort_order_next\":\"desc\"}", 
+ "modified": "2016-10-31 06:28:26.344862", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Serial No Status",