From c6f7423c4bf6b663dedd2a0b109eb2e982067c2a Mon Sep 17 00:00:00 2001 From: Jordi Ballester Alomar Date: Tue, 27 Oct 2026 10:03:56 +0100 Subject: [PATCH] [FIX] stock_account: don't create missing accounts from the chart template update_from_coa_generic() only means to fill the new stock fields on existing records, but when a template record has those fields and the company doesn't have it (e.g. the account was deleted), ref() returns an empty recordset, the record passes the filter and _load_data() tries to create it with only the stock fields: null value in column "name" of relation "account_account" violates not-null constraint Skip template records that don't exist in the company. --- .../scripts/stock_account/19.0.1.1/end-migration.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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..274a8dc446c2 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 @@ -49,10 +49,15 @@ def ref_or_id(ref_or_id, model_name, AccountChartTemplate=AccountChartTemplate): for record_id, record_data in template_data[model_name].items(): if not any(record_data.get(key) for key in field_names): continue + record = ref_or_id(record_id, model_name) + if not record: + # only complete existing records, _load_data would create + # the missing ones with just the fields in spec + 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