From 016924361a781c94c821c18c438bb93df1aa9efd Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 23 May 2025 13:50:46 +0530 Subject: [PATCH 1/3] refactor: full name field in contract --- erpnext/crm/doctype/contract/contract.json | 13 +++++++++++-- erpnext/crm/doctype/contract/contract.py | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/erpnext/crm/doctype/contract/contract.json b/erpnext/crm/doctype/contract/contract.json index 2dc62d895fa..b98e5c5a64c 100755 --- a/erpnext/crm/doctype/contract/contract.json +++ b/erpnext/crm/doctype/contract/contract.json @@ -14,6 +14,7 @@ "party_user", "status", "fulfilment_status", + "party_full_name", "sb_terms", "start_date", "cb_date", @@ -244,11 +245,18 @@ "fieldname": "authorised_by_section", "fieldtype": "Section Break", "label": "Authorised By" + }, + { + "fieldname": "party_full_name", + "fieldtype": "Data", + "label": "Party Full Name", + "read_only": 1 } ], + "grid_page_length": 50, "is_submittable": 1, "links": [], - "modified": "2024-03-27 13:06:46.177457", + "modified": "2025-05-23 13:54:03.346537", "modified_by": "Administrator", "module": "CRM", "name": "Contract", @@ -315,10 +323,11 @@ "write": 1 } ], + "row_format": "Dynamic", "show_name_in_global_search": 1, "sort_field": "creation", "sort_order": "DESC", "states": [], "track_changes": 1, "track_seen": 1 -} \ No newline at end of file +} diff --git a/erpnext/crm/doctype/contract/contract.py b/erpnext/crm/doctype/contract/contract.py index 6c3aace6fd8..1951dd25dee 100644 --- a/erpnext/crm/doctype/contract/contract.py +++ b/erpnext/crm/doctype/contract/contract.py @@ -34,6 +34,7 @@ class Contract(Document): fulfilment_terms: DF.Table[ContractFulfilmentChecklist] ip_address: DF.Data | None is_signed: DF.Check + party_full_name: DF.Data | None party_name: DF.DynamicLink party_type: DF.Literal["Customer", "Supplier", "Employee"] party_user: DF.Link | None From 752024e222b9d74b4193f410bf4a3ec840810b28 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 23 May 2025 14:04:07 +0530 Subject: [PATCH 2/3] refactor: fetch party name on selection --- erpnext/crm/doctype/contract/contract.js | 6 ++++++ erpnext/crm/doctype/contract/contract.py | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/erpnext/crm/doctype/contract/contract.js b/erpnext/crm/doctype/contract/contract.js index 8d44c22db28..42bd7f9b769 100644 --- a/erpnext/crm/doctype/contract/contract.js +++ b/erpnext/crm/doctype/contract/contract.js @@ -29,4 +29,10 @@ frappe.ui.form.on("Contract", { }); } }, + party_name: function (frm) { + let field = frm.doc.party_type.toLowerCase() + "_name"; + frappe.db.get_value(frm.doc.party_type, frm.doc.party_name, field, (r) => { + frm.set_value("party_full_name", r[field]); + }); + }, }); diff --git a/erpnext/crm/doctype/contract/contract.py b/erpnext/crm/doctype/contract/contract.py index 1951dd25dee..64f89552062 100644 --- a/erpnext/crm/doctype/contract/contract.py +++ b/erpnext/crm/doctype/contract/contract.py @@ -60,10 +60,17 @@ class Contract(Document): self.name = _(name) def validate(self): + self.set_missing_values() self.validate_dates() self.update_contract_status() self.update_fulfilment_status() + def set_missing_values(self): + if not self.party_full_name: + field = self.party_type.lower() + "_name" + if res := frappe.db.get_value(self.party_type, self.party_name, field): + self.party_full_name = res + def before_submit(self): self.signed_by_company = frappe.session.user From 8e2221178b00f8f148ad38bb90a6928ade9bdc23 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 23 May 2025 14:24:50 +0530 Subject: [PATCH 3/3] refactor: patch old contract with full party name --- erpnext/patches.txt | 1 + .../patches/v14_0/update_full_name_in_contract.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 erpnext/patches/v14_0/update_full_name_in_contract.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 143ec05455d..3f27e4ce26a 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -415,3 +415,4 @@ erpnext.patches.v15_0.set_grand_total_to_default_mop execute:frappe.db.set_single_value("Accounts Settings", "use_new_budget_controller", True) erpnext.patches.v15_0.rename_group_by_to_categorize_by_in_custom_reports erpnext.patches.v15_0.remove_agriculture_roles +erpnext.patches.v14_0.update_full_name_in_contract diff --git a/erpnext/patches/v14_0/update_full_name_in_contract.py b/erpnext/patches/v14_0/update_full_name_in_contract.py new file mode 100644 index 00000000000..19ee055ad12 --- /dev/null +++ b/erpnext/patches/v14_0/update_full_name_in_contract.py @@ -0,0 +1,15 @@ +import frappe +from frappe import qb + + +def execute(): + con = qb.DocType("Contract") + for c in ( + qb.from_(con) + .select(con.name, con.party_type, con.party_name) + .where(con.party_full_name.isnull()) + .run(as_dict=True) + ): + field = c.party_type.lower() + "_name" + if res := frappe.db.get_value(c.party_type, c.party_name, field): + frappe.db.set_value("Contract", c.name, "party_full_name", res)