dscf-marketplace 0.16.1 → 0.16.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a15bb7684af77ccd9899a60837a6c1e9e8ee8fb17a22729a39e070360d33dbfd
4
- data.tar.gz: 4cff160785cbc7a393836aabe6b867764680b43b0a8d35cea99669f2ee21946d
3
+ metadata.gz: be5ac84a6073e85553af278f37aed96cab1d39d3284817361e76060ca789f638
4
+ data.tar.gz: 2dfbf53884b07ea2e894e46b8dc3c99f8843b997ff6174a9a154ee1299ce6993
5
5
  SHA512:
6
- metadata.gz: bc114a3c32f7d60a54add756c7806c07d6c729b4a71be4e8be75c0a7db2a88e0818c437a64e7b6eeb4d5d64385c9311c309f56d89cceb913340b2c6030076d12
7
- data.tar.gz: 3dd22ead0c2ea3ad985505e336b2ff238a12d9b08e5f016286b584ed35f8c05dc8798d7ec64a19c47f6131831a95da653f8e88f7a0215d4533f1b7730833dbed
6
+ metadata.gz: 3e6c001c6f0af07cda0207acda610c20cb6eabd41c2a3fd24f8c4ea026c46e1b0dc8b6c7a84b5d3fcf22ec4b0bf974c434cdfe668a50049d4320260005d2b34c
7
+ data.tar.gz: 5115dad31f5607464892aea0b3dbee5d6761b84f21c81e26cc73febe091a13a1c7358911f89b21c37c618f78cbbd5f32a437ea131627502ae0872f5be486a538
@@ -44,11 +44,17 @@ module Dscf
44
44
  resolved_items, skipped, adjusted = resolve_reorder_items(source_order)
45
45
 
46
46
  if resolved_items.empty?
47
- return render_error(
48
- errors: "None of the items on order ##{source_order.id} are available to reorder",
49
- status: :unprocessable_entity,
50
- skipped_items: skipped
51
- )
47
+ # Distinguish "nothing left to reorder" from "everything is
48
+ # unavailable" an order whose lines were all cancelled has no
49
+ # availability problem, and reporting one sends the caller hunting
50
+ # through listings for a cause that isn't there.
51
+ message = if skipped.empty?
52
+ "Order ##{source_order.id} has no reorderable items (every line was cancelled or the order has no items)"
53
+ else
54
+ "None of the items on order ##{source_order.id} are available to reorder"
55
+ end
56
+
57
+ return render_error(errors: message, status: :unprocessable_entity, skipped_items: skipped)
52
58
  end
53
59
 
54
60
  parent, orders = place_direct_listing_cart(resolved_items, base_attrs: reorder_base_attributes(source_order))
@@ -648,8 +654,15 @@ module Dscf
648
654
 
649
655
  reorder_source_lines(source_order).each do |item, seller|
650
656
  product_name = item.product&.name
651
- wanted = item.quantity.to_i
652
- next if wanted <= 0
657
+ # Quantities are decimal(15,6) — goods sold by weight have fractional
658
+ # lines, and an aggregator resolving a line can set any decimal. to_i
659
+ # would silently truncate 0.5 to 0 and drop the line.
660
+ wanted = item.quantity.to_d
661
+
662
+ if wanted <= 0
663
+ skipped << {product_id: item.product_id, product_name: product_name, reason: "invalid_quantity"}
664
+ next
665
+ end
653
666
 
654
667
  listing, aggregator_listing = find_reorder_listing(item, seller)
655
668
 
@@ -658,7 +671,7 @@ module Dscf
658
671
  next
659
672
  end
660
673
 
661
- available = (listing || aggregator_listing).quantity.to_i
674
+ available = (listing || aggregator_listing).quantity.to_d
662
675
  if available <= 0
663
676
  skipped << {product_id: item.product_id, product_name: product_name, reason: "out_of_stock"}
664
677
  next
@@ -684,12 +697,18 @@ module Dscf
684
697
 
685
698
  # The lines worth reordering, each paired with the business it was bought
686
699
  # from. A parent holds no lines of its own, so a reorder of a whole cart
687
- # collects them from its sub-orders (and may split again). Cancelled lines
688
- # were never fulfilled, so they don't come along.
700
+ # collects them from its sub-orders (and may split again).
701
+ #
702
+ # Whether a cancelled line comes along depends on what was cancelled. A
703
+ # cancelled ORDER is precisely what a retailer wants to re-place — every
704
+ # line reads as cancelled, and dropping them all would leave nothing to
705
+ # reorder. On a live order a cancelled LINE was deliberately removed
706
+ # during validation or refused by its supplier, and that decision stands.
689
707
  def reorder_source_lines(source_order)
690
708
  orders = source_order.parent? ? source_order.sub_orders.to_a : [ source_order ]
691
709
  orders.flat_map do |order|
692
- order.order_items.reject(&:cancelled?).map { |item| [ item, order.ordered_to ] }
710
+ items = order.cancelled? ? order.order_items.to_a : order.order_items.reject(&:cancelled?)
711
+ items.map { |item| [ item, order.ordered_to ] }
693
712
  end
694
713
  end
695
714
 
@@ -1,5 +1,5 @@
1
1
  module Dscf
2
2
  module Marketplace
3
- VERSION = "0.16.1".freeze
3
+ VERSION = "0.16.2".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dscf-marketplace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.1
4
+ version: 0.16.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Asrat