fix(sales-invoice): inject Tax Articles column into saved grid layouts
Per-user grid layouts (GridView in __UserSettings) saved before this feature list the legacy tax_article column but not custom_tax_articles_display. Frappe renders the saved list verbatim and ignores the new in_list_view field, so the 'Tax Articles' cell never appears for those users until added via the grid gear -- which is why it showed on a fresh user (Administrator) but not on machines where the user had a saved layout. Patch replaces the legacy tax_article entry with custom_tax_articles_display in every saved Sales Invoice Item layout that lacks it. Idempotent; runs on migrate so every machine converges automatically. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
647f940328
commit
9c4e075527
|
|
@ -14,3 +14,4 @@ jey_erp.patches.remove_won_lost_checkboxes
|
|||
jey_erp.patches.drop_bank_integration_account_mapping
|
||||
jey_erp.patches.backfill_si_tax_article_row_keys
|
||||
jey_erp.patches.backfill_sales_invoice_tax_articles_history
|
||||
jey_erp.patches.add_tax_articles_to_si_grid_views
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
import json
|
||||
|
||||
import frappe
|
||||
|
||||
|
||||
def execute():
|
||||
"""Inject the new "Tax Articles" column into saved Sales Invoice Item grid layouts.
|
||||
|
||||
Per-user grid column layouts live in `__UserSettings` (GridView). A layout saved
|
||||
before the multi tax-article feature lists the legacy `tax_article` column but not
|
||||
the new `custom_tax_articles_display`. Frappe renders that saved list verbatim and
|
||||
ignores the new in_list_view field, so the "Tax Articles" cell never appears for
|
||||
those users until they add it manually via the grid gear.
|
||||
|
||||
Replace the legacy `tax_article` entry (or, lacking it, insert after
|
||||
`item_tax_template`) with `custom_tax_articles_display` in every saved layout that
|
||||
doesn't already have it. Idempotent.
|
||||
"""
|
||||
rows = frappe.db.sql(
|
||||
"select user, data from `__UserSettings` where doctype = 'Sales Invoice'",
|
||||
as_dict=True,
|
||||
)
|
||||
for r in rows:
|
||||
try:
|
||||
data = json.loads(r.data or "{}")
|
||||
except (ValueError, TypeError):
|
||||
continue
|
||||
|
||||
grid_view = data.get("GridView") or {}
|
||||
cols = grid_view.get("Sales Invoice Item")
|
||||
if not cols:
|
||||
continue
|
||||
|
||||
names = [c.get("fieldname") for c in cols]
|
||||
if "custom_tax_articles_display" in names:
|
||||
continue
|
||||
|
||||
new_col = {"fieldname": "custom_tax_articles_display", "columns": 2}
|
||||
if "tax_article" in names:
|
||||
cols[names.index("tax_article")] = new_col
|
||||
elif "item_tax_template" in names:
|
||||
cols.insert(names.index("item_tax_template") + 1, new_col)
|
||||
else:
|
||||
cols.append(new_col)
|
||||
|
||||
grid_view["Sales Invoice Item"] = cols
|
||||
data["GridView"] = grid_view
|
||||
frappe.db.sql(
|
||||
"update `__UserSettings` set data = %s where user = %s and doctype = 'Sales Invoice'",
|
||||
(json.dumps(data), r.user),
|
||||
)
|
||||
|
||||
frappe.db.commit()
|
||||
frappe.cache().delete_value("_user_settings")
|
||||
Loading…
Reference in New Issue