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 +4 -4
- data/app/controllers/dscf/marketplace/orders_controller.rb +30 -11
- data/lib/dscf/marketplace/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: be5ac84a6073e85553af278f37aed96cab1d39d3284817361e76060ca789f638
|
|
4
|
+
data.tar.gz: 2dfbf53884b07ea2e894e46b8dc3c99f8843b997ff6174a9a154ee1299ce6993
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
652
|
-
|
|
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.
|
|
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).
|
|
688
|
-
#
|
|
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?)
|
|
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
|
|