Merge pull request #2565 from alexandre-00/patch-11

Update bom.py
diff --git a/.travis.yml b/.travis.yml
index c136aa0..45410d5 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -16,8 +16,9 @@
   - sudo apt-get install mariadb-server mariadb-common libmariadbclient-dev
   - ./ci/fix-mariadb.sh
 
-  - wget http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.1/wkhtmltox-0.12.1_linux-precise-amd64.deb
-  - sudo dpkg -i wkhtmltox-0.12.1_linux-precise-amd64.deb
+  - sudo apt-get install xfonts-75dpi xfonts-base -y
+  - wget http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.2/wkhtmltox-0.12.2_linux-precise-amd64.deb
+  - sudo dpkg -i wkhtmltox-0.12.2_linux-precise-amd64.deb
   - CFLAGS=-O0 pip install git+https://github.com/frappe/frappe.git@develop
   - CFLAGS=-O0 pip install --editable .
 
diff --git a/README.md b/README.md
index b9d5a6e..efa3e33 100644
--- a/README.md
+++ b/README.md
@@ -1,34 +1,31 @@
-# ERPNext - Open Source ERP for small, medium sized businesses [![Build Status](https://travis-ci.org/frappe/erpnext.png)](https://travis-ci.org/frappe/erpnext)
+# ERPNext - Open source ERP for small and medium-size business [![Build Status](https://travis-ci.org/frappe/erpnext.png)](https://travis-ci.org/frappe/erpnext)
 
 [https://erpnext.com](https://erpnext.com)
 
-Includes Accounting, Inventory, CRM, Sales, Purchase, Projects, HRMS. Built on Python / MariaDB.
+Includes: Accounting, Inventory, CRM, Sales, Purchase, Projects, HRMS. Requires MariaDB.
 
-ERPNext is built on [frappe](https://github.com/frappe/frappe) Python Framework.
+ERPNext is built on the [Frappe](https://github.com/frappe/frappe) Framework, a full-stack web app framework in Python & Javascript.
 
-- [User Guide](http://erpnext.org/user-guide.html)
+- [User Guide](https://erpnext.com/user-guide)
 - [Getting Help](http://erpnext.org/getting-help.html)
-- [Developer Forum](http://groups.google.com/group/erpnext-developer-forum)
-- [User Forum](http://groups.google.com/group/erpnext-user-forum)
+- [Discussion Forum](https://discuss.frappe.io/)
 
 ---
 
-### Install
+### Full Install
 
-Use the bench, https://github.com/frappe/bench
+The Easy Way install script for bench will install all dependencies (e.g. MariaDB). See https://github.com/frappe/bench
 
-### Admin Login
+New passwords will be created for the ERPNext "Administrator" user, the MariaDB root user, and the frappe user (the script displays the passwords and saves them to ~/frappe_passwords.txt).
 
-1. go to "/login"
-1. Administrator user name: "Administrator"
-1. Administrator password: "admin"
+### Virtual Image
 
-### Download and Install
-
-##### Virtual Image:
+You can download a virtual image to run ERPNext in a virtual machine on your local system.
 
 - [ERPNext Download](http://erpnext.com/download)
 
+System and user credentials are listed on the download page.
+
 ---
 
 ## License
diff --git a/erpnext/__version__.py b/erpnext/__version__.py
index ebfb9bf..1eef0c4 100644
--- a/erpnext/__version__.py
+++ b/erpnext/__version__.py
@@ -1 +1 @@
-__version__ = '4.16.0'
+__version__ = '4.17.0'
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
index b27a2ab..9f70c70 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
@@ -423,6 +423,15 @@
    "permlevel": 0
   }, 
   {
+   "fieldname": "other_charges_total_export", 
+   "fieldtype": "Currency", 
+   "label": "Total Taxes and Charges", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "other_charges_total", 
    "fieldtype": "Currency", 
    "label": "Total Taxes and Charges (Company Currency)", 
@@ -439,23 +448,24 @@
    "permlevel": 0
   }, 
   {
-   "fieldname": "other_charges_total_export", 
-   "fieldtype": "Currency", 
-   "label": "Total Taxes and Charges", 
-   "options": "currency", 
-   "permlevel": 0, 
-   "print_hide": 1, 
-   "read_only": 1
-  }, 
-  {
    "fieldname": "discount_amount", 
    "fieldtype": "Currency", 
    "label": "Discount Amount", 
-   "options": "Company:company:default_currency", 
+   "options": "currency", 
    "permlevel": 0, 
    "print_hide": 0
   }, 
   {
+   "fieldname": "base_discount_amount", 
+   "fieldtype": "Currency", 
+   "label": "Discount Amount (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "totals", 
    "fieldtype": "Section Break", 
    "label": "Totals", 
@@ -1192,7 +1202,7 @@
  "icon": "icon-file-text", 
  "idx": 1, 
  "is_submittable": 1, 
- "modified": "2014-12-11 16:26:12.402110", 
+ "modified": "2015-01-12 17:34:36.353241", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Sales Invoice", 
diff --git a/erpnext/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js b/erpnext/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js
index d11bf29..f4e14b8 100644
--- a/erpnext/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js
+++ b/erpnext/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js
@@ -46,17 +46,17 @@
 		var new_val = flt(val)/flt(doc.conversion_rate);
 		return new_val;
 	}
-	
+
 	function print_hide(fieldname) {
 		var doc_field = frappe.meta.get_docfield(doc.doctype, fieldname, doc.name);
 		return doc_field.print_hide;
 	}
-	
+
 	out ='';
 	if (!doc.print_without_amount) {
 		var cl = doc.other_charges || [];
 
-		// outer table	
+		// outer table
 		var out='<div><table class="noborder" style="width:100%"><tr><td style="width: 60%"></td><td>';
 
 		// main table
@@ -77,12 +77,12 @@
 
 		// Discount Amount
 		if(!print_hide('discount_amount') && doc.discount_amount)
-			out += make_row('Discount Amount', convert_rate(doc.discount_amount), 0);
+			out += make_row('Discount Amount', doc.discount_amount, 0);
 
 		// grand total
 		if(!print_hide('grand_total_export'))
 			out += make_row('Grand Total', doc.grand_total_export, 1);
-		
+
 		if(!print_hide('rounded_total_export'))
 			out += make_row('Rounded Total', doc.rounded_total_export, 1);
 
@@ -92,7 +92,7 @@
 			out += '<table><tr><td style="width:25%;"><b>In Words</b></td>';
 			out += '<td style="width:50%;">' + doc.in_words_export + '</td></tr>';
 		}
-		out += '</table></td></tr></table></div>';	 
+		out += '</table></td></tr></table></div>';
 	}
 	return out;
 }
@@ -139,14 +139,14 @@
 			"account_type": ["Tax", "Chargeable", "Income Account"],
 			"company": doc.company
 		}
-	}	
+	}
 }
 
 cur_frm.fields_dict['other_charges'].grid.get_field("cost_center").get_query = function(doc) {
 	return{
 		'company': doc.company,
 		'group_or_ledger': "Ledger"
-	}	
+	}
 }
 
 cur_frm.cscript.rate = function(doc, cdt, cdn) {
diff --git a/erpnext/accounts/print_format/cheque_printing_format/cheque_printing_format.json b/erpnext/accounts/print_format/cheque_printing_format/cheque_printing_format.json
index ce61fa1..5b4d2f8 100755
--- a/erpnext/accounts/print_format/cheque_printing_format/cheque_printing_format.json
+++ b/erpnext/accounts/print_format/cheque_printing_format/cheque_printing_format.json
@@ -3,9 +3,9 @@
  "doc_type": "Journal Voucher", 
  "docstatus": 0, 
  "doctype": "Print Format", 
- "html": "<div style=\"position: relative\">\n\n\t{%- from \"templates/print_formats/standard_macros.html\" import add_header -%}\n<div class=\"page-break\">\n    {%- if not doc.get(\"print_heading\") and not doc.get(\"select_print_heading\") \n        and doc.set(\"select_print_heading\", _(\"Payment Advice\")) -%}{%- endif -%}\n    {{ add_header(0, 1, doc, letter_head, no_letterhead) }}\n\n{%- for label, value in (\n        (_(\"Voucher Date\"), frappe.utils.formatdate(doc.voucher_date)),\n        (_(\"Reference / Cheque No.\"), doc.cheque_no),\n        (_(\"Reference / Cheque Date\"), frappe.utils.formatdate(doc.cheque_date))\n    ) -%}\n    <div class=\"row\">\n        <div class=\"col-sm-4\"><label class=\"text-right\">{{ label }}</label></div>\n        <div class=\"col-sm-8\">{{ value }}</div>\n    </div>\n{%- endfor -%}\n\t<hr>\n\t<p>{{ _(\"This amount is in full / part settlement of the listed bills\") }}:</p>\n{%- for label, value in (\n         (_(\"Amount\"), \"<strong>\" + (doc.total_amount or \"\") + \"</strong><br>\" + (doc.total_amount_in_words or \"\") + \"<br>\"),\n        (_(\"References\"), doc.remark)\n    ) -%}\n    <div class=\"row\">\n        <div class=\"col-sm-4\"><label class=\"text-right\">{{ label }}</label></div>\n        <div class=\"col-sm-8\">{{ value }}</div>\n    </div>\n    {%- endfor -%}\n    <hr>\n\t<div style=\"position: absolute; top: 14cm; left: 0cm;\">\n\t\tPrepared By</div>\n\t<div style=\"position: absolute; top: 14cm; left: 5.5cm;\">\n\t\tAuthorised Signatory</div>\n\t<div style=\"position: absolute; top: 14cm; left: 11cm;\">\n\t\tReceived Payment as Above</div>\n\t<div style=\"position: absolute; top: 16.4cm; left: 5.9cm;\">\n\t\t<strong>_____________</strong></div>\n\t<div style=\"position: absolute; top: 16.7cm; left: 6cm;\">\n\t\t<strong>A/C Payee</strong></div>\n\t<div style=\"position: absolute; top: 16.7cm; left: 5.9cm;\">\n\t\t<strong>_____________</strong></div>\n\t<div style=\"position: absolute; top: 16.9cm; left: 12cm;\">\n\t\t{{ frappe.utils.formatdate(doc.cheque_date) }}</div>\n\t<div style=\"position: absolute; top: 17.9cm; left: 1cm;\">\n\t\t{{ doc.pay_to_recd_from }}</div>\n\t<div style=\"position: absolute; top: 18.6cm; left: 1cm; width: 7cm;\">\n\t\t{{ doc.total_amount_in_words }}</div>\n\t<div style=\"position: absolute; top: 19.7cm; left: 12cm;\">\n\t\t{{ doc.total_amount }}</div>\n</div>", 
+ "html": "<div style=\"position: relative\">\n\n\t{%- from \"templates/print_formats/standard_macros.html\" import add_header -%}\n<div class=\"page-break\">\n    {%- if not doc.get(\"print_heading\") and not doc.get(\"select_print_heading\") \n        and doc.set(\"select_print_heading\", _(\"Payment Advice\")) -%}{%- endif -%}\n    {{ add_header(0, 1, doc, letter_head, no_letterhead) }}\n\n{%- for label, value in (\n        (_(\"Voucher Date\"), frappe.utils.formatdate(doc.voucher_date)),\n        (_(\"Reference / Cheque No.\"), doc.cheque_no),\n        (_(\"Reference / Cheque Date\"), frappe.utils.formatdate(doc.cheque_date))\n    ) -%}\n    <div class=\"row\">\n        <div class=\"col-xs-4\"><label class=\"text-right\">{{ label }}</label></div>\n        <div class=\"col-xs-8\">{{ value }}</div>\n    </div>\n{%- endfor -%}\n\t<hr>\n\t<p>{{ _(\"This amount is in full / part settlement of the listed bills\") }}:</p>\n{%- for label, value in (\n         (_(\"Amount\"), \"<strong>\" + (doc.total_amount or \"\") + \"</strong><br>\" + (doc.total_amount_in_words or \"\") + \"<br>\"),\n        (_(\"References\"), doc.remark)\n    ) -%}\n    <div class=\"row\">\n        <div class=\"col-xs-4\"><label class=\"text-right\">{{ label }}</label></div>\n        <div class=\"col-xs-8\">{{ value }}</div>\n    </div>\n    {%- endfor -%}\n    <hr>\n\t<div style=\"position: absolute; top: 14cm; left: 0cm;\">\n\t\tPrepared By</div>\n\t<div style=\"position: absolute; top: 14cm; left: 5.5cm;\">\n\t\tAuthorised Signatory</div>\n\t<div style=\"position: absolute; top: 14cm; left: 11cm;\">\n\t\tReceived Payment as Above</div>\n\t<div style=\"position: absolute; top: 16.4cm; left: 5.9cm;\">\n\t\t<strong>_____________</strong></div>\n\t<div style=\"position: absolute; top: 16.7cm; left: 6cm;\">\n\t\t<strong>A/C Payee</strong></div>\n\t<div style=\"position: absolute; top: 16.7cm; left: 5.9cm;\">\n\t\t<strong>_____________</strong></div>\n\t<div style=\"position: absolute; top: 16.9cm; left: 12cm;\">\n\t\t{{ frappe.utils.formatdate(doc.cheque_date) }}</div>\n\t<div style=\"position: absolute; top: 17.9cm; left: 1cm;\">\n\t\t{{ doc.pay_to_recd_from }}</div>\n\t<div style=\"position: absolute; top: 18.6cm; left: 1cm; width: 7cm;\">\n\t\t{{ doc.total_amount_in_words }}</div>\n\t<div style=\"position: absolute; top: 19.7cm; left: 12cm;\">\n\t\t{{ doc.total_amount }}</div>\n</div>", 
  "idx": 1, 
- "modified": "2014-09-09 03:27:13.708596", 
+ "modified": "2015-01-12 11:03:17.032512", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Cheque Printing Format", 
diff --git a/erpnext/accounts/print_format/credit_note/credit_note.json b/erpnext/accounts/print_format/credit_note/credit_note.json
index ac0de75..e6c9e8f 100644
--- a/erpnext/accounts/print_format/credit_note/credit_note.json
+++ b/erpnext/accounts/print_format/credit_note/credit_note.json
@@ -4,9 +4,9 @@
  "doc_type": "Journal Voucher", 
  "docstatus": 0, 
  "doctype": "Print Format", 
- "html": "{%- from \"templates/print_formats/standard_macros.html\" import add_header -%}\n\n<div class=\"page-break\">\n    {%- if not doc.get(\"print_heading\") and not doc.get(\"select_print_heading\") \n        and doc.set(\"select_print_heading\", _(\"Credit Note\")) -%}{%- endif -%}\n    {{ add_header(0, 1, doc, letter_head, no_letterhead) }}\n\n    {%- for label, value in (\n        (_(\"Credit To\"), doc.pay_to_recd_from),\n        (_(\"Date\"), frappe.utils.formatdate(doc.voucher_date)),\n        (_(\"Amount\"), \"<strong>\" + frappe.utils.cstr(doc.total_amount) + \"</strong><br>\" + (doc.total_amount_in_words or \"\") + \"<br>\"),\n        (_(\"Remarks\"), doc.remark)\n    ) -%}\n\n    <div class=\"row\">\n        <div class=\"col-sm-3\"><label class=\"text-right\">{{ label }}</label></div>\n        <div class=\"col-sm-9\">{{ value }}</div>\n    </div>\n\n    {%- endfor -%}\n\n    <hr>\n    <br>\n    <p class=\"strong\">\n        {{ _(\"For\") }} {{ doc.company }},<br>\n        <br>\n        <br>\n        <br>\n        {{ _(\"Authorized Signatory\") }}\n    </p>\n</div>\n\n\n", 
+ "html": "{%- from \"templates/print_formats/standard_macros.html\" import add_header -%}\n\n<div class=\"page-break\">\n    {%- if not doc.get(\"print_heading\") and not doc.get(\"select_print_heading\") \n        and doc.set(\"select_print_heading\", _(\"Credit Note\")) -%}{%- endif -%}\n    {{ add_header(0, 1, doc, letter_head, no_letterhead) }}\n\n    {%- for label, value in (\n        (_(\"Credit To\"), doc.pay_to_recd_from),\n        (_(\"Date\"), frappe.utils.formatdate(doc.voucher_date)),\n        (_(\"Amount\"), \"<strong>\" + frappe.utils.cstr(doc.total_amount) + \"</strong><br>\" + (doc.total_amount_in_words or \"\") + \"<br>\"),\n        (_(\"Remarks\"), doc.remark)\n    ) -%}\n\n    <div class=\"row\">\n        <div class=\"col-xs-3\"><label class=\"text-right\">{{ label }}</label></div>\n        <div class=\"col-xs-9\">{{ value }}</div>\n    </div>\n\n    {%- endfor -%}\n\n    <hr>\n    <br>\n    <p class=\"strong\">\n        {{ _(\"For\") }} {{ doc.company }},<br>\n        <br>\n        <br>\n        <br>\n        {{ _(\"Authorized Signatory\") }}\n    </p>\n</div>\n\n\n", 
  "idx": 2, 
- "modified": "2014-10-17 17:20:02.740340", 
+ "modified": "2015-01-12 11:02:25.716825", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Credit Note", 
diff --git a/erpnext/accounts/print_format/payment_receipt_voucher/payment_receipt_voucher.json b/erpnext/accounts/print_format/payment_receipt_voucher/payment_receipt_voucher.json
index 5c0a72a..04fe746 100755
--- a/erpnext/accounts/print_format/payment_receipt_voucher/payment_receipt_voucher.json
+++ b/erpnext/accounts/print_format/payment_receipt_voucher/payment_receipt_voucher.json
@@ -3,9 +3,9 @@
  "doc_type": "Journal Voucher", 
  "docstatus": 0, 
  "doctype": "Print Format", 
- "html": "{%- from \"templates/print_formats/standard_macros.html\" import add_header -%}\n<div class=\"page-break\">\n    {%- if not doc.get(\"print_heading\") and not doc.get(\"select_print_heading\") \n        and doc.set(\"select_print_heading\", _(\"Payment Receipt Note\")) -%}{%- endif -%}\n    {{ add_header(0, 1, doc, letter_head, no_letterhead) }}\n\n    {%- for label, value in (\n        (_(\"Received On\"), frappe.utils.formatdate(doc.voucher_date)),\n        (_(\"Received From\"), doc.pay_to_recd_from),\n        (_(\"Amount\"), \"<strong>\" + doc.total_amount or 0 + \"</strong><br>\" + (doc.total_amount_in_words or \"\") + \"<br>\"),\n        (_(\"Remarks\"), doc.remark)\n    ) -%}\n    <div class=\"row\">\n        <div class=\"col-sm-3\"><label class=\"text-right\">{{ label }}</label></div>\n        <div class=\"col-sm-9\">{{ value }}</div>\n    </div>\n\n    {%- endfor -%}\n\n    <hr>\n    <br>\n    <p class=\"strong\">\n        {{ _(\"For\") }} {{ doc.company }},<br>\n        <br>\n        <br>\n        <br>\n        {{ _(\"Authorized Signatory\") }}\n    </p>\n</div>\n\n", 
+ "html": "{%- from \"templates/print_formats/standard_macros.html\" import add_header -%}\n<div class=\"page-break\">\n    {%- if not doc.get(\"print_heading\") and not doc.get(\"select_print_heading\") \n        and doc.set(\"select_print_heading\", _(\"Payment Receipt Note\")) -%}{%- endif -%}\n    {{ add_header(0, 1, doc, letter_head, no_letterhead) }}\n\n    {%- for label, value in (\n        (_(\"Received On\"), frappe.utils.formatdate(doc.voucher_date)),\n        (_(\"Received From\"), doc.pay_to_recd_from),\n        (_(\"Amount\"), \"<strong>\" + doc.total_amount or 0 + \"</strong><br>\" + (doc.total_amount_in_words or \"\") + \"<br>\"),\n        (_(\"Remarks\"), doc.remark)\n    ) -%}\n    <div class=\"row\">\n        <div class=\"col-xs-3\"><label class=\"text-right\">{{ label }}</label></div>\n        <div class=\"col-xs-9\">{{ value }}</div>\n    </div>\n\n    {%- endfor -%}\n\n    <hr>\n    <br>\n    <p class=\"strong\">\n        {{ _(\"For\") }} {{ doc.company }},<br>\n        <br>\n        <br>\n        <br>\n        {{ _(\"Authorized Signatory\") }}\n    </p>\n</div>\n\n", 
  "idx": 1, 
- "modified": "2014-11-04 11:25:57.560873", 
+ "modified": "2015-01-12 11:03:22.893209", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Payment Receipt Voucher", 
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index 02fdf2c..5219339 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -295,7 +295,7 @@
 			self.precision("tax_amount", tax))
 
 	def adjust_discount_amount_loss(self, tax):
-		discount_amount_loss = self.grand_total - flt(self.discount_amount) - tax.total
+		discount_amount_loss = self.grand_total - flt(self.base_discount_amount) - tax.total
 		tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount +
 			discount_amount_loss, self.precision("tax_amount", tax))
 		tax.total = flt(tax.total + discount_amount_loss, self.precision("total", tax))
diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py
index 68cdf18..4b0cd4e 100644
--- a/erpnext/controllers/selling_controller.py
+++ b/erpnext/controllers/selling_controller.py
@@ -218,8 +218,7 @@
 	def calculate_totals(self):
 		self.grand_total = flt(self.tax_doclist[-1].total if self.tax_doclist else self.net_total)
 
-		self.grand_total_export = flt(self.grand_total / self.conversion_rate) \
-			if self.tax_doclist else self.net_total_export
+		self.grand_total_export = flt(self.grand_total / self.conversion_rate)
 
 		self.other_charges_total = flt(self.grand_total - self.net_total, self.precision("other_charges_total"))
 
@@ -234,16 +233,20 @@
 
 	def apply_discount_amount(self):
 		if self.discount_amount:
+			self.base_discount_amount = flt(self.discount_amount * self.conversion_rate, self.precision("base_discount_amount"))
+
 			grand_total_for_discount_amount = self.get_grand_total_for_discount_amount()
 
 			if grand_total_for_discount_amount:
 				# calculate item amount after Discount Amount
 				for item in self.item_doclist:
-					distributed_amount = flt(self.discount_amount) * item.base_amount / grand_total_for_discount_amount
+					distributed_amount = flt(self.base_discount_amount) * item.base_amount / grand_total_for_discount_amount
 					item.base_amount = flt(item.base_amount - distributed_amount, self.precision("base_amount", item))
 
 				self.discount_amount_applied = True
 				self._calculate_taxes_and_totals()
+		else:
+			self.base_discount_amount = 0
 
 	def get_grand_total_for_discount_amount(self):
 		actual_taxes_dict = {}
diff --git a/erpnext/hooks.py b/erpnext/hooks.py
index d8b8a2e..e369453 100644
--- a/erpnext/hooks.py
+++ b/erpnext/hooks.py
@@ -4,7 +4,7 @@
 app_description = "Open Source Enterprise Resource Planning for Small and Midsized Organizations"
 app_icon = "icon-th"
 app_color = "#e74c3c"
-app_version = "4.16.0"
+app_version = "4.17.0"
 
 error_report_email = "support@erpnext.com"
 
diff --git a/erpnext/hr/doctype/leave_application/leave_application.js b/erpnext/hr/doctype/leave_application/leave_application.js
index 9ba988e..6605c30 100755
--- a/erpnext/hr/doctype/leave_application/leave_application.js
+++ b/erpnext/hr/doctype/leave_application/leave_application.js
@@ -33,7 +33,7 @@
 				cur_frm.set_intro(__("You are the Leave Approver for this record. Please Update the 'Status' and Save"));
 				cur_frm.toggle_enable("status", true);
 			} else {
-				cur_frm.set_intro(__("This Leave Application is pending approval. Only the Leave Apporver can update status."))
+				cur_frm.set_intro(__("This Leave Application is pending approval. Only the Leave Approver can update status."))
 				cur_frm.toggle_enable("status", false);
 				if(!doc.__islocal) {
 						cur_frm.frm_head.appframe.set_title_right("");
diff --git a/erpnext/manufacturing/doctype/production_order/test_production_order.py b/erpnext/manufacturing/doctype/production_order/test_production_order.py
index a9975c1..59e56ef 100644
--- a/erpnext/manufacturing/doctype/production_order/test_production_order.py
+++ b/erpnext/manufacturing/doctype/production_order/test_production_order.py
@@ -10,7 +10,7 @@
 from erpnext.stock.doctype.stock_entry import test_stock_entry
 
 class TestProductionOrder(unittest.TestCase):
-	def test_planned_qty(self):
+	def check_planned_qty(self):
 		set_perpetual_inventory(0)
 
 		planned0 = frappe.db.get_value("Bin", {"item_code": "_Test FG Item", "warehouse": "_Test Warehouse 1 - _TC"}, "planned_qty") or 0
@@ -27,11 +27,15 @@
 		s = frappe.get_doc(make_stock_entry(pro_doc.name, "Material Transfer", 4))
 		for d in s.get("mtn_details"):
 			d.s_warehouse = "Stores - _TC"
+		s.fiscal_year = "_Test Fiscal Year 2013"
+		s.posting_date = "2013-01-02"
 		s.insert()
 		s.submit()
 
 		# from wip to fg
 		s = frappe.get_doc(make_stock_entry(pro_doc.name, "Manufacture", 4))
+		s.fiscal_year = "_Test Fiscal Year 2013"
+		s.posting_date = "2013-01-03"
 		s.insert()
 		s.submit()
 
@@ -44,12 +48,14 @@
 
 	def test_over_production(self):
 		from erpnext.manufacturing.doctype.production_order.production_order import StockOverProductionError
-		pro_doc = self.test_planned_qty()
+		pro_doc = self.check_planned_qty()
 
 		test_stock_entry.make_stock_entry("_Test Item", None, "_Test Warehouse - _TC", 100, 100)
 		test_stock_entry.make_stock_entry("_Test Item Home Desktop 100", None, "_Test Warehouse - _TC", 100, 100)
 
 		s = frappe.get_doc(make_stock_entry(pro_doc.name, "Manufacture", 7))
+		s.fiscal_year = "_Test Fiscal Year 2013"
+		s.posting_date = "2013-01-04"
 		s.insert()
 
 		self.assertRaises(StockOverProductionError, s.submit)
diff --git a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.js b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.js
index e219215..f0616de 100644
--- a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.js
+++ b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.js
@@ -24,6 +24,13 @@
 	}
 }
 
