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 1c2470b6e4e..8a2c2e966e9 100644 --- a/erpnext/crm/doctype/contract/contract.py +++ b/erpnext/crm/doctype/contract/contract.py @@ -5,22 +5,32 @@ 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 = f"{name} - {self.contract_template} Agreement" - self.name = _(name) + # If identical, append contract name with the next number in the iteration + if frappe.db.exists("Contract", name): + count = frappe.db.count( + "Contract", + filters={ + "name": ("like", f"%{name}%"), + }, + ) + name = f"{name} - {count}" + + self.name = _(name) def validate(self): self.validate_dates() diff --git a/erpnext/education/doctype/student_admission/templates/student_admission_row.html b/erpnext/education/doctype/student_admission/templates/student_admission_row.html index 529d65184a8..dc4587bc940 100644 --- a/erpnext/education/doctype/student_admission/templates/student_admission_row.html +++ b/erpnext/education/doctype/student_admission/templates/student_admission_row.html @@ -1,6 +1,6 @@