export SC accounts as account_name, resolve to full account on import

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Ali 2026-03-26 16:31:24 +04:00
parent 0699beb3ba
commit fae51ca7ef
2 changed files with 24 additions and 3 deletions

View File

@ -1,6 +1,8 @@
import frappe
SKIP_FIELDS = {"name", "creation", "modified", "modified_by", "owner", "docstatus", "idx"}
CHILD_SKIP_FIELDS = {"name", "creation", "modified", "modified_by", "owner",
"docstatus", "idx", "parent", "parenttype", "parentfield", "company"}
@frappe.whitelist()
@ -15,8 +17,16 @@ def export_salary_components():
for field in SKIP_FIELDS:
data.pop(field, None)
# accounts — company-specific, не экспортируем
data.pop("accounts", None)
# В accounts сохраняем account_name вместо полного имени (без суффикса компании)
accounts = []
for row in data.get("accounts") or []:
if row.get("account"):
account_name = frappe.db.get_value("Account", row["account"], "account_name")
row["account"] = account_name
for field in CHILD_SKIP_FIELDS:
row.pop(field, None)
accounts.append(row)
data["accounts"] = accounts
result.append(data)

View File

@ -36,7 +36,18 @@ def create_default_salary_components(args):
continue
data["doctype"] = "Salary Component"
data["accounts"] = []
# Резолвим account_name → полное имя счёта в целевой компании
accounts = []
for row in data.get("accounts") or []:
account_name = row.get("account")
if account_name and company:
full_account = frappe.db.get_value(
"Account", {"account_name": account_name, "company": company}, "name"
)
if full_account:
accounts.append({"company": company, "account": full_account})
data["accounts"] = accounts
frappe.get_doc(data).insert(ignore_permissions=True)