Skip to content

Commit

Permalink
Basic structure placed for assembly in preparation for Demo & PoC
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfenheimm committed Nov 13, 2024
1 parent ea9c3cf commit 8119b4b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
9 changes: 5 additions & 4 deletions pallets/assembly/src/blogic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ impl<T: Config> Pallet<T> {
who: &T::AccountId,
sku: Sku,
serial_number: SerialNumber,
recipe: Recipe,
bom: Bom,
) -> DispatchResult {
// Create a new assembled product
let assembled_product = Item {
sku: sku.clone(),
serial_number: serial_number.clone(),
qty: recipe.output_quantity,
// Include other fields as needed for `Item`
..Default::default()
};
Expand Down Expand Up @@ -86,21 +88,20 @@ impl<T: Config> Pallet<T> {

let _ = required_components.try_push(RecipeComponent {
sku: component.sku.clone(),
serial_number: serial_number, // Track each component individually
serial_number, // Track each component individually
qty: component.qty,
});
}

let bom = Bom {
required_components: required_components.clone(),
required_equipment: assembly_details.required_equipment.clone(),
components: required_components.clone(),
};

// Insert the BOM into the staging area
StagingArea::<T>::insert(
work_order,
assembly_details.required_equipment.clone(),
bom.clone(),
(bom.clone(), assembly_details),
);

Ok(())
Expand Down
11 changes: 7 additions & 4 deletions pallets/assembly/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ pub mod pallet {
Twox64Concat,
WorkOrder, // First key: Work order
Twox64Concat,
Equipment, // Second key: Equipment
Bom, // Value: Bom
OptionQuery, // Query type
Equipment, // Second key: Equipment
(Bom, Recipe), // Value: Bom
OptionQuery, // Query type
>;

#[pallet::event]
Expand Down Expand Up @@ -91,11 +91,14 @@ pub mod pallet {
origin: OriginFor<T>,
sku: Sku,
serial_number: SerialNumber,
recipe: Recipe, // TODO: Only get the recipe qty
bom: Bom,
) -> DispatchResult {
let who = ensure_signed(origin)?;

Self::do_assemble_product(&who, sku.clone(), serial_number, bom.clone())?;
Self::do_assemble_product(&who, sku.clone(), serial_number, recipe, bom.clone())?; // Recipe qty to be sent here instead
// TODO: Think about what happens if the output quantity is less than the defined recipe quantity
// -- It can be acceptable to have a worker manually adjust the item quantity after assembly, in case something went wrong.

// Emit an event
Self::deposit_event(Event::ProductAssembled {
Expand Down
4 changes: 2 additions & 2 deletions pallets/assembly/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ pub type WorkOrder = u32;
pub struct Recipe {
pub required_components: BoundedVec<RecipeComponent, ConstU32<100>>,
pub required_equipment: Equipment,
pub output_quantity: u32,
}

#[derive(Encode, Decode, MaxEncodedLen, TypeInfo, Clone, PartialEq, Eq, Debug)]
pub struct Bom {
pub required_components: BoundedVec<RecipeComponent, ConstU32<100>>,
pub required_equipment: Equipment,
pub components: BoundedVec<RecipeComponent, ConstU32<100>>,
}

#[derive(Encode, Decode, MaxEncodedLen, TypeInfo, Clone, PartialEq, Eq, Debug)]
Expand Down

0 comments on commit 8119b4b

Please sign in to comment.