Distribute tax amount between items in stock entry
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.json b/erpnext/stock/doctype/stock_entry/stock_entry.json
index 3c39d42..f2ea6d4 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.json
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.json
@@ -369,6 +369,7 @@
    "fieldname": "total_incoming_value", 
    "fieldtype": "Currency", 
    "label": "Total Incoming Value", 
+   "options": "Company:company:default_currency", 
    "permlevel": 0, 
    "precision": "", 
    "read_only": 1
@@ -383,6 +384,7 @@
    "fieldname": "total_outgoing_value", 
    "fieldtype": "Currency", 
    "label": "Total Outgoing Value", 
+   "options": "Company:company:default_currency", 
    "permlevel": 0, 
    "precision": "", 
    "read_only": 1
@@ -391,6 +393,7 @@
    "fieldname": "value_difference", 
    "fieldtype": "Currency", 
    "label": "Total Value Difference (Out - In)", 
+   "options": "Company:company:default_currency", 
    "permlevel": 0, 
    "precision": "", 
    "read_only": 1
@@ -405,6 +408,30 @@
    "precision": ""
   }, 
   {
+   "fieldname": "taxes_section", 
+   "fieldtype": "Section Break", 
+   "label": "Taxes and Charges", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "taxes", 
+   "fieldtype": "Table", 
+   "label": "Taxes and Charges", 
+   "options": "Landed Cost Taxes and Charges", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
+   "fieldname": "total_taxes_and_charges", 
+   "fieldtype": "Currency", 
+   "label": "Total Taxes and Charges", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "read_only": 1
+  }, 
+  {
    "fieldname": "fold", 
    "fieldtype": "Fold", 
    "permlevel": 0
@@ -678,7 +705,7 @@
  "is_submittable": 1, 
  "issingle": 0, 
  "max_attachments": 0, 
- "modified": "2015-07-22 18:47:20.328749", 
+ "modified": "2015-07-24 18:47:55.902154", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Stock Entry", 
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index 61ef4cd..06249ed 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -50,6 +50,7 @@
 		self.validate_bom()
 		self.validate_finished_goods()
 		self.validate_with_material_request()
+		self.distribute_taxes()
 		self.validate_valuation_rate()
 		self.set_total_incoming_outgoing_value()
 		self.set_total_amount()
@@ -221,7 +222,7 @@
 				if d.s_warehouse and not d.t_warehouse:
 					valuation_at_source += flt(d.amount)
 				if d.t_warehouse and not d.s_warehouse:
-					valuation_at_target += flt(d.amount)
+					valuation_at_target += flt(d.amount) + flt(d.tax_amount)
 
 			if valuation_at_target + 0.001 < valuation_at_source:
 				frappe.throw(_("Total valuation ({0}) for manufactured or repacked item(s) can not be less than total valuation of raw materials ({1})").format(valuation_at_target,
@@ -230,10 +231,10 @@
 	def set_total_incoming_outgoing_value(self):
 		self.total_incoming_value = self.total_outgoing_value = 0.0
 		for d in self.get("items"):
-			if d.s_warehouse:
-				self.total_incoming_value += flt(d.amount)
 			if d.t_warehouse:
-				self.total_outgoing_value += flt(d.amount)
+				self.total_incoming_value += flt(d.amount)
+			if d.s_warehouse:
+				self.total_outgoing_value += flt(d.amount) + flt(d.tax_amount)
 
 		self.value_difference = self.total_outgoing_value - self.total_incoming_value
 
@@ -316,7 +317,7 @@
 			bom = frappe.db.get_value("BOM", bom_no, ["operating_cost", "quantity"], as_dict=1)
 			operation_cost_per_unit = flt(bom.operating_cost) / flt(bom.quantity)
 
-		return operation_cost_per_unit + (flt(self.additional_operating_cost) / flt(qty))
+		return operation_cost_per_unit
 
 	def validate_purchase_order(self):
 		"""Throw exception if more raw material is transferred against Purchase Order than in
@@ -402,22 +403,23 @@
 		
 		for d in self.get("items"):
 			tax_amount = flt(d.tax_amount, d.precision("tax_amount"))
-			gl_entries.append(self.get_gl_dict({
-				"account": d.expense_account,
-				"against": expenses_included_in_valuation,
-				"cost_center": d.cost_center,
-				"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
-				"debit": tax_amount
-			}))
+			if tax_amount:			
+				gl_entries.append(self.get_gl_dict({
+					"account": expenses_included_in_valuation,
+					"against": d.expense_account,
+					"cost_center": d.cost_center,
+					"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
+					"credit": tax_amount
+				}))
 			
-			gl_entries.append(self.get_gl_dict({
-				"account": expenses_included_in_valuation,
-				"against": warehouse_account[d.warehouse],
-				"cost_center": d.cost_center,
-				"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
-				"credit": tax_amount
-			}))
-			
+				gl_entries.append(self.get_gl_dict({
+					"account": d.expense_account,
+					"against": expenses_included_in_valuation,
+					"cost_center": d.cost_center,
+					"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
+					"credit": -1 * tax_amount
+				}))
+
 		return gl_entries
 
 	def update_production_order(self):
@@ -693,6 +695,12 @@
 					if expiry_date:
 						if getdate(self.posting_date) > getdate(expiry_date):
 							frappe.throw(_("Batch {0} of Item {1} has expired.").format(item.batch_no, item.item_code))
+							
+	def distribute_taxes(self):
+		self.total_taxes_and_charges = sum([flt(t.amount) for t in self.get("taxes")])
+		for d in self.get("items"):
+			if d.t_warehouse and self.total_incoming_value:
+				d.tax_amount = (flt(d.amount) / flt(self.total_incoming_value)) * self.total_taxes_and_charges
 
 
 @frappe.whitelist()
diff --git a/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json b/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json
index a373185..dcd46bd 100644
--- a/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json
+++ b/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json
@@ -161,6 +161,13 @@
    "read_only": 1
   }, 
   {
+   "fieldname": "tax_amount", 
+   "fieldtype": "Currency", 
+   "label": "Tax Amount", 
+   "permlevel": 0, 
+   "precision": ""
+  }, 
+  {
    "fieldname": "col_break3", 
    "fieldtype": "Column Break", 
    "permlevel": 0
@@ -344,7 +351,7 @@
  ], 
  "idx": 1, 
  "istable": 1, 
- "modified": "2015-07-02 05:32:56.511570", 
+ "modified": "2015-07-24 17:03:44.214018", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Stock Entry Detail",