Skip to content

Commit 1d9bf2d

Browse files
fix: improve Sales Invoice naming logic and add POS Profile validation
- Skip custom naming logic for non-POS invoices - Return early if no POS Profile is set on the document - Validate POS Profile existence and throw an error if invalid - Apply custom naming only when restaurant prefixing is enabled - Use aggregator prefix when available, otherwise fallback to invoice prefix - Let ERPNext handle default naming when custom rules do not apply
1 parent 12747c0 commit 1d9bf2d

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

ury/ury/hooks/ury_sales_invoice.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,33 @@ def on_update(doc,method):
88
aggregator_unpaid(doc,method)
99

1010
def sales_invoice_naming(doc, method):
11-
pos_profile = frappe.db.get_value("POS Profile", doc.pos_profile, ["restaurant_prefix", "restaurant"], as_dict=True)
11+
if not doc.is_pos:
12+
return
13+
14+
if not doc.pos_profile:
15+
return
16+
17+
pos_profile = frappe.db.get_value(
18+
"POS Profile",
19+
doc.pos_profile,
20+
["restaurant_prefix", "restaurant"],
21+
as_dict=True
22+
)
23+
24+
if not pos_profile:
25+
frappe.throw(f"POS Profile '{doc.pos_profile}' does not exist. Please select a valid POS Profile.")
26+
1227
restaurant = pos_profile.get("restaurant")
1328

1429
if pos_profile.get("restaurant_prefix") == 1 and restaurant:
15-
1630
if doc.order_type == "Aggregators":
1731

1832
# Get the aggregator series prefix
19-
aggregator_series_prefix = frappe.db.get_value("URY Restaurant", restaurant, "aggregator_series_prefix")
33+
aggregator_series_prefix = frappe.db.get_value(
34+
"URY Restaurant",
35+
restaurant,
36+
"aggregator_series_prefix"
37+
)
2038

2139
if aggregator_series_prefix:
2240
doc.naming_series = "SINV-" + aggregator_series_prefix

0 commit comments

Comments
 (0)