Merge pull request #39195 from GursheenK/no-copy-party-balance

fix: avoid copying party balance on duplication of PE
diff --git a/erpnext/accounts/doctype/bank_reconciliation_tool/bank_reconciliation_tool.py b/erpnext/accounts/doctype/bank_reconciliation_tool/bank_reconciliation_tool.py
index 0779a09..9e6b51d 100644
--- a/erpnext/accounts/doctype/bank_reconciliation_tool/bank_reconciliation_tool.py
+++ b/erpnext/accounts/doctype/bank_reconciliation_tool/bank_reconciliation_tool.py
@@ -444,6 +444,10 @@
 	vouchers = json.loads(vouchers)
 	transaction = frappe.get_doc("Bank Transaction", bank_transaction_name)
 	transaction.add_payment_entries(vouchers)
+	transaction.validate_duplicate_references()
+	transaction.allocate_payment_entries()
+	transaction.update_allocated_amount()
+	transaction.set_status()
 	transaction.save()
 
 	return transaction
diff --git a/erpnext/accounts/doctype/bank_transaction/bank_transaction.py b/erpnext/accounts/doctype/bank_transaction/bank_transaction.py
index 57f7c0e..8d82123 100644
--- a/erpnext/accounts/doctype/bank_transaction/bank_transaction.py
+++ b/erpnext/accounts/doctype/bank_transaction/bank_transaction.py
@@ -3,12 +3,11 @@
 
 import frappe
 from frappe import _
+from frappe.model.document import Document
 from frappe.utils import flt
 
-from erpnext.controllers.status_updater import StatusUpdater
 
-
-class BankTransaction(StatusUpdater):
+class BankTransaction(Document):
 	# begin: auto-generated types
 	# This code is auto-generated. Do not modify anything in this block.
 
@@ -50,6 +49,15 @@
 	def validate(self):
 		self.validate_duplicate_references()
 
+	def set_status(self):
+		if self.docstatus == 2:
+			self.db_set("status", "Cancelled")
+		elif self.docstatus == 1:
+			if self.unallocated_amount > 0:
+				self.db_set("status", "Unreconciled")
+			elif self.unallocated_amount <= 0:
+				self.db_set("status", "Reconciled")
+
 	def validate_duplicate_references(self):
 		"""Make sure the same voucher is not allocated twice within the same Bank Transaction"""
 		if not self.payment_entries:
@@ -88,7 +96,7 @@
 		for payment_entry in self.payment_entries:
 			self.clear_linked_payment_entry(payment_entry, for_cancel=True)
 
-		self.set_status(update=True)
+		self.set_status()
 
 	def add_payment_entries(self, vouchers):
 		"Add the vouchers with zero allocation. Save() will perform the allocations and clearance"
diff --git a/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.json b/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.json
index be35914..7383816 100644
--- a/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.json
+++ b/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.json
@@ -9,6 +9,7 @@
  "field_order": [
   "asset",
   "naming_series",
+  "company",
   "column_break_2",
   "gross_purchase_amount",
   "opening_accumulated_depreciation",
@@ -193,12 +194,20 @@
    "fieldtype": "Check",
    "label": "Depreciate based on shifts",
    "read_only": 1
+  },
+  {
+   "fetch_from": "asset.company",
+   "fieldname": "company",
+   "fieldtype": "Link",
+   "label": "Company",
+   "options": "Company",
+   "read_only": 1
   }
  ],
  "index_web_pages_for_search": 1,
  "is_submittable": 1,
  "links": [],
- "modified": "2023-11-29 00:57:00.461998",
+ "modified": "2024-01-08 16:31:04.533928",
  "modified_by": "Administrator",
  "module": "Assets",
  "name": "Asset Depreciation Schedule",
diff --git a/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py b/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py
index 67234cc..4c94be5 100644
--- a/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py
+++ b/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py
@@ -35,6 +35,7 @@
 
 		amended_from: DF.Link | None
 		asset: DF.Link
+		company: DF.Link | None
 		daily_prorata_based: DF.Check
 		depreciation_method: DF.Literal[
 			"", "Straight Line", "Double Declining Balance", "Written Down Value", "Manual"
diff --git a/erpnext/controllers/status_updater.py b/erpnext/controllers/status_updater.py
index d09001c..297f8c2 100644
--- a/erpnext/controllers/status_updater.py
+++ b/erpnext/controllers/status_updater.py
@@ -131,11 +131,6 @@
 			"eval:self.status != 'Stopped' and self.per_ordered == 100 and self.docstatus == 1 and self.material_request_type == 'Manufacture'",
 		],
 	],
-	"Bank Transaction": [
-		["Unreconciled", "eval:self.docstatus == 1 and self.unallocated_amount>0"],
-		["Reconciled", "eval:self.docstatus == 1 and self.unallocated_amount<=0"],
-		["Cancelled", "eval:self.docstatus == 2"],
-	],
 	"POS Opening Entry": [
 		["Draft", None],
 		["Open", "eval:self.docstatus == 1 and not self.pos_closing_entry"],
diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py
index 2bfd4be..f64af50 100644
--- a/erpnext/manufacturing/doctype/production_plan/production_plan.py
+++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py
@@ -646,6 +646,10 @@
 				"project": self.project,
 			}
 
