Skip to content

feat(donations): import donations from a Business Central export - #100

Merged
anis022 merged 4 commits into
developfrom
feature/77-bc-import
Dec 4, 2026
Merged

anis022 merged 4 commits into
developfrom
feature/77-bc-import

Conversation

@Lightsul

@Lightsul Lightsul commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #77

Overview

Imports donations from a Business Central purchase order export.

  • Reads the Lignes sheet. Every invalid row is reported with its row number, an error code and a message, and the valid rows are still imported.
  • Values each line through its confirmed item mapping and the price in effect on the donation date . The price, the percentage and the value are frozen on the donation.
  • Saves the import, its donations and its errors in one transaction.
  • Prevents duplicates with a SHA-256 checksum of the file and a unique source key per line.
  • Adds endpoints for the import, the report, the rejected rows, the imported lines and the history.
  • Adds the AddDonationImports migration, its SQL script, the format documentation and an anonymized sample file.

Testing

  • 797/797 tests pass, including new unit tests for the reader and integration tests for the endpoints and the migration.

Checklist

  • Code is neat, readable, and works
  • Code is commented where appropriate and well-documented
  • Commit messages follow our guidelines
  • Issue number is linked
  • Branch is linked
  • Reviewers are assigned (one of your tech leads)

Notes

  • Run dotnet ef database update --project src/MoissonMontreal.Api locally.
  • To confirm with Nafissa: that this is the right export, the Bon/Moyen/Mauvais → A/B/C mapping, and the choice to reject unknown donors.
  • Only the anonymized sample is versioned. Real exports stay out of the repo (Loi 25).

@Lightsul Lightsul added this to the Sprint 3 milestone Dec 3, 2026
@Lightsul Lightsul self-assigned this Dec 3, 2026
continue;
}

occurrences[code] = occurrences.GetValueOrDefault(code) + 1;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The real export has no N° ligne column, so the key of a line is {code}#{n}. But n only counts the lines that passed the checks. If a Poivron line is rejected (for example, missing quality) and then fixed in BC, every Poivron line after it moves by one on the next import. The fixed line is then skipped as "already imported" and another line is imported a second time. I'll fix it by counting the position on every row with that code, before the checks.

return Error(line, DonationImportErrorCode.InactiveCatalogItem, $"The Business Central item {line.ItemCode} is matched to {catalogItem.Name}, which is no longer in the price grid. Review its mapping.");
}

if (!string.Equals(line.Unit.Trim(), catalogItem.Unit.Trim(), StringComparison.OrdinalIgnoreCase))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Prices are per kg (#28), but the export lines are in CA. This check compares the line unit with the catalog item unit, not with the unit of the price. So 48 CA times a price per kg passes, and the value on the receipt is wrong. I'll fix it by rejecting lines that are not in kg until we know how to convert a case.

@anis022
anis022 removed the request for review from lauriechammah December 4, 2026 06:27
The position in the fallback key only counted rows that passed the checks. Fixing a rejected row shifted the key of every later row of the same item, so one line was skipped as already imported and another was imported twice.
Prices are per kg (#28), but the unit check only compared the line with the catalog item, so a line in CA was valued with a price per kg. Such lines are now rejected with UnitMismatch until we know how to turn a case into kg.
@anis022
anis022 merged commit 56a2c99 into develop Dec 4, 2026
1 check passed
@anis022
anis022 deleted the feature/77-bc-import branch December 4, 2026 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants