Admin business: optional fields such as withholdingTaxCompanyId can't be cleared

Open
#5,254 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
52/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
postgresql, typescript
Domain
backend, database

Research direction

Start with packages/server/src/modules/financial-entities/providers/admin-businesses.provider.ts and compare its update query with the tax-representation handling added in #5230. Read packages/server/src/modules/financial-entities/helpers/admin-businesses.helper.ts and the existing update integration test; first decide whether cleared array fields should be NULL or empty arrays. Done means each nullable field supports keep, clear and set, required fields retain their constraint with an explanatory comment, and the integration test covers those cases.

Written by the indexing model from the issue text.

Description

Several optional admin-business fields can be set but never cleared. The update query in packages/server/src/modules/financial-entities/providers/admin-businesses.provider.ts writes them as COALESCE($param, column). A null therefore means "keep", and there is no value that empties the column. Affected:

  • company_tax_id (withholdingTaxCompanyId)
  • business_registration_start_date
  • advance_tax_rates
  • tax_advances_ids
  • social_security_employer_ids
  • withholding_tax_annual_ids

Once one of these holds a value, a user who empties it in the admin business settings gets the old value back.

The three tax-representation fields added in #5230 already work differently:

  • tax_assessing_office, tax_representative_name, tax_representative_license
  • An omitted field keeps its value; '' or null clears it.
  • Implementation: a CASE WHEN $x::TEXT IS NULL THEN column ELSE NULLIF($x, '') END in the SQL, plus toClearableText in packages/server/src/modules/financial-entities/helpers/admin-businesses.helper.ts.
  • Covered by providers/__tests__/admin-businesses-update.integration.test.ts.

Done when

  • Each nullable field above can be cleared from the UI, and an omitted field still keeps its value.
  • The array fields need a decision: is "cleared" NULL or an empty array?
  • Fields that must never be empty (for example company_tax_id, if required) stay as they are, with a comment saying why.
  • The integration test covers keep, clear and set for the changed fields.
Dominant language
TypeScript
Stars
30
Forks
10
Avg merge
2d 12h
Merged PRs (30d)
276

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Urigo/accounter-fullstack

All issues in Urigo/accounter-fullstack

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.