refactor: department creation (#31548)
- all department creation always fails after first company, this is handled in exception handling code but better to not attempt this in first place. - move department creation to company.py this has nothing to do with setup and previous function signature made no sense.
This commit is contained in:
parent
0b5101d9c7
commit
bc3f99321a
@ -10,8 +10,9 @@ from frappe import _
|
|||||||
from frappe.cache_manager import clear_defaults_cache
|
from frappe.cache_manager import clear_defaults_cache
|
||||||
from frappe.contacts.address_and_contact import load_address_and_contact
|
from frappe.contacts.address_and_contact import load_address_and_contact
|
||||||
from frappe.custom.doctype.property_setter.property_setter import make_property_setter
|
from frappe.custom.doctype.property_setter.property_setter import make_property_setter
|
||||||
|
from frappe.desk.page.setup_wizard.setup_wizard import make_records
|
||||||
from frappe.utils import cint, formatdate, get_timestamp, today
|
from frappe.utils import cint, formatdate, get_timestamp, today
|
||||||
from frappe.utils.nestedset import NestedSet
|
from frappe.utils.nestedset import NestedSet, rebuild_tree
|
||||||
|
|
||||||
from erpnext.accounts.doctype.account.account import get_account_currency
|
from erpnext.accounts.doctype.account.account import get_account_currency
|
||||||
from erpnext.setup.setup_wizard.operations.taxes_setup import setup_taxes_and_charges
|
from erpnext.setup.setup_wizard.operations.taxes_setup import setup_taxes_and_charges
|
||||||
@ -150,9 +151,7 @@ class Company(NestedSet):
|
|||||||
self.create_default_tax_template()
|
self.create_default_tax_template()
|
||||||
|
|
||||||
if not frappe.db.get_value("Department", {"company": self.name}):
|
if not frappe.db.get_value("Department", {"company": self.name}):
|
||||||
from erpnext.setup.setup_wizard.operations.install_fixtures import install_post_company_fixtures
|
self.create_default_departments()
|
||||||
|
|
||||||
install_post_company_fixtures(frappe._dict({"company_name": self.name}))
|
|
||||||
|
|
||||||
if not frappe.local.flags.ignore_chart_of_accounts:
|
if not frappe.local.flags.ignore_chart_of_accounts:
|
||||||
self.set_default_accounts()
|
self.set_default_accounts()
|
||||||
@ -224,6 +223,104 @@ class Company(NestedSet):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def create_default_departments(self):
|
||||||
|
records = [
|
||||||
|
# Department
|
||||||
|
{
|
||||||
|
"doctype": "Department",
|
||||||
|
"department_name": _("All Departments"),
|
||||||
|
"is_group": 1,
|
||||||
|
"parent_department": "",
|
||||||
|
"__condition": lambda: not frappe.db.exists("Department", _("All Departments")),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"doctype": "Department",
|
||||||
|
"department_name": _("Accounts"),
|
||||||
|
"parent_department": _("All Departments"),
|
||||||
|
"company": self.name,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"doctype": "Department",
|
||||||
|
"department_name": _("Marketing"),
|
||||||
|
"parent_department": _("All Departments"),
|
||||||
|
"company": self.name,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"doctype": "Department",
|
||||||
|
"department_name": _("Sales"),
|
||||||
|
"parent_department": _("All Departments"),
|
||||||
|
"company": self.name,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"doctype": "Department",
|
||||||
|
"department_name": _("Purchase"),
|
||||||
|
"parent_department": _("All Departments"),
|
||||||
|
"company": self.name,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"doctype": "Department",
|
||||||
|
"department_name": _("Operations"),
|
||||||
|
"parent_department": _("All Departments"),
|
||||||
|
"company": self.name,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"doctype": "Department",
|
||||||
|
"department_name": _("Production"),
|
||||||
|
"parent_department": _("All Departments"),
|
||||||
|
"company": self.name,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"doctype": "Department",
|
||||||
|
"department_name": _("Dispatch"),
|
||||||
|
"parent_department": _("All Departments"),
|
||||||
|
"company": self.name,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"doctype": "Department",
|
||||||
|
"department_name": _("Customer Service"),
|
||||||
|
"parent_department": _("All Departments"),
|
||||||
|
"company": self.name,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"doctype": "Department",
|
||||||
|
"department_name": _("Human Resources"),
|
||||||
|
"parent_department": _("All Departments"),
|
||||||
|
"company": self.name,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"doctype": "Department",
|
||||||
|
"department_name": _("Management"),
|
||||||
|
"parent_department": _("All Departments"),
|
||||||
|
"company": self.name,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"doctype": "Department",
|
||||||
|
"department_name": _("Quality Management"),
|
||||||
|
"parent_department": _("All Departments"),
|
||||||
|
"company": self.name,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"doctype": "Department",
|
||||||
|
"department_name": _("Research & Development"),
|
||||||
|
"parent_department": _("All Departments"),
|
||||||
|
"company": self.name,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"doctype": "Department",
|
||||||
|
"department_name": _("Legal"),
|
||||||
|
"parent_department": _("All Departments"),
|
||||||
|
"company": self.name,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
# Make root department with NSM updation
|
||||||
|
make_records(records[:1])
|
||||||
|
|
||||||
|
frappe.local.flags.ignore_update_nsm = True
|
||||||
|
make_records(records)
|
||||||
|
frappe.local.flags.ignore_update_nsm = False
|
||||||
|
rebuild_tree("Department", "parent_department")
|
||||||
|
|
||||||
def validate_coa_input(self):
|
def validate_coa_input(self):
|
||||||
if self.create_chart_of_accounts_based_on == "Existing Company":
|
if self.create_chart_of_accounts_based_on == "Existing Company":
|
||||||
self.chart_of_accounts = None
|
self.chart_of_accounts = None
|
||||||
|
@ -12,7 +12,6 @@ from frappe.desk.doctype.global_search_settings.global_search_settings import (
|
|||||||
)
|
)
|
||||||
from frappe.desk.page.setup_wizard.setup_wizard import make_records
|
from frappe.desk.page.setup_wizard.setup_wizard import make_records
|
||||||
from frappe.utils import cstr, getdate
|
from frappe.utils import cstr, getdate
|
||||||
from frappe.utils.nestedset import rebuild_tree
|
|
||||||
|
|
||||||
from erpnext.accounts.doctype.account.account import RootNotEditable
|
from erpnext.accounts.doctype.account.account import RootNotEditable
|
||||||
from erpnext.regional.address_template.setup import set_up_address_templates
|
from erpnext.regional.address_template.setup import set_up_address_templates
|
||||||
@ -656,104 +655,6 @@ def install_company(args):
|
|||||||
make_records(records)
|
make_records(records)
|
||||||
|
|
||||||
|
|
||||||
def install_post_company_fixtures(args=None):
|
|
||||||
records = [
|
|
||||||
# Department
|
|
||||||
{
|
|
||||||
"doctype": "Department",
|
|
||||||
"department_name": _("All Departments"),
|
|
||||||
"is_group": 1,
|
|
||||||
"parent_department": "",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"doctype": "Department",
|
|
||||||
"department_name": _("Accounts"),
|
|
||||||
"parent_department": _("All Departments"),
|
|
||||||
"company": args.company_name,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"doctype": "Department",
|
|
||||||
"department_name": _("Marketing"),
|
|
||||||
"parent_department": _("All Departments"),
|
|
||||||
"company": args.company_name,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"doctype": "Department",
|
|
||||||
"department_name": _("Sales"),
|
|
||||||
"parent_department": _("All Departments"),
|
|
||||||
"company": args.company_name,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"doctype": "Department",
|
|
||||||
"department_name": _("Purchase"),
|
|
||||||
"parent_department": _("All Departments"),
|
|
||||||
"company": args.company_name,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"doctype": "Department",
|
|
||||||
"department_name": _("Operations"),
|
|
||||||
"parent_department": _("All Departments"),
|
|
||||||
"company": args.company_name,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"doctype": "Department",
|
|
||||||
"department_name": _("Production"),
|
|
||||||
"parent_department": _("All Departments"),
|
|
||||||
"company": args.company_name,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"doctype": "Department",
|
|
||||||
"department_name": _("Dispatch"),
|
|
||||||
"parent_department": _("All Departments"),
|
|
||||||
"company": args.company_name,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"doctype": "Department",
|
|
||||||
"department_name": _("Customer Service"),
|
|
||||||
"parent_department": _("All Departments"),
|
|
||||||
"company": args.company_name,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"doctype": "Department",
|
|
||||||
"department_name": _("Human Resources"),
|
|
||||||
"parent_department": _("All Departments"),
|
|
||||||
"company": args.company_name,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"doctype": "Department",
|
|
||||||
"department_name": _("Management"),
|
|
||||||
"parent_department": _("All Departments"),
|
|
||||||
"company": args.company_name,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"doctype": "Department",
|
|
||||||
"department_name": _("Quality Management"),
|
|
||||||
"parent_department": _("All Departments"),
|
|
||||||
"company": args.company_name,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"doctype": "Department",
|
|
||||||
"department_name": _("Research & Development"),
|
|
||||||
"parent_department": _("All Departments"),
|
|
||||||
"company": args.company_name,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"doctype": "Department",
|
|
||||||
"department_name": _("Legal"),
|
|
||||||
"parent_department": _("All Departments"),
|
|
||||||
"company": args.company_name,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
# Make root department with NSM updation
|
|
||||||
make_records(records[:1])
|
|
||||||
|
|
||||||
frappe.local.flags.ignore_update_nsm = True
|
|
||||||
make_records(records[1:])
|
|
||||||
frappe.local.flags.ignore_update_nsm = False
|
|
||||||
rebuild_tree("Department", "parent_department")
|
|
||||||
|
|
||||||
|
|
||||||
def install_defaults(args=None):
|
def install_defaults(args=None):
|
||||||
records = [
|
records = [
|
||||||
# Price Lists
|
# Price Lists
|
||||||
|
Loading…
x
Reference in New Issue
Block a user