Pre-seed Gender / Employment Type before bulk ƏMAS import

Diagnosed cause of "wizard says employees will load, I see 0":
the bulk import worker dies on the first emp.insert() with
LinkValidationError("Could not find Gender: Male"). Frappe ships
Gender records (Male/Female/Other/...) and HRMS ships Employment
Type rows (Full-time/Part-time/Contract/...) via fixtures, but on
a freshly-finalized site those fixtures may not have landed by the
time _materialize_amas_employees fires. Every employee then fails
identically and the import job finishes with 0 created.

Fix: _seed_amas_employee_dependencies() runs right before
import_bulk_employees and idempotently inserts the standard rows
for both doctypes if missing. Per-row insert failures are logged
to "Jey Wizard seed amas deps" and don't block the rest of the
seed loop. Idempotent — safe on reruns.

Sample output of the existing "Jey Wizard trace: amas outcome"
will now show employees_in_db_for_company > 0 instead of always 0.
This commit is contained in:
Ali 2026-05-04 10:35:33 +00:00
parent 1f32d0b07d
commit 6ba1bdf53d
3 changed files with 43 additions and 2 deletions

View File

@ -1 +1 @@
__version__ = "0.1.24" __version__ = "0.1.25"

View File

@ -1017,6 +1017,14 @@ def _materialize_amas_employees(company_name):
) )
return return
# Pre-seed standard Gender / Employment Type rows that the AMAS-imported
# Employees Link to. Frappe normally ships these via fixtures, but a
# fresh wizard install may finalize before HRMS' install fixtures land,
# in which case the bulk import worker errors out on the very first
# `emp.insert()` with LinkValidationError("Could not find Gender: Male")
# and never creates anything.
_seed_amas_employee_dependencies()
try: try:
from invoice_az import amas_api as _amas_api from invoice_az import amas_api as _amas_api
from invoice_az.amas_api import import_bulk_employees from invoice_az.amas_api import import_bulk_employees
@ -1290,6 +1298,39 @@ def _purge_inactive_etaxes_records(company):
) )
def _seed_amas_employee_dependencies():
"""Pre-create global Link targets the AMAS-imported Employee rows expect.
Anything Frappe / HRMS would normally ship via fixtures but might not
have loaded yet on a freshly-finalized site. Idempotent.
"""
# Standard Gender values used by AMAS payloads + Frappe's own fixtures.
for g in ("Male", "Female", "Other", "Prefer not to say", "Non-Conforming", "Transgender"):
if not frappe.db.exists("Gender", g):
try:
frappe.get_doc({"doctype": "Gender", "gender": g}).insert(ignore_permissions=True)
except Exception as exc:
frappe.log_error(
f"seed Gender '{g}' failed: {exc}",
"Jey Wizard seed amas deps",
)
# Employment Type — Employee.employment_type is a Link; AMAS feeds in
# common ones. HRMS normally creates these as fixtures.
for et in ("Full-time", "Part-time", "Probation", "Contract", "Commission", "Piecework", "Intern", "Apprentice"):
if not frappe.db.exists("Employment Type", et):
try:
frappe.get_doc({"doctype": "Employment Type", "employee_type_name": et}).insert(
ignore_permissions=True
)
except Exception as exc:
frappe.log_error(
f"seed Employment Type '{et}' failed: {exc}",
"Jey Wizard seed amas deps",
)
frappe.db.commit()
def _log_amas_dispatch( def _log_amas_dispatch(
company_name, company_name,
asan_login, asan_login,

View File

@ -10,7 +10,7 @@ frappe.provide("jey_wizard");
// Bump this string in every commit that changes wizard code. Displayed in the badge so // Bump this string in every commit that changes wizard code. Displayed in the badge so
// we can tell at a glance which version is actually running on a given machine. Kept in // we can tell at a glance which version is actually running on a given machine. Kept in
// sync with __version__ in jey_wizard/__init__.py. // sync with __version__ in jey_wizard/__init__.py.
const JEY_WIZARD_VERSION = "0.1.24"; const JEY_WIZARD_VERSION = "0.1.25";
// Wipe Frappe + ERPNext default slides so their `before_load`/`after_load` listeners // Wipe Frappe + ERPNext default slides so their `before_load`/`after_load` listeners
// don't try to mutate a wizard that isn't slide-based anymore. // don't try to mutate a wizard that isn't slide-based anymore.