changes according to the test

This commit is contained in:
2026-08-28 13:19:13 +05:30
parent c31f3aca27
commit 6c1ad472f2
3 changed files with 107 additions and 0 deletions

View File

@@ -1522,6 +1522,23 @@ func (r *orderRepository) createOrderTx(tx *gorm.DB, data models.Orders) (models
})
}
// An order has to name the outlet it is placed at, and one that did not was
// rejected as though the shop were empty.
//
// Stock is held per outlet: availableStock filters `locationid = ?`, so with
// 0 it matches no ledger row and returns 0 for every product. Each line then
// failed the check below with "insufficient stock ... available 0" — for a
// product sitting on the shelf with 25 of them. The message named the wrong
// thing entirely and sent people hunting for stock that was already there,
// which is the most expensive kind of error: confidently wrong.
//
// Checked per line, because a line may carry its own outlet and otherwise
// falls back to the header's.
if err := assertOutletNamed(lines); err != nil {
tx.Rollback()
return models.Orders{}, err
}
if err := lockStockRows(tx, data.Tenantid, lines); err != nil {
tx.Rollback()
return models.Orders{}, err