From e13e2bffe264180c2effc3c2cf36c4f0b15c384f Mon Sep 17 00:00:00 2001 From: khushi Date: Thu, 19 Jun 2025 14:03:42 +0530 Subject: [PATCH 1/8] fix: contract autoname --- erpnext/crm/doctype/contract/contract.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/erpnext/crm/doctype/contract/contract.py b/erpnext/crm/doctype/contract/contract.py index 64f89552062..559c89a9629 100644 --- a/erpnext/crm/doctype/contract/contract.py +++ b/erpnext/crm/doctype/contract/contract.py @@ -6,6 +6,7 @@ import frappe from frappe import _ from frappe.model.document import Document from frappe.utils import getdate, nowdate +from frappe.model.naming import append_number_if_name_exists class Contract(Document): @@ -52,12 +53,7 @@ class Contract(Document): if self.contract_template: name += f" - {self.contract_template} Agreement" - # If identical, append contract name with the next number in the iteration - if frappe.db.exists("Contract", name): - count = len(frappe.get_all("Contract", filters={"name": ["like", f"%{name}%"]})) - name = f"{name} - {count}" - - self.name = _(name) + self.name = append_number_if_name_exists("Contract", name) def validate(self): self.set_missing_values() From b55d1e61c7b9149fa180d46f0f4db536056feaf6 Mon Sep 17 00:00:00 2001 From: khushi Date: Thu, 19 Jun 2025 14:06:04 +0530 Subject: [PATCH 2/8] chore: test contract autoname --- erpnext/crm/doctype/contract/test_contract.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/erpnext/crm/doctype/contract/test_contract.py b/erpnext/crm/doctype/contract/test_contract.py index 2ea083834ce..e6a6ebb0f85 100644 --- a/erpnext/crm/doctype/contract/test_contract.py +++ b/erpnext/crm/doctype/contract/test_contract.py @@ -12,6 +12,19 @@ class TestContract(IntegrationTestCase): frappe.db.sql("delete from `tabContract`") self.contract_doc = get_contract() + def test_autoname_appends_suffix_for_duplicates(self): + contract_1 = self.contract_doc + contract_1.insert() + self.assertEqual(contract_1.name, "_Test Customer") + + contract_2 = get_contract() + contract_2.insert() + self.assertEqual(contract_2.name, "_Test Customer-1") + + contract_3 = get_contract() + contract_3.insert() + self.assertEqual(contract_3.name, "_Test Customer-2") + def test_validate_start_date_before_end_date(self): self.contract_doc.start_date = nowdate() self.contract_doc.end_date = add_days(nowdate(), -1) From f7e63936a9a0119de44296390b8b632399daedd1 Mon Sep 17 00:00:00 2001 From: khushi Date: Thu, 19 Jun 2025 15:07:44 +0530 Subject: [PATCH 3/8] chore: linters check --- erpnext/crm/doctype/contract/contract.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/crm/doctype/contract/contract.py b/erpnext/crm/doctype/contract/contract.py index 559c89a9629..ea4398d7bfa 100644 --- a/erpnext/crm/doctype/contract/contract.py +++ b/erpnext/crm/doctype/contract/contract.py @@ -5,8 +5,8 @@ import frappe from frappe import _ from frappe.model.document import Document -from frappe.utils import getdate, nowdate from frappe.model.naming import append_number_if_name_exists +from frappe.utils import getdate, nowdate class Contract(Document): From a4bb7c4e95c853fb0319a183c541e049242befae Mon Sep 17 00:00:00 2001 From: khushi Date: Thu, 19 Jun 2025 17:13:01 +0530 Subject: [PATCH 4/8] refactor: remove autoname --- erpnext/crm/doctype/contract/contract.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/erpnext/crm/doctype/contract/contract.py b/erpnext/crm/doctype/contract/contract.py index ea4398d7bfa..49988e546df 100644 --- a/erpnext/crm/doctype/contract/contract.py +++ b/erpnext/crm/doctype/contract/contract.py @@ -47,14 +47,6 @@ class Contract(Document): status: DF.Literal["Unsigned", "Active", "Inactive"] # end: auto-generated types - def autoname(self): - name = self.party_name - - if self.contract_template: - name += f" - {self.contract_template} Agreement" - - self.name = append_number_if_name_exists("Contract", name) - def validate(self): self.set_missing_values() self.validate_dates() From bf56c73c6c7d84ac5dcebbbd693abc15ecf508b8 Mon Sep 17 00:00:00 2001 From: khushi Date: Thu, 19 Jun 2025 17:45:22 +0530 Subject: [PATCH 5/8] feat: add naming series for Contract Doctype --- erpnext/crm/doctype/contract/contract.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/erpnext/crm/doctype/contract/contract.json b/erpnext/crm/doctype/contract/contract.json index b98e5c5a64c..336f51cfe04 100755 --- a/erpnext/crm/doctype/contract/contract.json +++ b/erpnext/crm/doctype/contract/contract.json @@ -2,6 +2,7 @@ "actions": [], "allow_import": 1, "allow_rename": 1, + "autoname": "CON-.YYYY.-.#####", "creation": "2018-04-12 06:32:04.582486", "doctype": "DocType", "editable_grid": 1, @@ -256,10 +257,11 @@ "grid_page_length": 50, "is_submittable": 1, "links": [], - "modified": "2025-05-23 13:54:03.346537", + "modified": "2025-06-19 17:27:19.908421", "modified_by": "Administrator", "module": "CRM", "name": "Contract", + "naming_rule": "Expression (old style)", "owner": "Administrator", "permissions": [ { @@ -328,6 +330,7 @@ "sort_field": "creation", "sort_order": "DESC", "states": [], + "title_field": "party_name", "track_changes": 1, "track_seen": 1 } From 0665691b881ddf2cb2e5a5af43a7d1dd4f24dcfd Mon Sep 17 00:00:00 2001 From: khushi8112 Date: Thu, 19 Jun 2025 18:09:10 +0530 Subject: [PATCH 6/8] feat: add search field for contract doctype --- erpnext/crm/doctype/contract/contract.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/crm/doctype/contract/contract.json b/erpnext/crm/doctype/contract/contract.json index 336f51cfe04..c5014542376 100755 --- a/erpnext/crm/doctype/contract/contract.json +++ b/erpnext/crm/doctype/contract/contract.json @@ -257,7 +257,7 @@ "grid_page_length": 50, "is_submittable": 1, "links": [], - "modified": "2025-06-19 17:27:19.908421", + "modified": "2025-06-19 17:48:45.049007", "modified_by": "Administrator", "module": "CRM", "name": "Contract", @@ -326,6 +326,7 @@ } ], "row_format": "Dynamic", + "search_fields": "party_type, party_name, contract_template", "show_name_in_global_search": 1, "sort_field": "creation", "sort_order": "DESC", From 4a027125bce7bb53e982eec0e960ba8027031b5c Mon Sep 17 00:00:00 2001 From: khushi8112 Date: Thu, 19 Jun 2025 18:09:54 +0530 Subject: [PATCH 7/8] refactor: remove test case --- erpnext/crm/doctype/contract/test_contract.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/erpnext/crm/doctype/contract/test_contract.py b/erpnext/crm/doctype/contract/test_contract.py index e6a6ebb0f85..2ea083834ce 100644 --- a/erpnext/crm/doctype/contract/test_contract.py +++ b/erpnext/crm/doctype/contract/test_contract.py @@ -12,19 +12,6 @@ class TestContract(IntegrationTestCase): frappe.db.sql("delete from `tabContract`") self.contract_doc = get_contract() - def test_autoname_appends_suffix_for_duplicates(self): - contract_1 = self.contract_doc - contract_1.insert() - self.assertEqual(contract_1.name, "_Test Customer") - - contract_2 = get_contract() - contract_2.insert() - self.assertEqual(contract_2.name, "_Test Customer-1") - - contract_3 = get_contract() - contract_3.insert() - self.assertEqual(contract_3.name, "_Test Customer-2") - def test_validate_start_date_before_end_date(self): self.contract_doc.start_date = nowdate() self.contract_doc.end_date = add_days(nowdate(), -1) From a1c0727d7b859737cc2265b98456577fb1b190c3 Mon Sep 17 00:00:00 2001 From: khushi8112 Date: Thu, 19 Jun 2025 18:40:37 +0530 Subject: [PATCH 8/8] chore: remove unused import --- erpnext/crm/doctype/contract/contract.py | 1 - 1 file changed, 1 deletion(-) diff --git a/erpnext/crm/doctype/contract/contract.py b/erpnext/crm/doctype/contract/contract.py index 49988e546df..223e0549ede 100644 --- a/erpnext/crm/doctype/contract/contract.py +++ b/erpnext/crm/doctype/contract/contract.py @@ -5,7 +5,6 @@ import frappe from frappe import _ from frappe.model.document import Document -from frappe.model.naming import append_number_if_name_exists from frappe.utils import getdate, nowdate