+			key = (d.item_code, d.sales_order, d.warehouse)
+			if not d.sales_order:
+				key = (d.name, d.item_code, d.warehouse)
+
 			if not item_details["project"] and d.sales_order:
 				item_details["project"] = frappe.get_cached_value("Sales Order", d.sales_order, "project")
 
@@ -654,12 +658,9 @@
 				item_dict[(d.item_code, d.material_request_item, d.warehouse)] = item_details
 			else:
 				item_details.update(
-					{
-						"qty": flt(item_dict.get((d.item_code, d.sales_order, d.warehouse), {}).get("qty"))
-						+ (flt(d.planned_qty) - flt(d.ordered_qty))
-					}
+					{"qty": flt(item_dict.get(key, {}).get("qty")) + (flt(d.planned_qty) - flt(d.ordered_qty))}
 				)
-				item_dict[(d.item_code, d.sales_order, d.warehouse)] = item_details
+				item_dict[key] = item_details
 
 		return item_dict
 
diff --git a/erpnext/manufacturing/doctype/production_plan/test_production_plan.py b/erpnext/manufacturing/doctype/production_plan/test_production_plan.py
index f6dfaa5..fedeb7a 100644
--- a/erpnext/manufacturing/doctype/production_plan/test_production_plan.py
+++ b/erpnext/manufacturing/doctype/production_plan/test_production_plan.py
@@ -672,7 +672,7 @@
 			items_data = pln.get_production_items()
 
 			# Update qty
-			items_data[(item, None, None)]["qty"] = qty
+			items_data[(pln.po_items[0].name, item, None)]["qty"] = qty
 
 			# Create and Submit Work Order for each item in items_data
 			for key, item in items_data.items():
@@ -1522,6 +1522,45 @@
 		for d in mr_items:
 			self.assertEqual(d.get("quantity"), 1000.0)
 
