From 1efb31724326a8778af8d3620d39c4e1defccf35 Mon Sep 17 00:00:00 2001 From: Anupam Date: Mon, 28 Mar 2022 14:36:43 +0530 Subject: [PATCH] feat: configurable Contract naming --- erpnext/crm/doctype/contract/contract.js | 11 ++++++++++ erpnext/crm/doctype/contract/contract.json | 13 +++++++++++- erpnext/crm/doctype/contract/contract.py | 21 ++++++++++++------- .../selling_settings/selling_settings.json | 12 ++++++++--- 4 files changed, 45 insertions(+), 12 deletions(-) diff --git a/erpnext/crm/doctype/contract/contract.js b/erpnext/crm/doctype/contract/contract.js index 7848de7a727..8751edbc9b2 100644 --- a/erpnext/crm/doctype/contract/contract.js +++ b/erpnext/crm/doctype/contract/contract.js @@ -2,6 +2,17 @@ // For license information, please see license.txt frappe.ui.form.on("Contract", { + onload: function(frm) { + frappe.db.get_value( + "Selling Settings", + "Selling Settings", + "contract_naming_by", + (r) => { + frm.toggle_display("naming_series", r.contract_naming_by === "Naming Series"); + } + ); + }, + contract_template: function (frm) { if (frm.doc.contract_template) { frappe.call({ diff --git a/erpnext/crm/doctype/contract/contract.json b/erpnext/crm/doctype/contract/contract.json index de3230f0e67..8a65ca5f20d 100755 --- a/erpnext/crm/doctype/contract/contract.json +++ b/erpnext/crm/doctype/contract/contract.json @@ -2,11 +2,13 @@ "actions": [], "allow_import": 1, "allow_rename": 1, + "autoname": "naming_series:", "creation": "2018-04-12 06:32:04.582486", "doctype": "DocType", "editable_grid": 1, "engine": "InnoDB", "field_order": [ + "naming_series", "party_type", "is_signed", "cb_party", @@ -244,11 +246,20 @@ "fieldname": "authorised_by_section", "fieldtype": "Section Break", "label": "Authorised By" + }, + { + "fieldname": "naming_series", + "fieldtype": "Select", + "label": "Naming Series", + "no_copy": 1, + "options": "CRM-CONTR-.YYYY.-", + "reqd": 1, + "set_only_once": 1 } ], "is_submittable": 1, "links": [], - "modified": "2020-12-07 11:15:58.385521", + "modified": "2022-03-28 10:22:11.156658", "modified_by": "Administrator", "module": "CRM", "name": "Contract", diff --git a/erpnext/crm/doctype/contract/contract.py b/erpnext/crm/doctype/contract/contract.py index e21f46a3837..86eaf07f1b5 100644 --- a/erpnext/crm/doctype/contract/contract.py +++ b/erpnext/crm/doctype/contract/contract.py @@ -5,22 +5,27 @@ import frappe from frappe import _ from frappe.model.document import Document +from frappe.model.naming import set_name_by_naming_series from frappe.utils import getdate, nowdate class Contract(Document): def autoname(self): - name = self.party_name + if frappe.db.get_single_value("Selling Settings", "contract_naming_by") == "Naming Series": + set_name_by_naming_series(self) - if self.contract_template: - name += " - {} Agreement".format(self.contract_template) + else: + name = self.party_name - # 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", "%{}%".format(name)]})) - name = "{} - {}".format(name, count) + if self.contract_template: + name += " - {} Agreement".format(self.contract_template) - self.name = _(name) + # 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", "%{}%".format(name)]})) + name = "{} - {}".format(name, count) + + self.name = _(name) def validate(self): self.validate_dates() diff --git a/erpnext/selling/doctype/selling_settings/selling_settings.json b/erpnext/selling/doctype/selling_settings/selling_settings.json index a0c1c85dd52..eabfd7d2e22 100644 --- a/erpnext/selling/doctype/selling_settings/selling_settings.json +++ b/erpnext/selling/doctype/selling_settings/selling_settings.json @@ -13,6 +13,7 @@ "territory", "crm_settings_section", "campaign_naming_by", + "contract_naming_by", "default_valid_till", "column_break_9", "close_opportunity_after_days", @@ -29,7 +30,6 @@ "so_required", "dn_required", "sales_update_frequency", - "column_break_5", "allow_multiple_items", "allow_against_multiple_purchase_orders", "hide_tax_id" @@ -193,6 +193,12 @@ "fieldname": "sales_transactions_settings_section", "fieldtype": "Section Break", "label": "Transaction Settings" + }, + { + "fieldname": "contract_naming_by", + "fieldtype": "Select", + "label": "Contract Naming By", + "options": "Party Name\nNaming Series" } ], "icon": "fa fa-cog", @@ -200,7 +206,7 @@ "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2021-09-14 22:05:06.139820", + "modified": "2022-03-28 12:18:06.768403", "modified_by": "Administrator", "module": "Selling", "name": "Selling Settings", @@ -219,4 +225,4 @@ "sort_field": "modified", "sort_order": "DESC", "track_changes": 1 -} +} \ No newline at end of file