Variable Weights on Line Items

Administrators can set variable weights of products on orders.

Use case
Producer sets 500g unit of mince as available but arrives as 510g. We want to be able to update the weight of the item upon receipt of the item. We want the price to then update automatically including all adjustments.

This will involve an enhancement to the bulk order management page such that an items weight can be edited from this form and item price displayed within the form.

Line Items will have variant weight stored as a field, set upon creation of a line item and then adjusted through the Bulk Order Management page.

As part of this change, clicking update on Bulk Order Management will force relevant order adjustments to be recalculated.

This change has been made by adding two fields to the viewable options on the Bulk Order Management page, ‘Weight/Volume’ and ‘Price’. Price is non-editable and is updated when ‘Weight/Volume’ changes.
A field ‘unit_value’ has been added to the Line Item table so that the weight/volume of a Line Item can be saved on a sold product basis.
The Spree::Api::LineItemController has been extended so that any update to the Line Item via the API will cause the order charges to be updated.

Hi @lin_d_hop - could you possibly add some more info above about how this is going to be done and where it’s up to? Just trying to plan and schedule some other changes to the Bulk Order Management interface but don’t want to get in your way

Hi @Kirsten, I added some implementation details. I’ve been pretty flat out here with the Yorkley eviction threats and catching up on stuff for DFFH plus the rest of life… so haven’t had as time as I’d have liked for OFN. The variable weights is almost ready for a PR. Just one test case causing me a few headaches. Should get it done when I find another solid chunk of time for it.

If you are making big changes to Bulk Order Management then I’m happy to submit a PR before it’s finished so that devs can see exactly the changes I’ve been making. Nothing too substantial in the actual Bulk Order Man code.

no worries - hope life is treating you well. the bulk order stuff doesn’t look like getting done in next couple of weeks so think best we wait. Will check in again if it gets pushed up the priority queue! Going to be very awesome to have this feature in place :slight_smile:

Hi @lin_d_hop, Food Connect need to adjust some product weight/unit values to a fraction (i.e. 1/2 a box) after order have been placed… will this be possible? @lisahill

Hi All,

To explain our use, and possibly make a short-term solution suggestion.

We often put something on our availability list (order cycle) knowing the farmer can supply 10 boxes. Customers get excited about the product and we sell 20 boxes. In the spirit of sharing the harvest, our general protocol is to then simply give every customer half a box.

For now, I can build a variant for each product, which is included in the order cycle but not in the distribution (therefore invisible to customers as an option for purchase, but available to us as an option to add to orders after the cycle ends - tbc doing proper testing of this theory today :smile: ). Downside to this is that the pricing of a half box includes a packing fee, whereas in the ‘share-the-harvest’ situation we’d rather not charge them that fee (@Kirsten i’ll add this to a list of fee topics to discuss in another section)

In the future, what is detailed above looks like it should work for this purpose, and in addition allow us to do any percentage of a box (e.g. sometimes we sell 4.2kg out of a 10kg box, because that’s what we have available - the ability to charge for that amount will be great). @lin_d_hop does that sound similar to what you are working towards?

Yes this is exactly the functionality I have implemented. It’s not yet on staging, awaiting a code review.

In the Bulk Order Mangement tab under Orders you will be able to change any line items weight/volume to a decimal and this will automatically update the price as a ratio.

To ensure that it works, when you create a product you’ll need to add a unit and value
eg Veg Box - Unit: kg - Value: 10

You’ll then be able to edit the delivered ‘value’ to 4.2 and this will update the price to price * 4.2/10 = 42% of the price.

This will be able to be done in bulk, searched for by product and unique per customer.

Let me know if you’d like to know any more, or if you have anything you’d like to add to this.

Additionally, the distribution fees such as packing fees are calculated on the same ratio of the price eg half a box = half the fee.

To get around this the ‘share the harvest’ boxes may need to be a separate variant without the fee on.
If that’s not possible it may mean extra functionality to optionally remove the distribution fees when the unit value is updated. I’ll have to refer this back to @Kirsten to suggest better ways to do this as it sounds a little sticky to me :smile:

@lin_d_hop it all sounds amazing and perfect. Can’t Wait :smile:

first version of this is now in Aus production. Couple of suggested tweaks will be picked up by aus team in next couple of weeks (unless you want to pick up and do @lin_d_hop) -

@oeoeaio @Kirsten @RohanM Please would you comment on the below…

Based on the tweaks on I’d like to propose some changes to the implementation above.

The line item model currently stores the ‘unit_value’ being the weight/volume per quantity.
Weight: 100g Qty: 6 Unit_Value (persisted in DB): 100
If we change the Bulk Management page to show totals:
Total Weight: 600g Qty: 6 Unit_Value (persisted in DB): 100
then I fear we will end up with rounding errors… for example:
Total Weight: 601g Qty: 6 Unit_Value (persisted in DB): 100.1666…7

I propose therefore to update the unit_value field to store the total_weight_volume. This field was added to the line item model for the purposes of this enhancement so there will no knock on effects (this field is not currently used in reports to my understanding, though I suspect it will be soon).

My only hesitation with the above is that it feels a line item is a little inconsistent storing:
Qty: 6 Total_weight_volume: 601.

I’d appreciate a thought or two if you have a moment. For the meantime I’m implementing in this way as my judgement says this is the better option.

Thanks! xx

Hi Lynne,

That sounds like a good approach! One thing that came up for me is that maybe a more specific name for the total_weight_volume field could indicate that an inconsistency is okay. Something like final_weight_volume instead of total_weight_volume.

Also, the weight_volume part seems a bit inconsistent, as the rest of the site uses unit_value as the name for that. But then we end up with a field named final_total_unit_value, which seems really verbose. So overall, I think I like final_weight_volume better, though open to suggestions if you come up with something else.


Hi people,

@kemmyfoo has started using variable weights (the older version prior to these changes obviously) and pointed out that none of the reports actually pick up the new values, which makes them obviously very confusing / wrong :smile:

My suggested path of action on this would be for

  • @sstead to check and document exactly what changes to reports are required (perhaps ‘reply as linked Topic’ to this page)
  • @lin_d_hop - is this something you would be able to do? We’re unlikely to be able to schedule it here before @oeoeaio is back, so wouldn’t get done till September :frowning: @RohanM is still here for three weeks so can ‘tic tac’, code review, merge etc but no way we can fit in actually doing it?

Also @sstead I hate to be the bearer of bad news, but I suspect that when we do bring in @lin_d_hop’s above changes, your videos might need to change? Also, could you include them in the feature page

Hi @Kirsten
Happy to incorporate this into the reports. It would be extremely helpful if @sstead could document which reports need updating.
Cheers x

Here’s a new topic to discuss when and where variable weights should be shown in reports…