Skip to main content

backbone_inventory/domain/event/
declared.rs

1//! The events this module declares, as typed payloads (`events:` in its schema files).
2//!
3//! Generated by metaphor-schema. Do not edit manually.
4//!
5//! Each declaration is a struct here, namespaced under `declared::` so it cannot collide with a
6//! hand-written event type, and implements `DeclaredEvent`: its name, version and aggregate, and
7//! `record(..)`, which builds the outbox row. An event declared with `on:` is staged by the write
8//! hooks of its aggregate, in the write's transaction. One without is staged by hand code:
9//! `ctx.stage(event.record(&id, &ctx))` inside a write's hooks, or
10//! `backbone_outbox::outbox::stage` in a transaction of its own.
11//! Delivery is at least once; a consumer dedupes with `backbone_outbox::inbox::once`.
12
13use backbone_core::write_hooks::DeclaredEvent;
14use serde::{Deserialize, Serialize};
15
16/// a purchase receipt is submitted
17/// Declared in `inventory.hook.yaml`; staged by hand code.
18#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
19pub struct StockReceived {
20    pub receipt_id: serde_json::Value,
21    pub company_id: serde_json::Value,
22    pub warehouse_id: serde_json::Value,
23    pub source_po_id: serde_json::Value,
24    pub total_value: serde_json::Value,
25}
26
27impl DeclaredEvent for StockReceived {
28    const NAME: &'static str = "StockReceived";
29    const VERSION: i32 = 1;
30    const AGGREGATE: &'static str = "";
31}
32
33/// a delivery note is submitted
34/// Declared in `inventory.hook.yaml`; staged by hand code.
35#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
36pub struct StockDelivered {
37    pub delivery_id: serde_json::Value,
38    pub company_id: serde_json::Value,
39    pub warehouse_id: serde_json::Value,
40    pub source_so_id: serde_json::Value,
41    pub total_cogs: serde_json::Value,
42}
43
44impl DeclaredEvent for StockDelivered {
45    const NAME: &'static str = "StockDelivered";
46    const VERSION: i32 = 1;
47    const AGGREGATE: &'static str = "";
48}
49
50/// a stock transfer is submitted
51/// Declared in `inventory.hook.yaml`; staged by hand code.
52#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
53pub struct StockMoved {
54    pub entry_id: serde_json::Value,
55    pub company_id: serde_json::Value,
56    pub from_warehouse_id: serde_json::Value,
57    pub to_warehouse_id: serde_json::Value,
58}
59
60impl DeclaredEvent for StockMoved {
61    const NAME: &'static str = "StockMoved";
62    const VERSION: i32 = 1;
63    const AGGREGATE: &'static str = "";
64}
65
66/// a stock reconciliation is submitted
67/// Declared in `inventory.hook.yaml`; staged by hand code.
68#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
69pub struct StockReconciled {
70    pub reconciliation_id: serde_json::Value,
71    pub company_id: serde_json::Value,
72    pub warehouse_id: serde_json::Value,
73    pub net_difference: serde_json::Value,
74}
75
76impl DeclaredEvent for StockReconciled {
77    const NAME: &'static str = "StockReconciled";
78    const VERSION: i32 = 1;
79    const AGGREGATE: &'static str = "";
80}
81
82/// a landed cost is validated (cost lines allocated, remaining-share revaluation minted)
83/// Declared in `inventory.hook.yaml`; staged by hand code.
84#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
85pub struct LandedCostValidated {
86    pub lc_id: serde_json::Value,
87    pub company_id: serde_json::Value,
88    pub target_receipt_id: serde_json::Value,
89    pub amount_total: serde_json::Value,
90    pub revalued_value: serde_json::Value,
91}
92
93impl DeclaredEvent for LandedCostValidated {
94    const NAME: &'static str = "LandedCostValidated";
95    const VERSION: i32 = 1;
96    const AGGREGATE: &'static str = "";
97}
98
99/// a stock move hits confirmed
100/// Declared in `stock.hook.yaml`; staged by hand code.
101#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
102pub struct MoveConfirmed {
103    pub move_id: serde_json::Value,
104    pub company_id: serde_json::Value,
105    pub item_id: serde_json::Value,
106    pub demand_qty: serde_json::Value,
107    pub picking_id: serde_json::Value,
108}
109
110impl DeclaredEvent for MoveConfirmed {
111    const NAME: &'static str = "MoveConfirmed";
112    const VERSION: i32 = 1;
113    const AGGREGATE: &'static str = "";
114}
115
116/// a stock move hits assigned (fully reserved)
117/// Declared in `stock.hook.yaml`; staged by hand code.
118#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
119pub struct MoveAssigned {
120    pub move_id: serde_json::Value,
121    pub company_id: serde_json::Value,
122    pub picking_id: serde_json::Value,
123}
124
125impl DeclaredEvent for MoveAssigned {
126    const NAME: &'static str = "MoveAssigned";
127    const VERSION: i32 = 1;
128    const AGGREGATE: &'static str = "";
129}
130
131/// a stock move hits done (quants flipped, SLE minted)
132/// Declared in `stock.hook.yaml`; staged by hand code.
133#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
134pub struct MoveDone {
135    pub move_id: serde_json::Value,
136    pub company_id: serde_json::Value,
137    pub item_id: serde_json::Value,
138    pub quantity: serde_json::Value,
139    pub price_unit: serde_json::Value,
140    pub is_inventory: serde_json::Value,
141}
142
143impl DeclaredEvent for MoveDone {
144    const NAME: &'static str = "MoveDone";
145    const VERSION: i32 = 1;
146    const AGGREGATE: &'static str = "";
147}
148
149/// a stock move hits cancel (reservation released)
150/// Declared in `stock.hook.yaml`; staged by hand code.
151#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
152pub struct MoveCancelled {
153    pub move_id: serde_json::Value,
154    pub company_id: serde_json::Value,
155    pub released_qty: serde_json::Value,
156}
157
158impl DeclaredEvent for MoveCancelled {
159    const NAME: &'static str = "MoveCancelled";
160    const VERSION: i32 = 1;
161    const AGGREGATE: &'static str = "";
162}
163
164/// a transfer's projected state changes (T1 recompute)
165/// Declared in `stock.hook.yaml`; staged by hand code.
166#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
167pub struct TransferProjected {
168    pub transfer_id: serde_json::Value,
169    pub company_id: serde_json::Value,
170    pub state: serde_json::Value,
171    pub previous_state: serde_json::Value,
172}
173
174impl DeclaredEvent for TransferProjected {
175    const NAME: &'static str = "TransferProjected";
176    const VERSION: i32 = 1;
177    const AGGREGATE: &'static str = "";
178}
179
180/// a partial validate mints the backorder transfer
181/// Declared in `stock.hook.yaml`; staged by hand code.
182#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
183pub struct BackorderCreated {
184    pub backorder_id: serde_json::Value,
185    pub company_id: serde_json::Value,
186    pub origin_id: serde_json::Value,
187}
188
189impl DeclaredEvent for BackorderCreated {
190    const NAME: &'static str = "BackorderCreated";
191    const VERSION: i32 = 1;
192    const AGGREGATE: &'static str = "";
193}
194
195/// the scheduler orders on a reordering rule (T11)
196/// Declared in `stock.hook.yaml`; staged by hand code.
197#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
198pub struct OrderpointTriggered {
199    pub orderpoint_id: serde_json::Value,
200    pub company_id: serde_json::Value,
201    pub item_id: serde_json::Value,
202    pub qty_to_order: serde_json::Value,
203    pub forecast_qty: serde_json::Value,
204}
205
206impl DeclaredEvent for OrderpointTriggered {
207    const NAME: &'static str = "OrderpointTriggered";
208    const VERSION: i32 = 1;
209    const AGGREGATE: &'static str = "";
210}
211
212/// The Postgres schemas whose `outbox_events` table this module's staged events are written to.
213pub const OUTBOX_SCHEMAS: &[&str] = &[];
214
215/// Create the outbox and inbox tables of [`OUTBOX_SCHEMAS`] (idempotent). The composing service
216/// runs it at startup with a role that may create tables, beside its relay; a write that stages an
217/// event needs the table to exist.
218pub async fn migrate_outbox(pool: &backbone_orm::PgPool) -> anyhow::Result<()> {
219    for schema in OUTBOX_SCHEMAS {
220        backbone_core::write_hooks::migrate_outbox(pool, schema).await?;
221    }
222    Ok(())
223}