dscf-marketplace 0.16.0 → 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 +34 -11
- data/lib/dscf/marketplace/version.rb +1 -1
- metadata +2 -2
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))
|
|
@@ -70,6 +76,10 @@ module Dscf
|
|
|
70
76
|
end
|
|
71
77
|
|
|
72
78
|
render_success(data: new_order, serializer_options: options, status: :created, meta: meta)
|
|
79
|
+
rescue ActiveRecord::RecordNotFound
|
|
80
|
+
# An unknown order id is a 404, not a business-rule failure — the broad
|
|
81
|
+
# rescue below would otherwise report it as 422.
|
|
82
|
+
raise
|
|
73
83
|
rescue ActiveRecord::RecordInvalid => e
|
|
74
84
|
errors = e.record&.errors&.full_messages&.presence || [ e.message ]
|
|
75
85
|
render_error(errors: errors.join(", "), status: :unprocessable_entity)
|
|
@@ -644,8 +654,15 @@ module Dscf
|
|
|
644
654
|
|
|
645
655
|
reorder_source_lines(source_order).each do |item, seller|
|
|
646
656
|
product_name = item.product&.name
|
|
647
|
-
|
|
648
|
-
|
|
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
|
|
649
666
|
|
|
650
667
|
listing, aggregator_listing = find_reorder_listing(item, seller)
|
|
651
668
|
|
|
@@ -654,7 +671,7 @@ module Dscf
|
|
|
654
671
|
next
|
|
655
672
|
end
|
|
656
673
|
|
|
657
|
-
available = (listing || aggregator_listing).quantity.
|
|
674
|
+
available = (listing || aggregator_listing).quantity.to_d
|
|
658
675
|
if available <= 0
|
|
659
676
|
skipped << {product_id: item.product_id, product_name: product_name, reason: "out_of_stock"}
|
|
660
677
|
next
|
|
@@ -680,12 +697,18 @@ module Dscf
|
|
|
680
697
|
|
|
681
698
|
# The lines worth reordering, each paired with the business it was bought
|
|
682
699
|
# from. A parent holds no lines of its own, so a reorder of a whole cart
|
|
683
|
-
# collects them from its sub-orders (and may split again).
|
|
684
|
-
#
|
|
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.
|
|
685
707
|
def reorder_source_lines(source_order)
|
|
686
708
|
orders = source_order.parent? ? source_order.sub_orders.to_a : [ source_order ]
|
|
687
709
|
orders.flat_map do |order|
|
|
688
|
-
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 ] }
|
|
689
712
|
end
|
|
690
713
|
end
|
|
691
714
|
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dscf-marketplace
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.16.
|
|
4
|
+
version: 0.16.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Asrat
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-07-
|
|
10
|
+
date: 2026-07-30 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: rails
|