Skip to content

fix: hide redundant company currency fields on transactions#54691

Open
barredterra wants to merge 3 commits intofrappe:developfrom
barredterra:base-visibility
Open

fix: hide redundant company currency fields on transactions#54691
barredterra wants to merge 3 commits intofrappe:developfrom
barredterra:base-visibility

Conversation

@barredterra
Copy link
Copy Markdown
Collaborator

@barredterra barredterra commented May 1, 2026

Hide redundant company-currency fields on transactions when the document currency is already the company currency.

  • Hides base_ fields on parent and child tables when document currency equals company currency.
  • Restores those fields when the currencies differ, while preserving fields that were originally hidden.
  • Resets company-currency labels back to their plain labels in same-currency transactions instead of showing duplicate currency suffixes.

Multi-Currency (unchanged)

multi

Single-Currency (cleaned up)

single

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 1, 2026

📝 Walkthrough

Walkthrough

Updates transaction.js to add base-currency–aware visibility and label handling. set_dynamic_labels now calls toggle_base_currency_fields(company_currency) which shows/hides base_-prefixed form fields and child-grid base_ columns and caches original hidden state in _base_currency_field_visibility. set_currency_labels_from_options gains a company_currency parameter and, when document currency and mapping currency both equal company currency, uses reset_currency_labels instead of applying frm.set_currency_labels. change_form_labels conditionally resets totals_section labels when currencies match. toggle_item_grid_columns is refactored to remove currency-mismatch toggling for some base_ columns and make base_net_rate/base_net_amount visibility depend only on show. change_grid_labels now passes company_currency; toggle_item_grid_columns signature was removed.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: hiding redundant company currency fields on transactions when document currency matches company currency.
Description check ✅ Passed The description is directly related to the changeset, explaining the purpose and behavior changes with clear examples and visual documentation of the improvements.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot]

This comment was marked as resolved.

Changed reset_currency_labels from stripping every parenthesized fragment to only removing a parenthesized suffix.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (3)
erpnext/public/js/controllers/transaction.js (3)

2107-2123: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

base_net_* item columns are still force-shown from show alone.

toggle_item_grid_columns() now calls set_column_disp(fname, show) for base_net_rate and base_net_amount, which ignores _base_currency_field_visibility. In a foreign-currency document with discounts or inclusive taxes, that re-surfaces item columns that were intentionally hidden. Please gate these through should_show_base_currency_field(...) && show instead of showing them unconditionally from show.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@erpnext/public/js/controllers/transaction.js` around lines 2107 - 2123, In
toggle_item_grid_columns(), the base currency item columns (base_net_rate,
base_net_amount) are being shown solely based on show; update the second $.each
block so that when calling item_grid.set_column_disp for base_net_rate and
base_net_amount you combine the existing show flag with
should_show_base_currency_field(...) (e.g.
should_show_base_currency_field(item_grid.doctype, fname) && show) while keeping
the frappe.meta.get_docfield(...) guard and using the same item_grid and fname
symbols.

1969-1992: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

The foreign-currency path still re-shows cached-hidden base_* fields.

These hard-coded toggle_display / set_column_disp calls still bypass _base_currency_field_visibility and force overlapping base_* fields back on whenever currencies differ. That means customized hides like base_total, base_operating_cost, base_rate, or payment-schedule base_* columns can still leak back in multi-currency documents. Let the cached helper remain the single source of truth for overlapping base_* visibility here too.

Also applies to: 2047-2073

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@erpnext/public/js/controllers/transaction.js` around lines 1969 - 1992, The
hard-coded frm.toggle_display and set_column_disp calls are forcing base_*
fields visible and bypassing the canonical helper; replace these explicit
toggles with a call to the existing _base_currency_field_visibility helper so
cached/ customized visibility remains the single source of truth. Specifically,
remove the explicit frm.toggle_display([...]) / set_column_disp blocks (the one
shown and the similar block at the 2047-2073 range) and invoke
this._base_currency_field_visibility(this.frm) or
this._base_currency_field_visibility() as implemented in this file so base_*
field visibility is determined by that helper (preserving any cached hides)
rather than re-showing fields when this.frm.doc.currency != company_currency.

1861-1866: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Only remove a suffix that was actually generated by currency labeling.

reset_currency_labels() still strips any trailing parenthesized text. On the first same-currency render, a custom label like Amount (Tax Incl.) becomes Amount even if no currency suffix was ever appended. This should only remove the expected generated currency suffix, not arbitrary trailing parentheses.

Also applies to: 1873-1883

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@erpnext/public/js/controllers/transaction.js` around lines 1861 - 1866, The
current reset_currency_labels implementation unconditionally strips any trailing
parenthesized text (e.g., " (Tax Incl.)") which removes custom labels; change
reset_currency_labels so it only removes a suffix that exactly matches the
currency-label pattern previously appended (e.g., " (USD)" or the string
produced by add_currency_label for the current company currency). Implement this
by matching and removing only a well-defined regex or exact string built from
the currency code/symbol used when labeling (not any parentheses), update the
logic used in the block around the fields.filter(...) call and the analogous
block at the later lines (1873-1883) to use the same guarded removal, and keep
all other custom trailing parentheses intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@erpnext/public/js/controllers/transaction.js`:
- Around line 2107-2123: In toggle_item_grid_columns(), the base currency item
columns (base_net_rate, base_net_amount) are being shown solely based on show;
update the second $.each block so that when calling item_grid.set_column_disp
for base_net_rate and base_net_amount you combine the existing show flag with
should_show_base_currency_field(...) (e.g.
should_show_base_currency_field(item_grid.doctype, fname) && show) while keeping
the frappe.meta.get_docfield(...) guard and using the same item_grid and fname
symbols.
- Around line 1969-1992: The hard-coded frm.toggle_display and set_column_disp
calls are forcing base_* fields visible and bypassing the canonical helper;
replace these explicit toggles with a call to the existing
_base_currency_field_visibility helper so cached/ customized visibility remains
the single source of truth. Specifically, remove the explicit
frm.toggle_display([...]) / set_column_disp blocks (the one shown and the
similar block at the 2047-2073 range) and invoke
this._base_currency_field_visibility(this.frm) or
this._base_currency_field_visibility() as implemented in this file so base_*
field visibility is determined by that helper (preserving any cached hides)
rather than re-showing fields when this.frm.doc.currency != company_currency.
- Around line 1861-1866: The current reset_currency_labels implementation
unconditionally strips any trailing parenthesized text (e.g., " (Tax Incl.)")
which removes custom labels; change reset_currency_labels so it only removes a
suffix that exactly matches the currency-label pattern previously appended
(e.g., " (USD)" or the string produced by add_currency_label for the current
company currency). Implement this by matching and removing only a well-defined
regex or exact string built from the currency code/symbol used when labeling
(not any parentheses), update the logic used in the block around the
fields.filter(...) call and the analogous block at the later lines (1873-1883)
to use the same guarded removal, and keep all other custom trailing parentheses
intact.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 2315cf6d-8bbc-4431-a871-7850c5807157

📥 Commits

Reviewing files that changed from the base of the PR and between 873755d and fb974f5.

📒 Files selected for processing (1)
  • erpnext/public/js/controllers/transaction.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant