mirror of
https://github.com/frappe/frappe_docker.git
synced 2026-06-17 13:55:08 +00:00
fix: use company abbr for warehouse names
ERPNext auto-appends the company abbreviation (e.g. "F") to warehouse names, not the full company name. Fixed create_warehouses(), the default_wh reference in raw material items, and the OnSite WIP server script to all resolve the abbr at runtime via frappe.db.get_value. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
97dbe774f1
commit
ff152a3020
1 changed files with 26 additions and 15 deletions
|
|
@ -12,6 +12,13 @@ import frappe.defaults
|
||||||
|
|
||||||
COMPANY = "Furnitex"
|
COMPANY = "Furnitex"
|
||||||
SITE = "frontend"
|
SITE = "frontend"
|
||||||
|
ABBR = None # resolved at runtime via get_abbr()
|
||||||
|
|
||||||
|
def get_abbr():
|
||||||
|
global ABBR
|
||||||
|
if not ABBR:
|
||||||
|
ABBR = frappe.db.get_value("Company", COMPANY, "abbr") or "F"
|
||||||
|
return ABBR
|
||||||
|
|
||||||
|
|
||||||
# ─────────────────────────────────────────────────────────────
|
# ─────────────────────────────────────────────────────────────
|
||||||
|
|
@ -124,22 +131,24 @@ def create_supplier_groups():
|
||||||
|
|
||||||
def create_warehouses():
|
def create_warehouses():
|
||||||
print("\n[4/9] Creating Warehouses...")
|
print("\n[4/9] Creating Warehouses...")
|
||||||
|
abbr = get_abbr()
|
||||||
|
|
||||||
# Find the company's root warehouse group
|
# Find the company's root warehouse group
|
||||||
root_wh = frappe.db.get_value(
|
root_wh = frappe.db.get_value(
|
||||||
"Warehouse",
|
"Warehouse",
|
||||||
{"company": COMPANY, "is_group": 1, "parent_warehouse": ["in", ["", None]]},
|
{"company": COMPANY, "is_group": 1},
|
||||||
"name"
|
"name"
|
||||||
)
|
)
|
||||||
if not root_wh:
|
if not root_wh:
|
||||||
root_wh = f"All Warehouses - {COMPANY}"
|
root_wh = f"All Warehouses - {abbr}"
|
||||||
|
|
||||||
warehouses = [
|
warehouses = [
|
||||||
("Main Store", root_wh, "Transit", 0),
|
("Main Store", root_wh, 0),
|
||||||
("Rejected Stock",root_wh, "Transit", 0),
|
("Rejected Stock", root_wh, 0),
|
||||||
]
|
]
|
||||||
for w_short, parent, w_type, is_group in warehouses:
|
for w_short, parent, is_group in warehouses:
|
||||||
w_full = f"{w_short} - {COMPANY}"
|
# ERPNext appends company abbr: "Main Store - F"
|
||||||
|
w_full = f"{w_short} - {abbr}"
|
||||||
if not exists("Warehouse", w_full):
|
if not exists("Warehouse", w_full):
|
||||||
d = frappe.get_doc({
|
d = frappe.get_doc({
|
||||||
"doctype": "Warehouse",
|
"doctype": "Warehouse",
|
||||||
|
|
@ -319,7 +328,7 @@ def create_raw_material_items():
|
||||||
_find_account("Stock Expenses", root_type="Expense") or
|
_find_account("Stock Expenses", root_type="Expense") or
|
||||||
_find_account("Expenses Included", root_type="Expense"))
|
_find_account("Expenses Included", root_type="Expense"))
|
||||||
|
|
||||||
default_wh = f"Main Store - {COMPANY}"
|
default_wh = f"Main Store - {get_abbr()}"
|
||||||
if not exists("Warehouse", default_wh):
|
if not exists("Warehouse", default_wh):
|
||||||
default_wh = frappe.db.get_value(
|
default_wh = frappe.db.get_value(
|
||||||
"Warehouse", {"company": COMPANY, "is_group": 0}, "name"
|
"Warehouse", {"company": COMPANY, "is_group": 0}, "name"
|
||||||
|
|
@ -492,22 +501,24 @@ def create_server_scripts():
|
||||||
# Auto-fires after a new Project is saved
|
# Auto-fires after a new Project is saved
|
||||||
# Creates "{Project Name} - OnSite WIP" warehouse automatically
|
# Creates "{Project Name} - OnSite WIP" warehouse automatically
|
||||||
|
|
||||||
project_name = doc.project_name or doc.name
|
project_name = doc.project_name or doc.name
|
||||||
company = doc.company or "Furnitex"
|
company = doc.company or "Furnitex"
|
||||||
warehouse_name = project_name + " - OnSite WIP"
|
abbr = frappe.db.get_value("Company", company, "abbr") or "F"
|
||||||
|
# OnSite WIP name uses company abbr so ERPNext accepts it
|
||||||
|
wh_short_name = project_name + " - OnSite WIP"
|
||||||
|
warehouse_name = wh_short_name + " - " + abbr
|
||||||
|
|
||||||
# Find root warehouse for this company
|
# Find root warehouse group for this company
|
||||||
root_wh = frappe.db.get_value(
|
root_wh = frappe.db.get_value(
|
||||||
"Warehouse",
|
"Warehouse",
|
||||||
{"company": company, "is_group": 1,
|
{"company": company, "is_group": 1},
|
||||||
"parent_warehouse": ["in", ["", None]]},
|
|
||||||
"name"
|
"name"
|
||||||
) or ("All Warehouses - " + company)
|
) or ("All Warehouses - " + abbr)
|
||||||
|
|
||||||
if not frappe.db.exists("Warehouse", warehouse_name):
|
if not frappe.db.exists("Warehouse", warehouse_name):
|
||||||
wh = frappe.get_doc({
|
wh = frappe.get_doc({
|
||||||
"doctype": "Warehouse",
|
"doctype": "Warehouse",
|
||||||
"warehouse_name": warehouse_name,
|
"warehouse_name": wh_short_name,
|
||||||
"parent_warehouse": root_wh,
|
"parent_warehouse": root_wh,
|
||||||
"company": company,
|
"company": company,
|
||||||
"is_group": 0,
|
"is_group": 0,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue