Merge pull request #3164 from nabinhait/v4.x.x

advance paid should not be copied and patch to fix affected records
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.json b/erpnext/buying/doctype/purchase_order/purchase_order.json
index a57f544..28a50f5 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.json
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.json
@@ -389,6 +389,7 @@
    "fieldname": "advance_paid", 
    "fieldtype": "Currency", 
    "label": "Advance Paid", 
+   "no_copy": 1, 
    "permlevel": 0, 
    "print_hide": 1, 
    "read_only": 1
@@ -775,7 +776,7 @@
  "icon": "icon-file-text", 
  "idx": 1, 
  "is_submittable": 1, 
- "modified": "2014-11-27 17:27:38.839440", 
+ "modified": "2015-04-27 13:40:17.589085", 
  "modified_by": "Administrator", 
  "module": "Buying", 
  "name": "Purchase Order", 
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 60df4ce..bccbe79 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -98,3 +98,4 @@
 erpnext.patches.v4_2.repost_sle_for_si_with_no_warehouse
 erpnext.patches.v4_2.fix_recurring_orders
 erpnext.patches.v4_2.delete_gl_entries_for_cancelled_invoices
+erpnext.patches.v4_2.update_advance_paid
diff --git a/erpnext/patches/v4_2/update_advance_paid.py b/erpnext/patches/v4_2/update_advance_paid.py
new file mode 100644
index 0000000..818735a
--- /dev/null
+++ b/erpnext/patches/v4_2/update_advance_paid.py
@@ -0,0 +1,13 @@
+# 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
+
+def execute():
+	for dt in ("Sales Order", "Purchase Order"):
+		orders_with_advance = frappe.db.sql("""select name from `tab{0}` 
+			where docstatus < 2 and ifnull(advance_paid, 0) != 0""".format(dt), as_dict=1)
+			
+		for order in orders_with_advance:
+			frappe.get_doc(dt, order.name).set_total_advance_paid()
\ No newline at end of file
diff --git a/erpnext/selling/doctype/sales_order/sales_order.json b/erpnext/selling/doctype/sales_order/sales_order.json
index 4ffc603..1277e06 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.json
+++ b/erpnext/selling/doctype/sales_order/sales_order.json
@@ -549,6 +549,7 @@
    "fieldname": "advance_paid", 
    "fieldtype": "Currency", 
    "label": "Advance Paid", 
+   "no_copy": 1, 
    "options": "Company:company:default_currency", 
    "permlevel": 0, 
    "print_hide": 1, 
@@ -1033,7 +1034,7 @@
  "idx": 1, 
  "is_submittable": 1, 
  "issingle": 0, 
- "modified": "2015-01-12 15:16:51.611467", 
+ "modified": "2015-04-27 13:39:50.229026", 
  "modified_by": "Administrator", 
  "module": "Selling", 
  "name": "Sales Order",