+	def test_fg_item_quantity(self):
+		from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse
+		from erpnext.stock.utils import get_or_make_bin
+
+		fg_item = make_item(properties={"is_stock_item": 1}).name
+		rm_item = make_item(properties={"is_stock_item": 1}).name
+
+		make_bom(item=fg_item, raw_materials=[rm_item], source_warehouse="_Test Warehouse - _TC")
+
+		pln = create_production_plan(item_code=fg_item, planned_qty=10, do_not_submit=1)
+
+		pln.append(
+			"po_items",
+			{
+				"item_code": rm_item,
+				"planned_qty": 20,
+				"bom_no": pln.po_items[0].bom_no,
+				"warehouse": pln.po_items[0].warehouse,
+				"planned_start_date": add_to_date(nowdate(), days=1),
+			},
+		)
+		pln.submit()
+		wo_qty = {}
+
+		for row in pln.po_items:
+			wo_qty[row.name] = row.planned_qty
+
+		pln.make_work_order()
+
+		work_orders = frappe.get_all(
+			"Work Order",
+			fields=["qty", "production_plan_item as name"],
+			filters={"production_plan": pln.name},
+		)
+		self.assertEqual(len(work_orders), 2)
+
+		for row in work_orders:
+			self.assertEqual(row.qty, wo_qty[row.name])
+
 
 def create_production_plan(**args):
 	"""
diff --git a/erpnext/projects/doctype/project/project.json b/erpnext/projects/doctype/project/project.json
index 715b09c..5917e9b 100644
--- a/erpnext/projects/doctype/project/project.json
+++ b/erpnext/projects/doctype/project/project.json
@@ -131,6 +131,7 @@
    "set_only_once": 1
   },
   {
+   "bold": 1,
    "fieldname": "expected_start_date",
    "fieldtype": "Date",
    "label": "Expected Start Date",
@@ -453,7 +454,7 @@
  "index_web_pages_for_search": 1,
  "links": [],
  "max_attachments": 4,
- "modified": "2023-08-28 22:27:28.370849",
+ "modified": "2024-01-08 16:01:34.598258",
  "modified_by": "Administrator",
  "module": "Projects",
  "name": "Project",
diff --git a/erpnext/projects/doctype/project/project.py b/erpnext/projects/doctype/project/project.py
index 751dcbd..d17d21c 100644
--- a/erpnext/projects/doctype/project/project.py
+++ b/erpnext/projects/doctype/project/project.py
@@ -19,6 +19,62 @@
 
 
 class Project(Document):
+	# begin: auto-generated types
+	# This code is auto-generated. Do not modify anything in this block.
+
+	from typing import TYPE_CHECKING
+
+	if TYPE_CHECKING:
+		from frappe.types import DF
+
+		from erpnext.projects.doctype.project_user.project_user import ProjectUser
+
+		actual_end_date: DF.Date | None
+		actual_start_date: DF.Date | None
+		actual_time: DF.Float
+		collect_progress: DF.Check
+		company: DF.Link
+		copied_from: DF.Data | None
+		cost_center: DF.Link | None
+		customer: DF.Link | None
+		daily_time_to_send: DF.Time | None
+		day_to_send: DF.Literal[
+			"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"
+		]
+		department: DF.Link | None
+		estimated_costing: DF.Currency
+		expected_end_date: DF.Date | None
+		expected_start_date: DF.Date | None
+		first_email: DF.Time | None
+		frequency: DF.Literal["Hourly", "Twice Daily", "Daily", "Weekly"]
+		from_time: DF.Time | None
+		gross_margin: DF.Currency
+		holiday_list: DF.Link | None
+		is_active: DF.Literal["Yes", "No"]
+		message: DF.Text | None
+		naming_series: DF.Literal["PROJ-.####"]
+		notes: DF.TextEditor | None
+		per_gross_margin: DF.Percent
+		percent_complete: DF.Percent
+		percent_complete_method: DF.Literal["Manual", "Task Completion", "Task Progress", "Task Weight"]
+		priority: DF.Literal["Medium", "Low", "High"]
+		project_name: DF.Data
+		project_template: DF.Link | None
+		project_type: DF.Link | None
+		sales_order: DF.Link | None
+		second_email: DF.Time | None
+		status: DF.Literal["Open", "Completed", "Cancelled"]
+		to_time: DF.Time | None
+		total_billable_amount: DF.Currency
+		total_billed_amount: DF.Currency
+		total_consumed_material_cost: DF.Currency
+		total_costing_amount: DF.Currency
+		total_purchase_cost: DF.Currency
+		total_sales_amount: DF.Currency
+		users: DF.Table[ProjectUser]
+		weekly_time_to_send: DF.Time | None
+	# end: auto-generated types
+
 	def onload(self):
 		self.set_onload(
 			"activity_summary",
diff --git a/erpnext/projects/doctype/task/task.json b/erpnext/projects/doctype/task/task.json
index 4d2d225..cc9832b 100644
--- a/erpnext/projects/doctype/task/task.json
+++ b/erpnext/projects/doctype/task/task.json
@@ -153,6 +153,7 @@
    "label": "Timeline"
   },
   {
+   "bold": 1,
    "fieldname": "exp_start_date",
    "fieldtype": "Date",
    "label": "Expected Start Date",
@@ -398,7 +399,7 @@
  "is_tree": 1,
  "links": [],
  "max_attachments": 5,
- "modified": "2023-11-20 11:42:41.884069",
+ "modified": "2024-01-08 16:00:41.296203",
  "modified_by": "Administrator",
  "module": "Projects",
  "name": "Task",
diff --git a/erpnext/public/js/utils/dimension_tree_filter.js b/erpnext/public/js/utils/dimension_tree_filter.js
index bb23f15..3f70c09 100644
--- a/erpnext/public/js/utils/dimension_tree_filter.js
+++ b/erpnext/public/js/utils/dimension_tree_filter.js
@@ -16,6 +16,8 @@
 			},
 			callback: function(r) {
 				me.accounting_dimensions = r.message[0];
+				// Ignoring "Project" as it is already handled specifically in Sales Order and Delivery Note
+				me.accounting_dimensions = me.accounting_dimensions.filter(x=>{return x.document_type != "Project"});
 				me.default_dimensions = r.message[1];
 				me.setup_filters(frm, doctype);
 			}
diff --git a/erpnext/stock/doctype/item/item.json b/erpnext/stock/doctype/item/item.json
index 13f3be8..6529bb2 100644
--- a/erpnext/stock/doctype/item/item.json
+++ b/erpnext/stock/doctype/item/item.json
@@ -202,6 +202,7 @@
    "label": "Allow Alternative Item"
   },
   {
+   "allow_in_quick_entry": 1,
    "bold": 1,
    "default": "1",
    "depends_on": "eval:!doc.is_fixed_asset",
@@ -239,6 +240,7 @@
    "label": "Standard Selling Rate"
   },
   {
+   "allow_in_quick_entry": 1,
    "default": "0",
    "fieldname": "is_fixed_asset",
    "fieldtype": "Check",
@@ -246,6 +248,7 @@
    "set_only_once": 1
   },
   {
+   "allow_in_quick_entry": 1,
    "depends_on": "is_fixed_asset",
    "fieldname": "asset_category",
    "fieldtype": "Link",
@@ -888,7 +891,7 @@
  "index_web_pages_for_search": 1,
  "links": [],
  "make_attachments_public": 1,
- "modified": "2023-09-18 15:41:32.688051",
+ "modified": "2024-01-08 18:09:30.225085",
  "modified_by": "Administrator",
  "module": "Stock",
  "name": "Item",
@@ -961,4 +964,4 @@
  "states": [],
  "title_field": "item_name",
  "track_changes": 1
-}
+}
\ No newline at end of file