fix: create default warehouse (#47125)

This commit is contained in:
Raffael Meyer
2025-04-17 13:17:02 +02:00
committed by barredterra
parent 503b89a764
commit a766aa0837

View File

@@ -167,6 +167,7 @@ class Company(NestedSet):
frappe.clear_cache() frappe.clear_cache()
def create_default_warehouses(self): def create_default_warehouses(self):
parent_warehouse = None
for wh_detail in [ for wh_detail in [
{"warehouse_name": _("All Warehouses"), "is_group": 1}, {"warehouse_name": _("All Warehouses"), "is_group": 1},
{"warehouse_name": _("Stores"), "is_group": 0}, {"warehouse_name": _("Stores"), "is_group": 0},
@@ -174,24 +175,31 @@ class Company(NestedSet):
{"warehouse_name": _("Finished Goods"), "is_group": 0}, {"warehouse_name": _("Finished Goods"), "is_group": 0},
{"warehouse_name": _("Goods In Transit"), "is_group": 0, "warehouse_type": "Transit"}, {"warehouse_name": _("Goods In Transit"), "is_group": 0, "warehouse_type": "Transit"},
]: ]:
if not frappe.db.exists("Warehouse", "{} - {}".format(wh_detail["warehouse_name"], self.abbr)): if frappe.db.exists(
warehouse = frappe.get_doc( "Warehouse",
{ {
"doctype": "Warehouse", "warehouse_name": wh_detail["warehouse_name"],
"warehouse_name": wh_detail["warehouse_name"], "company": self.name,
"is_group": wh_detail["is_group"], },
"company": self.name, ):
"parent_warehouse": "{} - {}".format(_("All Warehouses"), self.abbr) continue
if not wh_detail["is_group"]
else "", warehouse = frappe.get_doc(
"warehouse_type": wh_detail["warehouse_type"] {
if "warehouse_type" in wh_detail "doctype": "Warehouse",
else None, "warehouse_name": wh_detail["warehouse_name"],
} "is_group": wh_detail["is_group"],
) "company": self.name,
warehouse.flags.ignore_permissions = True "parent_warehouse": parent_warehouse,
warehouse.flags.ignore_mandatory = True "warehouse_type": wh_detail.get("warehouse_type"),
warehouse.insert() }
)
warehouse.flags.ignore_permissions = True
warehouse.flags.ignore_mandatory = True
warehouse.insert()
if wh_detail["is_group"]:
parent_warehouse = warehouse.name
def create_default_accounts(self): def create_default_accounts(self):
from erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts import create_charts from erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts import create_charts