+cur_frm.cscript.raise_purchase_request = function(doc, cdt, cdn) {
+	return frappe.call({
+		method: "raise_purchase_request",
+		doc:doc
+	})
+}
+
 cur_frm.cscript.download_materials_required = function(doc, cdt, cdn) {
 	return $c_obj(doc, 'validate_data', '', function(r, rt) {
 		if (!r['exc'])
diff --git a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.json b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.json
index bdfab41..c6ec1e2 100644
--- a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.json
+++ b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.json
@@ -1,5 +1,5 @@
 {
- "creation": "2013-01-21 12:03:47.000000", 
+ "creation": "2013-01-21 12:03:47", 
  "default_print_format": "Standard", 
  "docstatus": 0, 
  "doctype": "DocType", 
@@ -20,6 +20,7 @@
   {
    "fieldname": "fg_item", 
    "fieldtype": "Link", 
+   "in_list_view": 1, 
    "label": "Filter based on item", 
    "options": "Item", 
    "permlevel": 0
@@ -27,6 +28,7 @@
   {
    "fieldname": "customer", 
    "fieldtype": "Link", 
+   "in_list_view": 1, 
    "label": "Filter based on customer", 
    "options": "Customer", 
    "permlevel": 0
@@ -34,6 +36,7 @@
   {
    "fieldname": "company", 
    "fieldtype": "Link", 
+   "in_list_view": 1, 
    "label": "Company", 
    "options": "Company", 
    "permlevel": 0, 
@@ -140,7 +143,7 @@
    "fieldname": "raise_purchase_request", 
    "fieldtype": "Button", 
    "label": "Create Material Requests", 
-   "options": "raise_purchase_request", 
+   "options": "", 
    "permlevel": 0
   }, 
   {
@@ -155,7 +158,7 @@
  "idx": 1, 
  "in_create": 1, 
  "issingle": 1, 
- "modified": "2013-12-20 19:23:25.000000", 
+ "modified": "2015-01-11 21:53:21.253556", 
  "modified_by": "Administrator", 
  "module": "Manufacturing", 
  "name": "Production Planning Tool", 
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 33fa396..7fda960 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -90,3 +90,4 @@
 erpnext.patches.v4_2.update_requested_and_ordered_qty
 execute:frappe.delete_doc("DocType", "Contact Control")
 erpnext.patches.v4_2.recalculate_bom_costs
+erpnext.patches.v4_2.discount_amount
diff --git a/erpnext/patches/v4_2/discount_amount.py b/erpnext/patches/v4_2/discount_amount.py
new file mode 100644
index 0000000..e23a10e
--- /dev/null
+++ b/erpnext/patches/v4_2/discount_amount.py
@@ -0,0 +1,12 @@
+# 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.modules import scrub, get_doctype_module
+
+def execute():
+	for dt in ["Quotation", "Sales Order", "Delivery Note", "Sales invoice"]:
+		frappe.reload_doc(get_doctype_module(dt), "doctype", scrub(dt))
+		frappe.db.sql("""update `tab{0}` set base_discount_amount=discount_amount,
+			discount_amount=discount_amount/conversion_rate""".format(dt))
diff --git a/erpnext/public/js/transaction.js b/erpnext/public/js/transaction.js
index acb841b..6d38b46 100644
--- a/erpnext/public/js/transaction.js
+++ b/erpnext/public/js/transaction.js
@@ -734,7 +734,7 @@
 	},
 
 	adjust_discount_amount_loss: function(tax) {
-		var discount_amount_loss = this.frm.doc.grand_total - flt(this.frm.doc.discount_amount) - tax.total;
+		var discount_amount_loss = this.frm.doc.grand_total - flt(this.frm.doc.base_discount_amount) - tax.total;
 		tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount +
 			discount_amount_loss, precision("tax_amount", tax));
 		tax.total = flt(tax.total + discount_amount_loss, precision("total", tax));
@@ -748,8 +748,7 @@
 			// distribute the tax amount proportionally to each item row
 			var actual = flt(tax.rate, precision("tax_amount", tax));
 			current_tax_amount = this.frm.doc.net_total ?
-				((item.base_amount / this.frm.doc.net_total) * actual) :
-				0.0;
+			((item.base_amount / this.frm.doc.net_total) * actual) : 0.0;
 
 		} else if(tax.charge_type == "On Net Total") {
 			current_tax_amount = (tax_rate / 100.0) * item.base_amount;
diff --git a/erpnext/selling/doctype/opportunity/test_records.json b/erpnext/selling/doctype/opportunity/test_records.json
index 3970903..43ab55d 100644
--- a/erpnext/selling/doctype/opportunity/test_records.json
+++ b/erpnext/selling/doctype/opportunity/test_records.json
@@ -5,6 +5,8 @@
 		"enquiry_from": "Lead",
 		"enquiry_type": "Sales",
 		"lead": "_T-Lead-00001",
+		"transaction_date": "2013-12-12",
+		"fiscal_year": "_Test Fiscal Year 2013", 
 		"enquiry_details": [{
 			"item_name": "Test Item",
 			"description": "Some description"
diff --git a/erpnext/selling/doctype/quotation/quotation.json b/erpnext/selling/doctype/quotation/quotation.json
index 5d960e9..9af5029 100644
--- a/erpnext/selling/doctype/quotation/quotation.json
+++ b/erpnext/selling/doctype/quotation/quotation.json
@@ -406,6 +406,15 @@
    "permlevel": 0
   }, 
   {
+   "fieldname": "other_charges_total_export", 
+   "fieldtype": "Currency", 
+   "label": "Taxes and Charges Total", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "other_charges_total", 
    "fieldtype": "Currency", 
    "label": "Taxes and Charges Total (Company Currency)", 
@@ -422,22 +431,23 @@
    "permlevel": 0
   }, 
   {
-   "fieldname": "other_charges_total_export", 
-   "fieldtype": "Currency", 
-   "label": "Taxes and Charges Total", 
-   "options": "currency", 
-   "permlevel": 0, 
-   "print_hide": 1, 
-   "read_only": 1
-  }, 
-  {
    "fieldname": "discount_amount", 
    "fieldtype": "Currency", 
    "label": "Discount Amount", 
-   "options": "Company:company:default_currency", 
+   "options": "currency", 
    "permlevel": 0
   }, 
   {
+   "fieldname": "base_discount_amount", 
+   "fieldtype": "Currency", 
+   "label": "Discount Amount (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "totals", 
    "fieldtype": "Section Break", 
    "label": "Totals", 
@@ -832,7 +842,7 @@
  "idx": 1, 
  "is_submittable": 1, 
  "max_attachments": 1, 
- "modified": "2014-09-09 05:35:33.413559", 
+ "modified": "2015-01-12 16:57:14.706270", 
  "modified_by": "Administrator", 
  "module": "Selling", 
  "name": "Quotation", 
diff --git a/erpnext/selling/doctype/sales_order/sales_order.json b/erpnext/selling/doctype/sales_order/sales_order.json
index 5064703..4ffc603 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.json
+++ b/erpnext/selling/doctype/sales_order/sales_order.json
@@ -421,11 +421,6 @@
    "read_only": 1
   }, 
   {
-   "fieldname": "column_break_46", 
-   "fieldtype": "Column Break", 
-   "permlevel": 0
-  }, 
-  {
    "fieldname": "other_charges_total", 
    "fieldtype": "Currency", 
    "label": "Taxes and Charges Total (Company Currency)", 
@@ -438,11 +433,27 @@
    "width": "150px"
   }, 
   {
+   "fieldname": "column_break_46", 
+   "fieldtype": "Column Break", 
+   "permlevel": 0
+  }, 
+  {
    "fieldname": "discount_amount", 
    "fieldtype": "Currency", 
    "label": "Discount Amount", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "print_hide": 0
+  }, 
+  {
+   "fieldname": "base_discount_amount", 
+   "fieldtype": "Currency", 
+   "label": "Discount Amount (Company Currency)", 
    "options": "Company:company:default_currency", 
-   "permlevel": 0
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
   }, 
   {
    "fieldname": "totals", 
@@ -491,14 +502,6 @@
    "width": "200px"
   }, 
   {
-   "fieldname": "advance_paid", 
-   "fieldtype": "Currency", 
-   "label": "Advance Paid", 
-   "permlevel": 0, 
-   "print_hide": 1, 
-   "read_only": 1
-  }, 
-  {
    "fieldname": "column_break3", 
    "fieldtype": "Column Break", 
    "oldfieldtype": "Column Break", 
@@ -543,6 +546,15 @@
    "width": "200px"
   }, 
   {
+   "fieldname": "advance_paid", 
+   "fieldtype": "Currency", 
+   "label": "Advance Paid", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "view_details", 
    "fieldtype": "Fold", 
    "label": "View Details", 
@@ -1021,7 +1033,7 @@
  "idx": 1, 
  "is_submittable": 1, 
  "issingle": 0, 
- "modified": "2014-12-16 10:36:47.295144", 
+ "modified": "2015-01-12 15:16:51.611467", 
  "modified_by": "Administrator", 
  "module": "Selling", 
  "name": "Sales Order", 
diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js
index c7c21fd..3a01811 100644
--- a/erpnext/selling/sales_common.js
+++ b/erpnext/selling/sales_common.js
@@ -342,8 +342,7 @@
 		var tax_count = this.frm.tax_doclist.length;
 
 		this.frm.doc.grand_total = flt(tax_count ? this.frm.tax_doclist[tax_count - 1].total : this.frm.doc.net_total);
-		this.frm.doc.grand_total_export = flt(tax_count ?
-			flt(this.frm.doc.grand_total / this.frm.doc.conversion_rate) : this.frm.doc.net_total_export);
+		this.frm.doc.grand_total_export = flt(this.frm.doc.grand_total / this.frm.doc.conversion_rate);
 
 		this.frm.doc.other_charges_total = flt(this.frm.doc.grand_total - this.frm.doc.net_total,
 			precision("other_charges_total"));
@@ -363,17 +362,22 @@
 		var distributed_amount = 0.0;
 
 		if (this.frm.doc.discount_amount) {
+			this.frm.set_value("base_discount_amount",
+				flt(this.frm.doc.discount_amount * this.frm.doc.conversion_rate, precision("base_discount_amount")))
+
 			var grand_total_for_discount_amount = this.get_grand_total_for_discount_amount();
 			// calculate item amount after Discount Amount
 			if (grand_total_for_discount_amount) {
 				$.each(this.frm.item_doclist, function(i, item) {
-					distributed_amount = flt(me.frm.doc.discount_amount) * item.base_amount / grand_total_for_discount_amount;
+					distributed_amount = flt(me.frm.doc.base_discount_amount) * item.base_amount / grand_total_for_discount_amount;
 					item.base_amount = flt(item.base_amount - distributed_amount, precision("base_amount", item));
 				});
 
 				this.discount_amount_applied = true;
 				this._calculate_taxes_and_totals();
 			}
+		} else {
+			this.frm.set_value("base_discount_amount", 0);
 		}
 	},
 
@@ -507,12 +511,12 @@
 				}
 			});
 		};
-		setup_field_label_map(["net_total", "other_charges_total", "grand_total",
+		setup_field_label_map(["net_total", "other_charges_total", "base_discount_amount", "grand_total",
 			"rounded_total", "in_words",
 			"outstanding_amount", "total_advance", "paid_amount", "write_off_amount"],
 			company_currency);
 
-		setup_field_label_map(["net_total_export", "other_charges_total_export", "grand_total_export",
+		setup_field_label_map(["net_total_export", "other_charges_total_export", "discount_amount", "grand_total_export",
 			"rounded_total_export", "in_words_export"], this.frm.doc.currency);
 
 		cur_frm.set_df_property("conversion_rate", "description", "1 " + this.frm.doc.currency
@@ -525,7 +529,7 @@
 
 		// toggle fields
 		this.frm.toggle_display(["conversion_rate", "net_total", "other_charges_total",
-			"grand_total", "rounded_total", "in_words"],
+			"grand_total", "rounded_total", "in_words", "base_discount_amount"],
 			this.frm.doc.currency != company_currency);
 
 		this.frm.toggle_display(["plc_conversion_rate", "price_list_currency"],
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.json b/erpnext/stock/doctype/delivery_note/delivery_note.json
index 98e7748..c7a25d2 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.json
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.json
@@ -435,6 +435,15 @@
    "permlevel": 0
   }, 
   {
+   "fieldname": "other_charges_total_export", 
+   "fieldtype": "Currency", 
+   "label": "Taxes and Charges Total", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "other_charges_total", 
    "fieldtype": "Currency", 
    "label": "Taxes and Charges Total (Company Currency)", 
@@ -453,22 +462,23 @@
    "permlevel": 0
   }, 
   {
-   "fieldname": "other_charges_total_export", 
-   "fieldtype": "Currency", 
-   "label": "Taxes and Charges Total", 
-   "options": "Company:company:default_currency", 
-   "permlevel": 0, 
-   "print_hide": 1, 
-   "read_only": 1
-  }, 
-  {
    "fieldname": "discount_amount", 
    "fieldtype": "Currency", 
    "label": "Discount Amount", 
-   "options": "Company:company:default_currency", 
+   "options": "currency", 
    "permlevel": 0
   }, 
   {
+   "fieldname": "base_discount_amount", 
+   "fieldtype": "Currency", 
+   "label": "Discount Amount (Company Currency)", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "totals", 
    "fieldtype": "Section Break", 
    "label": "Totals", 
@@ -1013,7 +1023,7 @@
  "idx": 1, 
  "in_create": 0, 
  "is_submittable": 1, 
- "modified": "2014-12-22 14:58:19.575566", 
+ "modified": "2015-01-12 16:56:39.975961", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Delivery Note", 
diff --git a/erpnext/stock/doctype/stock_entry/test_stock_entry.py b/erpnext/stock/doctype/stock_entry/test_stock_entry.py
index e010bd1..73f1d0a 100644
--- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py
@@ -936,6 +936,8 @@
 		"incoming_rate": incoming_rate,
 		"conversion_factor": 1.0
 	})
+	s.posting_date= "2013-01-01"
+	s.fiscal_year= "_Test Fiscal Year 2013"
 	s.insert()
 	s.submit()
 	return s
diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
index 530ab9a..9c85277 100644
--- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
+++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
@@ -153,8 +153,8 @@
 				if row.valuation_rate in ("", None):
 					row.valuation_rate = previous_sle.get("valuation_rate")
 
-			# if row.qty and not row.valuation_rate:
-			# 	frappe.throw(_("Valuation Rate required for Item {0}").format(row.item_code))
+			if row.qty and not row.valuation_rate:
+				frappe.throw(_("Valuation Rate required for Item {0}").format(row.item_code))
 
 			self.insert_entries(row)
 
diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py
index fffb52e..5145e0a 100644
--- a/erpnext/stock/get_item_details.py
+++ b/erpnext/stock/get_item_details.py
@@ -4,7 +4,7 @@
 from __future__ import unicode_literals
 import frappe
 from frappe import _, throw
-from frappe.utils import flt, cint, add_days
+from frappe.utils import flt, cint, add_days, cstr
 import json
 from erpnext.accounts.doctype.pricing_rule.pricing_rule import get_pricing_rule_for_item
 from erpnext.setup.utils import get_exchange_rate
@@ -140,7 +140,7 @@
 
 		"item_code": item.name,
 		"item_name": item.item_name,
-		"description": item.description_html or item.description,
+		"description": cstr(item.description_html).strip() or cstr(item.description).strip(),
 		"warehouse": user_default_warehouse or args.warehouse or item.default_warehouse,
 		"income_account": (item.income_account
 			or args.income_account
diff --git a/erpnext/utilities/repost_stock.py b/erpnext/utilities/repost_stock.py
index b63493e..2985725 100644
--- a/erpnext/utilities/repost_stock.py
+++ b/erpnext/utilities/repost_stock.py
@@ -240,7 +240,7 @@
 				doc.validate()
 
 			doc.update_stock_ledger()
-			doc.make_gl_entries(repost_future_gle=False, allow_negative_stock=True)
+			doc.make_gl_entries(repost_future_gle=False)
 			frappe.db.commit()
 		except Exception, e:
 			print frappe.get_traceback()
diff --git a/setup.py b/setup.py
index 4df9566..eb28008 100644
--- a/setup.py
+++ b/setup.py
@@ -1,7 +1,7 @@
 from setuptools import setup, find_packages
 import os
 
-version = "4.16.0"
+version = "4.17.0"
 
 with open("requirements.txt", "r") as f:
 	install_requires = f.readlines()