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:
parent
0699beb3ba
commit
fae51ca7ef
|
|
@ -1,6 +1,8 @@
|
||||||
import frappe
|
import frappe
|
||||||
|
|
||||||
SKIP_FIELDS = {"name", "creation", "modified", "modified_by", "owner", "docstatus", "idx"}
|
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()
|
@frappe.whitelist()
|
||||||
|
|
@ -15,8 +17,16 @@ def export_salary_components():
|
||||||
for field in SKIP_FIELDS:
|
for field in SKIP_FIELDS:
|
||||||
data.pop(field, None)
|
data.pop(field, None)
|
||||||
|
|
||||||
# accounts — company-specific, не экспортируем
|
# В accounts сохраняем account_name вместо полного имени (без суффикса компании)
|
||||||
data.pop("accounts", None)
|
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)
|
result.append(data)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,18 @@ def create_default_salary_components(args):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
data["doctype"] = "Salary Component"
|
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)
|
frappe.get_doc(data).insert(ignore_permissions=True)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue