Added DocType override for Sales Invoice and Quotation naming

This commit is contained in:
Jeremy Rangel
2025-05-06 14:50:17 -07:00
parent 51bfdb2735
commit c51e7a8086
6 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,26 @@
import random
import frappe
from frappe.model.naming import parse_naming_series
from erpnext.selling.doctype.quotation.quotation import Quotation as OriginalQuotation
class Quotation(OriginalQuotation):
def autoname(self):
# Use selected naming series or default from meta
naming_series_pattern = self.naming_series or frappe.get_meta(self.doctype).get_field("naming_series").options.split("\n")[0]
# Step 1: Resolve dynamic placeholders (like .YYYY.) WITHOUT incrementing the counter
prefix = parse_naming_series(naming_series_pattern)
# Remove any trailing dash if it exists
prefix = prefix.rstrip("-")
# Step 2: Append a random 6-digit number
random_part = str(random.randint(100_000, 999_999)) # 6-digit number
name = f"{prefix}-{random_part}"
# Step 3: Ensure name is unique
while frappe.db.exists(self.doctype, name):
random_part = str(random.randint(100_000, 999_999)) # 6-digit number
name = f"{prefix}-{random_part}"
self.name = name

View File

@ -0,0 +1,26 @@
import random
import frappe
from frappe.model.naming import parse_naming_series
from erpnext.accounts.doctype.sales_invoice.sales_invoice import SalesInvoice as OriginalSalesInvoice
class SalesInvoice(OriginalSalesInvoice):
def autoname(self):
# Use selected naming series or default from meta
naming_series_pattern = self.naming_series or frappe.get_meta(self.doctype).get_field("naming_series").options.split("\n")[0]
# Step 1: Resolve dynamic placeholders (like .YYYY.) WITHOUT incrementing the counter
prefix = parse_naming_series(naming_series_pattern)
# Remove any trailing dash if it exists
prefix = prefix.rstrip("-")
# Step 2: Append a random 6-digit number
random_part = str(random.randint(100_000, 999_999))
name = f"{prefix}-{random_part}"
# Step 3: Ensure name is unique
while frappe.db.exists(self.doctype, name):
random_part = str(random.randint(100_000, 999_999))
name = f"{prefix}-{random_part}"
self.name = name