fix: contract autoname

This commit is contained in:
khushi
2025-06-19 14:03:42 +05:30
parent c94764ab52
commit e13e2bffe2

View File

@@ -6,6 +6,7 @@ import frappe
from frappe import _ from frappe import _
from frappe.model.document import Document from frappe.model.document import Document
from frappe.utils import getdate, nowdate from frappe.utils import getdate, nowdate
from frappe.model.naming import append_number_if_name_exists
class Contract(Document): class Contract(Document):
@@ -52,12 +53,7 @@ class Contract(Document):
if self.contract_template: if self.contract_template:
name += f" - {self.contract_template} Agreement" name += f" - {self.contract_template} Agreement"
# If identical, append contract name with the next number in the iteration self.name = append_number_if_name_exists("Contract", name)
if frappe.db.exists("Contract", name):
count = len(frappe.get_all("Contract", filters={"name": ["like", f"%{name}%"]}))
name = f"{name} - {count}"
self.name = _(name)
def validate(self): def validate(self):
self.set_missing_values() self.set_missing_values()