diff --git a/taxes_az/taxes_az/doctype/vat_allocation/vat_allocation.json b/taxes_az/taxes_az/doctype/vat_allocation/vat_allocation.json index 25cbe3a..bcfab92 100644 --- a/taxes_az/taxes_az/doctype/vat_allocation/vat_allocation.json +++ b/taxes_az/taxes_az/doctype/vat_allocation/vat_allocation.json @@ -1,6 +1,5 @@ { "actions": [], - "autoname": "format:VAT-{year}-{month}", "creation": "2025-09-29 19:03:22.767217", "doctype": "DocType", "engine": "InnoDB", @@ -240,7 +239,6 @@ "modified_by": "Administrator", "module": "Taxes Az", "name": "VAT allocation", - "naming_rule": "Expression", "owner": "Administrator", "permissions": [ { diff --git a/taxes_az/taxes_az/doctype/vat_allocation/vat_allocation.py b/taxes_az/taxes_az/doctype/vat_allocation/vat_allocation.py index af10490..f295821 100644 --- a/taxes_az/taxes_az/doctype/vat_allocation/vat_allocation.py +++ b/taxes_az/taxes_az/doctype/vat_allocation/vat_allocation.py @@ -8,6 +8,27 @@ import json ROUNDING_TOLERANCE = Decimal('0.01') class VATallocation(Document): + def autoname(self): + """ + Generate unique name for the document + - For submitted documents or first draft: VAT-{year}-{month} + - For additional drafts: VAT-{year}-{month}-{counter} + """ + if not self.year or not self.month: + frappe.throw(_("Year and Month are required")) + + base_name = f"VAT-{self.year}-{self.month}" + + # Check if base name already exists + if frappe.db.exists('VAT allocation', base_name): + # Add counter for additional drafts + counter = 1 + while frappe.db.exists('VAT allocation', f"{base_name}-{counter}"): + counter += 1 + self.name = f"{base_name}-{counter}" + else: + self.name = base_name + def validate(self): # Check if document with same year and month already exists self.validate_unique_year_month()