feat(orders): manual order optionally creates a linked project
Add `create_project` flag (default true) to `CreateOrderSchema` and `CreateOrderData`. When true and `quotation_id` is absent, `createOrder` creates a `projects` row sharing the order's shared-pool number and `order_id` link — mirroring the from-quotation flow. The route audits the new project creation when it occurs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -288,6 +288,7 @@ interface CreateOrderData {
|
||||
notes?: string | null;
|
||||
items?: OrderItemInput[];
|
||||
sections?: OrderSectionInput[];
|
||||
create_project?: boolean;
|
||||
}
|
||||
|
||||
export async function createOrder(body: CreateOrderData) {
|
||||
@@ -352,7 +353,27 @@ export async function createOrder(body: CreateOrderData) {
|
||||
});
|
||||
}
|
||||
|
||||
return { id: order.id, order_number: order.order_number };
|
||||
let projectId: number | undefined;
|
||||
// Only auto-create a project for genuine offer-less orders; share the
|
||||
// order's number (same shared pool) exactly like the from-quotation flow.
|
||||
if (body.create_project !== false && body.quotation_id == null) {
|
||||
const project = await tx.projects.create({
|
||||
data: {
|
||||
project_number: orderNumber,
|
||||
name: body.scope_title || body.customer_order_number || orderNumber,
|
||||
customer_id: order.customer_id,
|
||||
order_id: order.id,
|
||||
status: "aktivni",
|
||||
},
|
||||
});
|
||||
projectId = project.id;
|
||||
}
|
||||
|
||||
return {
|
||||
id: order.id,
|
||||
order_number: order.order_number,
|
||||
project_id: projectId,
|
||||
};
|
||||
});
|
||||
} catch (err) {
|
||||
if (err instanceof Error && "status" in err) {
|
||||
|
||||
Reference in New Issue
Block a user