feat(e-taxes-settings): auto-fill Default Item Group & UOM on install
The required Link fields default_item_group / default_uom had no field-level default and nothing ever populated them, so every fresh base started with them empty (had to be filled by hand). Add setup_defaults.ensure_settings_defaults() that sets default_item_group="All Item Groups" and default_uom="Nos" — but only when the field is blank AND the target record exists. Idempotent; wired into after_install and after_migrate so it never overwrites an admin's choice. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
f5b7e56577
commit
610b98ca69
|
|
@ -73,18 +73,22 @@ def after_install():
|
|||
"""Run installation tasks"""
|
||||
from invoice_az.auth import setup_token_renewal
|
||||
from invoice_az.master_data.sync import sync_all
|
||||
from invoice_az.setup_defaults import ensure_settings_defaults
|
||||
|
||||
setup_token_renewal()
|
||||
sync_all()
|
||||
ensure_settings_defaults()
|
||||
|
||||
|
||||
def after_migrate():
|
||||
"""Run migration tasks"""
|
||||
from invoice_az.auth import setup_token_renewal
|
||||
from invoice_az.master_data.sync import sync_all
|
||||
from invoice_az.setup_defaults import ensure_settings_defaults
|
||||
|
||||
setup_token_renewal()
|
||||
sync_all()
|
||||
ensure_settings_defaults()
|
||||
|
||||
|
||||
fixtures = []
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
import frappe
|
||||
|
||||
# Sensible out-of-the-box defaults for E-Taxes Settings on a fresh base.
|
||||
# These are required Link fields with no field-level default, so without this
|
||||
# they start empty on every new install and have to be filled by hand.
|
||||
SETTINGS_DEFAULTS = {
|
||||
"default_item_group": ("Item Group", "All Item Groups"),
|
||||
"default_uom": ("UOM", "Nos"),
|
||||
}
|
||||
|
||||
|
||||
def ensure_settings_defaults():
|
||||
"""Populate E-Taxes Settings defaults if they are empty.
|
||||
|
||||
Idempotent: only writes a field when it is currently blank AND the target
|
||||
record exists. Safe to run on every after_install / after_migrate — it
|
||||
never overwrites a value an admin has already chosen.
|
||||
"""
|
||||
settings = frappe.get_single("E-Taxes Settings")
|
||||
|
||||
changed = False
|
||||
for fieldname, (doctype, value) in SETTINGS_DEFAULTS.items():
|
||||
if settings.get(fieldname):
|
||||
continue
|
||||
if not frappe.db.exists(doctype, value):
|
||||
continue
|
||||
settings.set(fieldname, value)
|
||||
changed = True
|
||||
|
||||
if changed:
|
||||
settings.flags.ignore_permissions = True
|
||||
settings.save(ignore_permissions=True)
|
||||
frappe.db.commit()
|
||||
Loading…
Reference in New Issue