fix(integrations): handle fixed_charge fees in accounting and tax sync#4992
Merged
fix(integrations): handle fixed_charge fees in accounting and tax sync#4992
Conversation
## Context When an invoice contains a fixed_charge fee, syncing to accounting providers (NetSuite, Xero) fails with an "Invalid mapping" error because the item() dispatch logic only handles charge, add_on, credit, commitment, and subscription fee types. ## Description Add fixed_charge branch to all accounting payload item() methods, mapping fixed_charge fees to their underlying add-on's integration mapping via fee.fixed_charge_add_on. This covers both invoice and credit note payloads for NetSuite, Xero, and Anrok integrations.
## Context The tax payload dispatchers (Anrok and Avalara) for both invoices and credit notes did not handle fixed_charge fees, causing them to fall through to an empty struct with nil item_code. ## Description Add fixed_charge branch to all four tax payload files (Anrok/Avalara for invoices and credit notes), mapping fixed_charge fees to their underlying add-on via fixed_charge_item.
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes a critical bug where invoices and credit notes containing fixed_charge fees fail to sync to accounting providers (NetSuite, Xero) and tax providers (Anrok, Avalara) with "Invalid mapping" errors. The fix adds support for the fixed_charge fee type, which was added to the Fee model but not properly handled in integration payload dispatch logic.
Changes:
- Added
fixed_charge_itemmethod to base payload that maps fixed_charge fees to their underlying add-on's integration mapping - Updated all 8 fee type dispatch sites across accounting and tax provider payloads to handle the
fixed_charge?case - Added comprehensive test coverage for fixed_charge fees across all integration providers with billing entity and organization-level mapping fallback tests
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| app/services/integrations/aggregator/base_payload.rb | Adds fixed_charge_item method that looks up AddOn mapping using fee.fixed_charge_add_on.id |
| app/services/integrations/aggregator/invoices/payloads/base_payload.rb | Adds fixed_charge? branch to invoice fee dispatch logic |
| app/services/integrations/aggregator/invoices/payloads/netsuite.rb | Adds fixed_charge? branch to NetSuite invoice fee dispatch logic |
| app/services/integrations/aggregator/credit_notes/payloads/base_payload.rb | Adds fixed_charge? branch to credit note fee dispatch logic |
| app/services/integrations/aggregator/credit_notes/payloads/netsuite.rb | Adds fixed_charge? branch to NetSuite credit note fee dispatch logic |
| app/services/integrations/aggregator/taxes/invoices/payloads/anrok.rb | Adds fixed_charge? branch to Anrok tax invoice fee dispatch logic |
| app/services/integrations/aggregator/taxes/invoices/payloads/avalara.rb | Adds fixed_charge? branch to Avalara tax invoice fee dispatch logic |
| app/services/integrations/aggregator/taxes/credit_notes/payloads/anrok.rb | Adds fixed_charge? branch to Anrok tax credit note fee dispatch logic |
| app/services/integrations/aggregator/taxes/credit_notes/payloads/avalara.rb | Adds fixed_charge? branch to Avalara tax credit note fee dispatch logic |
| spec/support/shared_examples/an_integration_payload.rb | Adds fixed_charge_add_on, fixed_charge, fixed_charge_fee fixtures and mappings to shared examples for comprehensive test coverage |
| spec/services/integrations/aggregator/invoices/payloads/netsuite_spec.rb | Adds dedicated test case for fixed_charge fee in NetSuite invoice payloads |
| spec/services/integrations/aggregator/invoices/payloads/xero_spec.rb | Updates expected payload with fixed_charge fee entry and adjusted coupon tax calculation |
| spec/services/integrations/aggregator/invoices/payloads/anrok_spec.rb | Updates expected payload with fixed_charge fee entry and adjusted coupon tax calculation |
| spec/services/integrations/aggregator/credit_notes/payloads/netsuite_spec.rb | Adds dedicated test case for fixed_charge fee in NetSuite credit note payloads |
| spec/services/integrations/aggregator/credit_notes/payloads/xero_spec.rb | Updates expected payload with fixed_charge fee entry |
| spec/services/integrations/aggregator/credit_notes/payloads/anrok_spec.rb | Updates expected payload with fixed_charge fee entry |
| spec/services/integrations/aggregator/taxes/invoices/payloads/avalara_spec.rb | Updates expected payload with fixed_charge fee entry |
| spec/services/integrations/aggregator/taxes/invoices/payloads/anrok_spec.rb | Updates expected payload with fixed_charge fee entry |
| spec/services/integrations/aggregator/taxes/credit_notes/payloads/avalara_spec.rb | Updates expected payload with fixed_charge fee entry |
| spec/services/integrations/aggregator/taxes/credit_notes/payloads/anrok_spec.rb | Updates expected payload with fixed_charge fee entry |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
When an invoice or credit note contains a fixed_charge fee, syncing to accounting providers (NetSuite, Xero) fails with an "Invalid mapping" error because the item dispatch logic in the payload classes only handles
charge,add_on,credit,commitment, andsubscriptionfee types. Thefixed_chargefee type was added to theFeemodel but the integration payload logic was never updated to handle it. Tax provider payloads (Anrok, Avalara) also silently produce nil item codes for fixed_charge fees.Description
Add a
fixed_charge_itemmethod to the base payload that maps fixed_charge fees to their underlying add-on's integration mapping viafee.fixed_charge_add_on. Add afixed_charge?branch to all nine fee type dispatch sites across accounting payloads (invoices and credit notes for NetSuite, Xero, Anrok) and tax payloads (invoices and credit notes for Anrok, Avalara). Since every fixed charge belongs to an add-on, the mapping reuses the existing AddOn lookup mechanism.