Skip to content

fix(integrations): handle fixed_charge fees in accounting and tax sync#4992

Merged
ancorcruz merged 2 commits intomainfrom
fix/fixed-charge-accounting-sync
Feb 6, 2026
Merged

fix(integrations): handle fixed_charge fees in accounting and tax sync#4992
ancorcruz merged 2 commits intomainfrom
fix/fixed-charge-accounting-sync

Conversation

@ancorcruz
Copy link
Contributor

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, and subscription fee types. The fixed_charge fee type was added to the Fee model 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_item method to the base payload that maps fixed_charge fees to their underlying add-on's integration mapping via fee.fixed_charge_add_on. Add a fixed_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.

## 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.
@ancorcruz ancorcruz self-assigned this Feb 6, 2026
@ancorcruz ancorcruz marked this pull request as ready for review February 6, 2026 10:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_item method 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.

Copy link
Contributor

@annvelents annvelents left a comment

Choose a reason for hiding this comment

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

Super!

@ancorcruz ancorcruz merged commit 461598e into main Feb 6, 2026
16 checks passed
@ancorcruz ancorcruz deleted the fix/fixed-charge-accounting-sync branch February 6, 2026 11:08
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.

2 participants