jey_erp/jey_erp/custom/salary_component_export.py

34 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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()
def export_salary_components():
components = frappe.get_all("Salary Component", fields=["name"])
result = []
for c in components:
doc = frappe.get_doc("Salary Component", c.name)
data = doc.as_dict()
for field in SKIP_FIELDS:
data.pop(field, 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)
return result