feat: batchwise valuation flag

This is required to avoid breaking behaviour in valuation
of old batches
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index a93ceca..52c29b2 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -353,3 +353,4 @@
 erpnext.patches.v13_0.update_exchange_rate_settings
 erpnext.patches.v14_0.delete_amazon_mws_doctype
 erpnext.patches.v13_0.set_work_order_qty_in_so_from_mr
+erpnext.patches.v14_0.update_batch_valuation_flag
diff --git a/erpnext/patches/v14_0/update_batch_valuation_flag.py b/erpnext/patches/v14_0/update_batch_valuation_flag.py
new file mode 100644
index 0000000..d9f08d8
--- /dev/null
+++ b/erpnext/patches/v14_0/update_batch_valuation_flag.py
@@ -0,0 +1,12 @@
+import frappe
+
+
+def execute():
+	"""
+	- Don't use batchwise valuation for existing batches.
+	- Only batches created after this patch shoule use it.
+	"""
+	frappe.db.sql("""
+		UPDATE `tabBatch`
+		SET use_batchwise_valuation=0
+	""")
diff --git a/erpnext/stock/doctype/batch/batch.json b/erpnext/stock/doctype/batch/batch.json
index fc4cf1d..0d28ea0 100644
--- a/erpnext/stock/doctype/batch/batch.json
+++ b/erpnext/stock/doctype/batch/batch.json
@@ -9,6 +9,8 @@
  "field_order": [
   "sb_disabled",
   "disabled",
+  "column_break_24",
+  "use_batchwise_valuation",
   "sb_batch",
   "batch_id",
   "item",
@@ -186,6 +188,18 @@
    "fieldtype": "Float",
    "label": "Produced Qty",
    "read_only": 1
+  },
+  {
+   "fieldname": "column_break_24",
+   "fieldtype": "Column Break"
+  },
+  {
+   "default": "1",
+   "fieldname": "use_batchwise_valuation",
+   "fieldtype": "Check",
+   "label": "Use Batch-wise Valuation",
+   "read_only": 1,
+   "set_only_once": 1
   }
  ],
  "icon": "fa fa-archive",
@@ -193,7 +207,7 @@
  "image_field": "image",
  "links": [],
  "max_attachments": 5,
- "modified": "2021-07-08 16:22:01.343105",
+ "modified": "2021-10-11 13:38:12.806976",
  "modified_by": "Administrator",
  "module": "Stock",
  "name": "Batch",