This commit is contained in:
seb
2026-10-16 22:09:15 +02:00
parent 188cd71f63
commit d7f7d669f9
13 changed files with 446 additions and 171 deletions

View File

@@ -135,4 +135,146 @@ export function register(app, basePath = '') {
});
// #endregion
/**
* @openapi
* /stock/accept:
* post:
* tags: [Stock]
* summary: Accept delivery manifest item(s)
* description: |
* Books acceptance for a delivery manifest item on the ledger (warehouse_id = null).
* If the connected article has stock tracking enabled, an adjustment entry is also
* booked to adjust physical stock in the target warehouse.
* If line amount is negative, books as a delivery return (outgoing).
* security:
* - cookieAuth: []
* x-signals: [stock, ledger, articles, delivery]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* manifestarticleId:
* type: integer
* description: Manifest article ID of the delivery line
* warehouseId:
* type: integer
* description: Optional warehouse ID for inventory intake
* items:
* type: array
* items:
* type: object
* required: [manifestarticleId]
* properties:
* manifestarticleId:
* type: integer
* warehouseId:
* type: integer
* responses:
* 200:
* description: Delivery item(s) accepted successfully
* 400:
* description: Validation error or no company selected
* 404:
* description: Manifest article or warehouse not found
* 409:
* description: Delivery line already accepted on ledger
*/
// #region POST /stock/accept
app.post(`${basePath}/stock/accept`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
return res.status(400).json({ error: selected.error });
}
try {
const result = await db.accept(req.user.id, req.body ?? {});
emit('stock', { companyId: selected.companyId });
emit('ledger', { companyId: selected.companyId });
emit('articles', { companyId: selected.companyId });
emit('delivery', { companyId: selected.companyId });
res.status(200).json(result);
} catch (error) {
const status = stockErrorStatus(error);
if (status === 500) console.error('Stock accept failed:', error);
res.status(status).json({ error: error.message });
}
});
// #endregion
/**
* @openapi
* /stock/ship:
* post:
* tags: [Stock]
* summary: Ship shipment manifest item(s)
* description: |
* Books shipment for a shipment manifest item on the ledger (warehouse_id = null).
* If the connected article has stock tracking enabled, an adjustment entry is also
* booked to deduct physical stock from the target warehouse.
* If line amount is negative, books as a customer retoure (incoming).
* security:
* - cookieAuth: []
* x-signals: [stock, ledger, articles, shipping]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* manifestarticleId:
* type: integer
* description: Manifest article ID of the shipment line
* warehouseId:
* type: integer
* description: Optional warehouse ID for inventory deduction
* items:
* type: array
* items:
* type: object
* required: [manifestarticleId]
* properties:
* manifestarticleId:
* type: integer
* warehouseId:
* type: integer
* responses:
* 200:
* description: Shipment item(s) shipped successfully
* 400:
* description: Validation error or no company selected
* 404:
* description: Manifest article or warehouse not found
* 409:
* description: Shipment line already shipped on ledger
*/
// #region POST /stock/ship
app.post(`${basePath}/stock/ship`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
return res.status(400).json({ error: selected.error });
}
try {
const result = await db.ship(req.user.id, req.body ?? {});
emit('stock', { companyId: selected.companyId });
emit('ledger', { companyId: selected.companyId });
emit('articles', { companyId: selected.companyId });
emit('shipping', { companyId: selected.companyId });
res.status(200).json(result);
} catch (error) {
const status = stockErrorStatus(error);
if (status === 500) console.error('Stock ship failed:', error);
res.status(status).json({ error: error.message });
}
});
// #endregion
}