Skip to content

Feature/29 business central import - #88

Merged
anis022 merged 14 commits into
developfrom
feature/29-business-central-import
Nov 21, 2026
Merged

anis022 merged 14 commits into
developfrom
feature/29-business-central-import

Conversation

@maayjayy

@maayjayy maayjayy commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #29

Overview

  • Goal: import the food catalog from a Business Central Excel export, instead of entering it by hand
  • New endpoint: POST api/catalog-items/import (Admin, ManagePriceGrid permission)
  • 4 pieces:
    • BusinessCentralExportReader: reads the Excel file with ClosedXML, columns found by name
    • CatalogImporter: creates or updates by BC code, so no duplicates
    • CatalogImportController: checks the file (missing, not .xlsx, > 10 MB, missing sheet or column) and returns a report
    • CatalogSaveErrors: recognizes database conflicts, shared with CatalogItemsController ([Issue]: Food catalog (name, category, Business Central code) #27)
  • Report: created / updated / unchanged + refused rows (row number, code, reason), the other rows imported
  • Choices:
    • the import reads the BC item list (sheet Articles, type Inventaire, columns N°, Description, Unité de mesure de base);
    • no category / quality class in the export, so new items get To classify and an empty class until someone picks it (no default, so a forgotten class never gives a wrong receipt value)
    • re-import only updates the name; the unit, category and class are never changed (a row with a different unit is reported)
    • a code saved by another request at the same time returns 409, nothing is saved, and importing again works
    • cells with an Excel error (#REF!, #N/A...) are reported as row errors
    • Coût unitaire is not imported (internal value, not the fair market value)
  • Docs: "Import from Business Central" section in docs/database/catalog.md, migration MakeCatalogItemQualityClassOptional with SQL script 0007, updated .dbml files and diagrams (some images were outdated since [Issue]: Food catalog (name, category, Business Central code) #27)

Testing

Automated tests (Docker must be running): all 455 pass with dotnet test.

  • CatalogImporterTests: create, update the name, no duplicates on re-import, same code on several rows, unit never changed, empty class, category/class kept, invalid rows reported without blocking, conflict on save
  • BusinessCentralExportReaderTests: reading, numeric codes as text, columns in any order, empty rows, non-Inventaire rows reported, Excel errors reported, formulas not calculated, missing sheet/column, non-Excel file
  • CatalogImportEndpointTests: 401 / 403 by role, 200 with the report, re-import, errors sorted by row, 400 for bad files, 409 on conflict
  • CatalogItemQualityClassOptionalMigrationTests: items without class, existing classes kept, rollback refused while an item has no class
  • CatalogSaveErrorsTests: database errors recognized correctly
  • CatalogItemValidatorTests and CatalogEndpointTests ([Issue]: Food catalog (name, category, Business Central code) #27): a class is still required when creating or editing by hand
  • Test Excel files are built in memory with ClosedXML, with invented data, so no real file is in the repo.

Manual test with the real export:

  • BC item list (Listes des Articles - BC, 747 items, kept outside the repo)
  • imported twice into a local database through the reader + importer
  • run with a small local script (reader + importer). I can share it if useful

Here's the output (with only a snippet of the item list itself):

Catalog before the import: 0 of the 747 foods in the files already exist.

=== Import #1 ===

Listes des Articles- BC.xlsx
  747 rows read (747 different foods)
  ✔ 747 created   ↻ 0 updated   = 0 already up to date
  ✔ No errors

=== Import #2: same files again ===

Listes des Articles- BC.xlsx
  747 rows read (747 different foods)
  ✔ 0 created   ↻ 0 updated   = 747 already up to date
  ✔ No errors

✔ Nothing created: re-importing does not create duplicates.

=== Catalog after the import ===
Code     | Name                                               | Category    | Unit | Class
1000xxx  | Yogourt moins de 500g                              | To classify | KG   | 
1000xxx  | Fromage                                            | To classify | KG   | 

✔ No Business Central code appears twice in the catalog. 

What wasn't tested:

Screenshots / Screencasts

No UI change.

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

  • Decisions taken: the BC item list replaces the PO format, imported items have an empty quality class, the endpoint keeps the ManagePriceGrid permission.
  • Limitations:
    • 10 MB upload limit (≈ 75,000 rows; the real item list is about 60 KB)

@maayjayy maayjayy added this to the Sprint - 2 milestone Nov 19, 2026
@maayjayy maayjayy self-assigned this Nov 19, 2026
@maayjayy
maayjayy removed the request for review from jspngl November 19, 2026 04:50

@anis022 anis022 left a comment

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.

Nice work, left 4 comments to fix before merging.

@anis022
anis022 removed the request for review from lauriechammah November 19, 2026 18:10
@maayjayy
maayjayy requested a review from anis022 November 20, 2026 03:58

@anis022 anis022 left a comment

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.

looks good, thanks

@anis022
anis022 merged commit 2b10136 into develop Nov 21, 2026
1 check passed
@anis022
anis022 deleted the feature/29-business-central-import branch November 21, 2026 22:02
Lightsul added a commit that referenced this pull request Nov 23, 2026
Renumber the receipt status SQL script to 0008, since 0007 is now the catalog quality class migration from #88.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Lightsul Lightsul mentioned this pull request Nov 23, 2026
4 of 6 tasks
Lightsul added a commit that referenced this pull request Nov 23, 2026
Renumber the receipt status SQL script to 0008, since 0007 is now the catalog quality class migration from #88.
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