From 8eab5e4f2f6301098f3591a9748be3f89b5d717c Mon Sep 17 00:00:00 2001 From: Quoc - Pham Ngoc Date: Wed, 5 Aug 2026 18:40:33 +0700 Subject: [PATCH] [FIX] stock_account: skip accounts that don't exist yet in company_data update_from_coa_generic() included a record_id in filtered_records whenever the target field appeared unset. But when ref_or_id() can't resolve the xmlid to an existing account.account record, indexing the field on the resulting empty recordset is also falsy, so a not-yet-existing account was treated the same as an existing account with the field unset. AccountChartTemplate._load_data() then created a new account.account row from only the partial company_data (the 2 stock-account fields), missing required fields like name/account_type, causing: null value in column "name" of relation "account_account" violates not-null constraint Skip record_ids that don't resolve to an existing record instead of partially-creating them. --- .../scripts/stock_account/19.0.1.1/end-migration.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/openupgrade_scripts/scripts/stock_account/19.0.1.1/end-migration.py b/openupgrade_scripts/scripts/stock_account/19.0.1.1/end-migration.py index 52f1ce0de916..639ea2420fdf 100644 --- a/openupgrade_scripts/scripts/stock_account/19.0.1.1/end-migration.py +++ b/openupgrade_scripts/scripts/stock_account/19.0.1.1/end-migration.py @@ -47,12 +47,15 @@ def ref_or_id(ref_or_id, model_name, AccountChartTemplate=AccountChartTemplate): for model_name, field_names in spec.items(): filtered_records = {} for record_id, record_data in template_data[model_name].items(): - if not any(record_data.get(key) for key in field_names): + record = ref_or_id(record_id, model_name) + if not record or not any(record_data.get(key) for key in field_names): + # record doesn't exist yet in this company's chart; + # don't partially-create it here, only backfill existing ones continue filtered = { key: value for key, value in record_data.items() - if key in field_names and not ref_or_id(record_id, model_name)[key] + if key in field_names and not record[key] } if filtered: filtered_records[record_id] = filtered