openfoodfoundation / openfoodnetwork

Connect suppliers, distributors and consumers to trade local produce.
https://www.openfoodnetwork.org
GNU Affero General Public License v3.0
1.1k stars 714 forks source link

[DFC] Orders Part 1: Create order from OFN via DFC #11678

Open mkllnk opened 11 months ago

mkllnk commented 11 months ago

Funded Feature. Please track ALL ASSOCIATED WORK under the associated tracking code #11678 DFC Orders

What is the problem we are solving

The UK project Food Data Collaboration (FDC) aims to connect Shopify and OFN via the Data Food Consortium (DFC) standard.

With DFC products completed, products can exist within OFN and be linked to products another platform. An OFN Hub can add these products to their shopfront. When a shopper buys these products the order must be placed on the originating platform. The orders from different customers on a Hub order cycle must be aggregated into a single wholesale order.

In Part 1 the minimum requirement is only implementing sending orders from OFN to another Platform. Orders from the other platform back to OFN are currently out of scope. Stock is also out of scope in this case.

Success factors = expected outcome

Ignoring for now:

Useful information for inception

Link to the "Product Development - Backlog" item in Discourse

RaggedStaff commented 11 months ago

Further to discussion on slack... yes, we will need to use OIDC authentication for this. We'll need a token refresh method implementing in OFN, I didn't realise that wasn't already included in the Product work.

lin-d-hop commented 11 months ago

I feel confused that this issue is referencing Shopify. Does this change the spec from integrating with the DFC? If so then I would suggest the spec might be out.

Would anyone mind if I reframed this to not specifically talk about SHopify?

RaggedStaff commented 11 months ago

Would anyone mind if I reframed this to not specifically talk about SHopify?

Go for it - we can refer to Producer platform (Shopify) and Hub platform (OFN) if that's easier?

RaggedStaff commented 10 months ago

Just a note from conversations with @lin-d-hop around Shopify work... we need to track any partial sold whoelsale cases/product across Sales Sessions (Order Cycles).

For example: A hub received a retail order for 8 cans of beans They order 1 case of 12 cans of beans, so have 4 remaining in stock at the end of the order cycle We need to ensure these 4 are sold in the next Order Cycle, before ordering any further cases

I think we can probably use existing OFN inventory functionality, is that right @lin-d-hop ?

mkllnk commented 10 months ago

O#%&$... I was hoping not to worry about stock in part 1. I thought that in the first order cycle, we would only order wholesale items if we actually reach the number. Otherwise we fall back to retail items to not have spare stock.

This is a whole new functionality not implemented anywhere. But I think you are hinting at the DFC order being like a backorder. So we draw local stock first, allow going over because they are backorderable (this term is in our code, comes from Spree) and then place an aggregated backorder with wholesale items at the end of the order cycle.

But OFN removed this whole backorder concept. When an order is "backorderable" it just means we don't care about stock and don't adjust the level. Stock levels can't go negative at the moment. So we can't use a model of a customer order drawing stock into negative and that negative level being used to place the DFC wholesale order. To make this work, the OFN customer order shouldn't adjust the stock level and the DFC order aggregation draws from stock first then increases the quantity on wholesale line items. This may get really hacky to start with.

mkllnk commented 10 months ago

Example:

This is a bit crazy because the wholesale order is only a draft at this point. But we hope to reserve stock in the future, right? So then it would be fair to count that. I just don't know how we work with our existing data structure otherwise.

RaggedStaff commented 10 months ago

O#%&$... I was hoping not to worry about stock in part 1. I thought that in the first order cycle, we would only order wholesale items if we actually reach the number. Otherwise we fall back to retail items to not have spare stock.

There is an option we've implemented in Shopify: Order Partially Sold Cases which allows the Hub to determine whether to order a wholesale case when the first one is ordered, or the last one, but we may drop that (and it's not in scope for the intial OFN work) as it has the potential to be confusing & lead to orders going unfulfilled.

This isn't directly related... this is the part where:

Does that make sense?

There are 2 ways I see this could be done:

  1. The backorderable thing you mention (sounds complex) :sweat:

  2. We track how many items have been ordered within the Order Cycle (we need to do that anyway, right... in order to tell when to amend the wholesale order), and persist that value between Order Cycles.

Maybe we should have a quick chat about this? I'm around in the am, if you want to book a call.

lin-d-hop commented 10 months ago

I'd like to be in on any call you have please :pray:

@mkllnk I think this might be overcomplicated a bit. Core priority - The stock only needs to be checked before an order is created with the wholesaler. Secondary - After the wholesaler order is made any excess stock is added. This is the thing OFN doesn't currently do. For the initial implementation we can get away with the user having to update stock after the wholesale order. This isnt ideal and could be a nice to have if there is budget left.

The supplier side does most of the work with stock levels so we don't need to do the complexity you describe. @RaggedStaff #2 is more realistic.

mkllnk commented 10 months ago

We track how many items have been ordered within the Order Cycle (we need to do that anyway, right... in order to tell when to amend the wholesale order), and persist that value between Order Cycles.

I was hoping for a simpler solution that works just on the fly:

In this version, all state needed would be persisted in the DFC wholesale order and OFN wouldn't need to store anything. But if I understand you correctly then we don't want to order any retail packs in the wholesale order and we order enough bulk items to cover all retail orders even if we have left-over stock. Then we need to adjust stock accordingly.

I think that my solution I described as "crazy" is workable. At this point I prefer that over adding more data structures to the OFN database to track stock over order cycles separately.

This week is really busy. We could try to chat next week. Maybe Thursday?

lin-d-hop commented 9 months ago

At this point I prefer that over adding more data structures to the OFN database to track stock over order cycles separately. I don't see how we would need to add anything to OFN data structures. OFN already tracks stock.

In the case that the product is linking to cases of 12, I see it as:

Or when OFN has some stock:

The Shopify integration handles this and this seems like a straight forward way for OFN to best handle this. ping @RaggedStaff @mkllnk

I'll be in touch via Slack for a call

mkllnk commented 9 months ago

Yes, that sounds doable.