Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special Character in Cost Center Name Causing Auto Naming Hit Error in Creating Budget #32390

Closed
erpitadmin opened this issue Sep 28, 2022 · 3 comments · Fixed by #32554
Closed
Assignees
Labels

Comments

@erpitadmin
Copy link

erpitadmin commented Sep 28, 2022

Information about bug

Because Budget is using Cost Center or Project name when creating its auto naming, so if special characters exist in Cost Center's name ( let's say 'P & L Company Cost Center' ), it will cause error in saving new Budget. But special character is allowed in Cost Center naming. Below is the code that causing issue.

erpnext/accounts/doctype/budget/budget.py

def autoname(self):
		self.name = make_autoname(
			self.get(frappe.scrub(self.budget_against)) + "/" + self.fiscal_year + "/.###"
		)

Module

accounts

Version

Frappe Version - v14.8.0
ERPNext Version - v14.2.0

Installation method

FrappeCloud

Relevant log output / Stack trace / Full Error Message.

Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 69, in application
    response = frappe.api.handle()
  File "apps/frappe/frappe/api.py", line 54, in handle
    return frappe.handler.handle()
  File "apps/frappe/frappe/handler.py", line 45, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/handler.py", line 83, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "apps/frappe/frappe/__init__.py", line 1598, in call
    return fn(*args, **newargs)
  File "apps/frappe/frappe/desk/form/save.py", line 22, in savedocs
    doc.save()
  File "apps/frappe/frappe/model/document.py", line 301, in save
    return self._save(*args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 323, in _save
    return self.insert()
  File "apps/frappe/frappe/model/document.py", line 250, in insert
    self.set_new_name(set_name=set_name, set_child_names=set_child_names)
  File "apps/frappe/frappe/model/document.py", line 446, in set_new_name
    set_new_name(self)
  File "apps/frappe/frappe/model/naming.py", line 163, in set_new_name
    doc.run_method("autoname")
  File "apps/frappe/frappe/model/document.py", line 928, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1268, in composer
    return composed(self, method, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1250, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "apps/frappe/frappe/model/document.py", line 925, in fn
    return method_object(*args, **kwargs)
  File "apps/erpnext/erpnext/accounts/doctype/budget/budget.py", line 27, in autoname
    self.name = make_autoname(
  File "apps/frappe/frappe/model/naming.py", line 285, in make_autoname
    return series.generate_next_name(doc)
  File "apps/frappe/frappe/model/naming.py", line 68, in generate_next_name
    self.validate()
  File "apps/frappe/frappe/model/naming.py", line 60, in validate
    frappe.throw(
  File "apps/frappe/frappe/__init__.py", line 523, in throw
    msgprint(
  File "apps/frappe/frappe/__init__.py", line 491, in msgprint
    _raise_exception()
  File "apps/frappe/frappe/__init__.py", line 443, in _raise_exception
    raise raise_exception(msg)
frappe.model.naming.InvalidNamingSeriesError: Special Characters except "-", "#", ".", "/", "{" and "}" not allowed in naming series
@ankush
Copy link
Member

ankush commented Oct 6, 2022

Just convert this to naming series and remove autoname

We shouldn't ever be hardcoding autoname in code like this 😅

@anandbaburajan
Copy link
Contributor

@ankush I didn't get how that solves the problem. Even after we convert it into a naming series, they can't use an '&' in the budget name right since it would still throw an InvalidNamingSeriesError because of the '&'. Also, are you suggesting to remove https://frappeframework.com/docs/v14/user/en/basics/doctypes/naming#by-controller-method?

@ankush
Copy link
Member

ankush commented Oct 7, 2022

@anandbaburajan they can. Naming series validation only applies on template and not field values. Here the code is passing field values already substituted in the template.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants