Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Record manual stock changes in InventoryJournal

Đang mở
#880 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
csharp, mongodb
Lĩnh vực
backend, databases

Hướng nghiên cứu

Start with InventoryManageService and IInventoryManageService, then trace the listed stock-update paths in ProductViewModelService, BaseProductController, and the API command handlers. Review InventoryJournal and InventoryManageServiceTests before estimating how the shared adjustment flow fits. Done means all listed adjustment paths, notification behavior, no-op handling, and the specified tests meet the acceptance criteria.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

enhancement

Problem

Manual stock changes leave no trace. InventoryJournal (src/Core/Grand.Domain/Catalog/InventoryJournal.cs) is written only for shipments: InventoryManageService.InsertInventoryJournal (src/Business/Grand.Business.Catalog/Services/Products/InventoryManageService.cs) is called with ObjectType = nameof(Shipment). When an administrator or an API client edits a quantity, the old value is simply overwritten, so there is no answer to "who changed this, when, from what to what, and why".

Code paths that change StockQuantity / ProductWarehouseInventory / combination stock without a journal entry:

  • Product edit - ProductViewModelService (src/Web/Grand.Web.AdminShared/Services/ProductViewModelService.cs): StockQuantity is mapped from the model on update, and SaveProductWarehouseInventory (~L439) writes per-warehouse StockQuantity and then sums to product.StockQuantity. Same flow for create (~L771) and update (~L830).
  • Bulk edit (grid) - same file, ~L1362-1367: product.StockQuantity = pModel.StockQuantity.
  • Attribute combinations - same file, ~L2200-2260: combination.StockQuantity, PrepareCombinationWarehouseInventory (per-warehouse ProductCombinationWarehouseInventory), and the recalculated product.StockQuantity. Also the "generate all combinations" path (BaseProductController, ~L2949 resets StockQuantity = 0).
  • Out-of-stock subscription notifications live in this view-model layer (OutOfStockNotifications, ~L189 and ~L223), so they only fire for panel edits.
  • Store owner and Vendor panels reuse the same AdminShared services/controllers, so they have the same gap.
  • Backend API (src/Modules/Grand.Module.Api):
    • PUT /Product and PATCH /Product/{key} -> UpdateProductCommandHandler maps StockQuantity from the DTO and calls UpdateProduct; it has its own, partial copy of the back-in-stock logic.
    • POST /Product/{key}/UpdateStock -> UpdateProductStockCommandHandler sets product.StockQuantity or the ProductWarehouseInventory row; it duplicates OutOfStockNotifications a third time.
    • ProductAttributeCombinationDto.StockQuantity is part of the DTO, so combination stock can change through product update as well.

Product import (ProductImportDataObject) also sets StockQuantity; it is a bulk path and is probably better handled as a follow-up.

The panels do not display InventoryJournal anywhere (no reference in Grand.Web.*); the collection is currently write-only from shipments and read nowhere.

Proposal

Add a core method to IInventoryManageService, for example:

Task AdjustStock(Product product, ProductAttributeCombination combination, string warehouseId,
    int newQuantity, string reason, string reference);

(or a delta-based overload). It should:

  • apply the new quantity to the product / warehouse row / combination (and its warehouse row), recompute the aggregates, and call UpdateStockProduct so LowStock / auto-unpublish keep working as today;
  • insert an InventoryJournal entry with a new ObjectType for manual adjustments (e.g. "StockAdjustment"), InQty / OutQty derived from the delta, ProductId, Attributes (combination), WarehouseId, Comments = reason, Reference = who/what (user e-mail, "api");
  • do nothing (no journal entry) when the quantity did not change;
  • own the out-of-stock subscription notifications: move OutOfStockNotifications from ProductViewModelService into core so the panel and every API path share one implementation, and delete the copies in the API handlers.

Route every path listed above through it: product edit and warehouse inventory, bulk edit, combination create/edit, API PUT/PATCH/UpdateStock.

Out of scope / follow-ups

  • A journal view per product in the admin panel (read side of InventoryJournal).
  • An optional "reason" field in the panel UI (until then Comments can be a default text such as "Manual adjustment").
  • Journal entries for product import.

Acceptance criteria

  • IInventoryManageService exposes a stock adjustment method covering product, warehouse and combination (+ combination warehouse) quantities.
  • Each adjustment writes one InventoryJournal entry with a dedicated ObjectType, correct InQty/OutQty, Comments and Reference.
  • Unchanged quantities produce no entry.
  • Admin, Store and Vendor product edit, bulk edit and combination edit go through the new method.
  • API PUT, PATCH and UpdateStock go through the new method; Reference identifies the API caller.
  • LowStock flag, auto-unpublish / out-of-stock behaviour and back-in-stock notifications behave as before, from a single implementation in core.
  • Unit tests in InventoryManageServiceTests cover product, warehouse and combination adjustments, no-op, and notification triggering.

Notes

  • Add an index on InventoryJournal (ProductId, CreateDateUtc) - needed as soon as a per-product view reads it.
  • No migration needed for existing data; history starts from the release that ships this.
Ngôn ngữ chính
C#
Star
1.3k
Fork
549
Merge trung bình
8 giờ 14 phút
Pull request đã merge (30 ngày)
53

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của grandnode/grandnode2

Tất cả issue của grandnode/grandnode2

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.