Skip to content

Commit

Permalink
feat: use Year Of Settlement for naming (LAN-852)
Browse files Browse the repository at this point in the history
  • Loading branch information
barredterra committed Aug 31, 2024
1 parent ba32b70 commit 69dbbc8
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion landa/landa_sales/payment_entry/pament_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ def autoname(doc, event):
"""Create Company-specific Payment Entry name."""
from landa.utils import get_new_name

doc.name = get_new_name("ZAHL", doc.company, "Payment Entry")
doc.name = get_new_name("ZAHL", doc.company, "Payment Entry", doc.year_of_settlement)
4 changes: 2 additions & 2 deletions landa/landa_sales/sales_invoice/sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def autoname(doc, event):
from landa.utils import get_new_name

if doc.is_return:
doc.name = get_new_name("GUTS", doc.company, "Sales Invoice")
doc.name = get_new_name("GUTS", doc.company, "Sales Invoice", doc.year_of_settlement)
else:
doc.name = get_new_name("RECH", doc.company, "Sales Invoice")
doc.name = get_new_name("RECH", doc.company, "Sales Invoice", doc.year_of_settlement)


@frappe.whitelist()
Expand Down
2 changes: 1 addition & 1 deletion landa/landa_sales/sales_order/sales_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def autoname(doc, event):
"""Create Company-specific Sales Order name."""
from landa.utils import get_new_name

doc.name = get_new_name("BEST", doc.company, "Sales Order")
doc.name = get_new_name("BEST", doc.company, "Sales Order", doc.year_of_settlement)


def get_dashboard_data(data):
Expand Down
4 changes: 2 additions & 2 deletions landa/landa_stock/delivery_note/delivery_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def autoname(doc, event):
from landa.utils import get_new_name

if doc.is_return:
doc.name = get_new_name("RET", doc.company, "Delivery Note")
doc.name = get_new_name("RET", doc.company, "Delivery Note", doc.year_of_settlement)
else:
doc.name = get_new_name("LIEF", doc.company, "Delivery Note")
doc.name = get_new_name("LIEF", doc.company, "Delivery Note", doc.year_of_settlement)


@frappe.whitelist()
Expand Down
9 changes: 6 additions & 3 deletions landa/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from frappe.utils.nestedset import get_ancestors_of


def get_new_name(prefix, company, doctype):
def get_new_name(prefix: str, company: str, doctype: str, year: str | None = None) -> str:
"""
Create a document name like prefix-company-year-####.
Expand All @@ -18,8 +18,11 @@ def get_new_name(prefix, company, doctype):
from frappe.utils.data import nowdate

company_abbr = frappe.get_value("Company", company, "abbr")
current_year = nowdate()[:4] # note: y10k problem
return make_autoname(f"{prefix}-{company_abbr}-{current_year}-.####", doctype)

if not year:
year = nowdate()[:4] # note: y10k problem

return make_autoname(f"{prefix}-{company_abbr}-{year}-.####", doctype)


def welcome_email():
Expand Down

0 comments on commit 69dbbc8

Please sign in to comment.