Order From List of Cards
Description¶
Allow Users either through the UI or an API call to create an Order (Header and Lines) from a list of KanbanCards.
Requirement¶
Given a list of KanbanCard Details (given by cards.arda.operations.resources.kanban.business.KanbanCardDetails) implement
a function that creates:
- An OrderHeader object (
cards.arda.operations.resources.order.business.OrderHeader) - An OrderMetadata object (
cards.arda.operations.resources.order.business.OrderMetadata) - A list of
Pair<OrderLine, OrderLineMetadata>objects (cards.arda.operations.resources.order.business.OrderLine,cards.arda.operations.resources.order.business.OrderLineMetadata)
Preconditions/Validations¶
If any of these preconditions are violated, the system will return an error and no changes to the system will be made.
- All input KanbanCards are in status
KanbanCardStatus.REQUESTING - All Kanban Cards must be for the same Vendor or have no vendor information.
Scenario Overview¶
- The user selects a list of Kanban Cards in status
KanbanCardStatus.REQUESTING. - The system then:
- Identifies the Cards by their
eIdand theTimeCoordinates.now()bitemporal coordinates. - Retrieves the
KanbanCardDetailsand composes an OrderHeader and a list of OrderLines according to the rules below. - Persists the OrderHeader and OrderLines.
- Signals the KanbanCards
KanbanCardEventType.ACCEPTwhich causes them to transition toKanbanCardStatus.ORDERED,
and links them to the created OrderLines. - Returns the newly created OrderHeader and OrderLines for the User (through the UI or API) to review and modify.
- Identifies the Cards by their
PostConditions¶
- The new OrderHeader and OrderLines are persisted and accessible in the system.
- The selected KanbanCards are updated to status
KanbanCardStatus.ORDEREDand linked to the created OrderLines.
Creation of Order Lines¶
One order line will be created for each group of KanbanCardDetails that share the same values for:
item.eIdcardQuantity.unit
cardQuantity.unit values include null.
Note
Define $ as the KanbanCardDetails object under consideration.
The fields of the resulting OrderLine are:
Simple OrderLine fields¶
- The eId’s of
OrderLineis generated with a Random UUID (UUID.randomUUID()) statusset toOrderLineStatus.BLANKitem: set to theitemfield of the `KanbanCardDetailsreceivedset to0.0with the same unit as thequantityfield (see below)notesset tonull
6privateNotesset tonull
Quantity field.¶
Intermediate values¶
- Define
$.sourceSupplyas the object$.itemDetails.primarySupplyor$.itemDetails.secondarySupplywhosesupplierfield is equals toheader.supplierName(see below how this is determined). This value isnull
if either the headersupplierNameisnullor if neither of the two supplies has asupplierfield equal toheader.supplierName.
Quantity computation¶
if the unit value of the group is null, the quantity for the order line is null.
Otherwise:
unitset to the sharedcardQuantity.unitof the group.amountsets to:- The sum of the
cardQuantity.amountif theunitfield is either different to the$.sourceSupply.orderQuantity.unitor if$.sourceSupply.orderQuantityis null. - The maximum of the sum of the
cardQuantity.amountand the$.sourceSupply.orderQuantity.amountif theunitfield is equal (not null) to the$.sourceSupply.orderQuantity.unit.
- The sum of the
Unit Cost field.¶
unitCostisnullifR.sourceSupplyisnullor if$.sourceSupply.orderQuantity.unitis different than$.quantity.unit.- Otherwise,
unitCostis set to$.sourceSupply.unitCost.
Cost field¶
costisnullif eitherunitCostorquantityisnull.- Otherwise,
costis set tounitCost * quantity.amountin the same currency unit as$.unitCost.
Cards Field¶
The cards field is a list of KanbanCardReference Value objects. They are implemented as a Json field in the OrderLine table for persistence.
This means that the cards field is not accessible through queries at this point. For it to be queryable, a new intersection table will be needed and
may be implemented in a future release.
Creation of Order Header¶
Simple OrderHeader fields¶
- The eId’s of
OrderHeaderis generated with a Random UUID (UUID.randomUUID()) - Simple
OrderHeaderfields:statusset toOrderStatus.BLANKorderNumber: For now, set to a parameter of the function.orderDate: Set to the current time in the timezone of the system.allowPartialset totruedeliverByset to the current time plus 7 days in the timezone of the system.deliveryAddressset tonull.procurement: set tonullsupplierAddress: set tonull.sales: set tonull.taxesAndFees: set to an empty map.termsAndConditions: set tonull.notes: set tonull.privateNotes: set tonull.
supplierName field¶
Let candidateSuppliers for a KanbanCardDetails be the list of values: itemDetails.primarySupply.supplier, itemDetails.secondarySupply.supplier that are non-null.
- If there is a value in all the
KanbanCardDetails.candidateSuppliersthat is common to all of them, then setsupplierNameto that value. - If there are no common non-null values shared by all
KanbanCardDetailsin the list, setsupplierNametonull. - If there is more than one common non-null value shared by all
KanbanCardDetails, pick the one that has the most mentions asitemDetails.primarySupply.supplieracross allKanbanCardDetails.
orderMethod field¶
If the supplierName assigned according to the rules above is non-null, set orderMethod to the value of the first non-null value among the itemDetails.primarySupply.orderMethod in the
order of the list of KanbanCardDetails in the input argument.
Otherwise, set orderMethod to OrderMethod.UNKNOWN.
goodsValue field¶
Set the goodsValue field to sum(orderLine.cost) for all order lines created from the KanbanCardDetails in the input argument that have non-null cost fields (see above).
Updates to Kanban Cards¶
Each KanbanCard in the input list will be signalled with a KanbanCardEventType.ACCEPT event that will cause it to transition to status KanbanCardStatus.ORDERED through
the KanbanCardService.