dscf-marketplace 0.13.6 → 0.13.7

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: 02ad82c5c180b78f7d7e6dd9fa99ad4f9d085fada05a9458d4f808dc4786589c
4
- data.tar.gz: c2f9f253a2c90b0efd917f1479272bac714761e97a502eaaccc453b1cf57bfb4
3
+ metadata.gz: 21099282f07c99ae15cd4c526736df7c8e1597ff82caf3e1b540380417f093d0
4
+ data.tar.gz: e870bcffce615ba356fec8fa15055aa545a3c7efc17cffe95d6bb61f9420d73b
5
5
  SHA512:
6
- metadata.gz: fa26ea6d381ac3736aae27cb6cd1664629d39a6683524a5266ca8555cbe7c348c0d2c6c642cb1fe32cdfcb017f031091d8c6a07e146e8f7142ca319c83d5bc02
7
- data.tar.gz: 5906f2d82f237f21a0038c2c2304a4455faeb46982fc5fb9779675796e75feb5f08f3a0584784b978a0ab159f439722a1c2c506f28d08c43ed9bf6f60096d193
6
+ metadata.gz: e3284d4198ad24bbe298fbf6a6a9c4be20a33e72ed0391d865f524859fd0064c925f8d0693f25bc23cf47504e1f180a0a52dc3fa0256ab8cf8b2ac0f5bfb0334
7
+ data.tar.gz: 3667ca220153c9a32cc0162ef8018c9204fdb39005f4a109ce88f8e77f31c08d110d1f76d2d25009e6bc891b0c611eb124dfc688044a81a53efd7adcd6695397
@@ -14,16 +14,27 @@ module Dscf
14
14
  password_confirmation: registration_params[:password_confirmation]
15
15
  )
16
16
 
17
+ # `authenticate_user` is skipped for this action so self-service
18
+ # registration stays public, but `current_user` still resolves
19
+ # whatever Bearer token was sent — an agent onboarding a retailer
20
+ # on their behalf attaches their own token, so we derive the
21
+ # onboarding agent from it rather than trusting a client-supplied
22
+ # agent_id.
23
+ onboarding_agent = Dscf::Marketplace::Agent.find_by(user_id: current_user&.id)
24
+
17
25
  retailer = Dscf::Marketplace::Retailer.new(
18
26
  name: registration_params[:name],
19
27
  phone: registration_params[:phone],
20
28
  tin_number: registration_params[:tin_number],
21
29
  location: registration_params[:location],
22
- status: :active
30
+ status: :active,
31
+ agent: onboarding_agent,
32
+ onboarded_at: (Time.current if onboarding_agent)
23
33
  )
24
34
 
25
35
  user.save!
26
36
  assign_default_role(user, "RETAILER")
37
+ retailer.user = user
27
38
  retailer.save!
28
39
 
29
40
  render_success("retailers.success.register", data: retailer, status: :created)
@@ -34,8 +45,9 @@ module Dscf
34
45
  end
35
46
 
36
47
  def my_retailers
37
- authorize @clazz.new, :index?
38
- retailers = @clazz.where(agent_id: params[:agent_id])
48
+ authorize @clazz.new, :my_retailers?
49
+ service = MyResourceService.new(current_user)
50
+ retailers = service.my_retailers(params)
39
51
 
40
52
  options = {
41
53
  include: default_serializer_includes[:index] || [],
@@ -35,6 +35,13 @@ module Dscf
35
35
  apply_filters(listings, params)
36
36
  end
37
37
 
38
+ def my_retailers(params = {})
39
+ agent = Dscf::Marketplace::Agent.find_by(user_id: @current_user.id)
40
+ retailers = agent ? Dscf::Marketplace::Retailer.where(agent_id: agent.id) : Dscf::Marketplace::Retailer.none
41
+
42
+ apply_filters(retailers, params)
43
+ end
44
+
38
45
  def my_products(params = {})
39
46
  products = Dscf::Marketplace::SupplierProduct.joins(:business)
40
47
  .where(dscf_core_businesses: {user_id: @current_user.id})
@@ -1,5 +1,5 @@
1
1
  module Dscf
2
2
  module Marketplace
3
- VERSION = "0.13.6".freeze
3
+ VERSION = "0.13.7".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.13.6
4
+ version: 0.13.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Asrat
@@ -536,7 +536,6 @@ files:
536
536
  - config/environments/production.rb
537
537
  - config/locales/en.yml
538
538
  - config/routes.rb
539
- - db/antigravity_seeds.rb
540
539
  - db/demo_seeds.rb
541
540
  - db/migrate/20250827172043_create_dscf_marketplace_categories.rb
542
541
  - db/migrate/20250827173526_update_dscf_marketplace_categories_indexes.rb
@@ -1,274 +0,0 @@
1
- # ════════════════════════════════════════════════════════════════════════════
2
- # ANTIGRAVITY SEEDS — Clean, collision-free, and fully idempotent demo data
3
- # ════════════════════════════════════════════════════════════════════════════
4
- # NOTE: This script does NOT delete any existing tables or database records.
5
- # It safely finds-or-creates our custom test ecosystem.
6
-
7
- puts "🌱 Initializing Antigravity test data safely..."
8
-
9
- # ── 1. Find Existing Super Admin ──
10
- admin = Dscf::Core::User.find_by(email: "admin@dscf.com")
11
- unless admin
12
- puts "❌ admin@dscf.com not found! Creating default admin as fallback..."
13
- admin = Dscf::Core::User.create!(
14
- email: "admin@dscf.com",
15
- phone: "+251999000000",
16
- password: "Admin@2024",
17
- verified_at: Time.current,
18
- temp_password: false
19
- )
20
- end
21
-
22
- sa_role = Dscf::Core::Role.find_or_create_by!(code: "SUPER_ADMIN") { |r| r.name = "Super Admin"; r.active = true }
23
- Dscf::Core::UserRole.find_or_create_by!(user: admin, role: sa_role)
24
-
25
- # Ensure SUPER_ADMIN has basic orders permissions
26
- orders_perms = Dscf::Core::Permission.where(resource: "orders")
27
- orders_perms.each do |perm|
28
- Dscf::Core::RolePermission.find_or_create_by!(role: sa_role, permission: perm)
29
- end
30
- puts "✅ Super Admin configured."
31
-
32
- # ── 2. Find or Create Custom Antigravity Users safely ──
33
- retailer_user = Dscf::Core::User.find_by(email: "antigravity.retailer@example.com")
34
- unless retailer_user
35
- phone = "+251977111111"
36
- # Avoid phone collisions if already taken
37
- while Dscf::Core::User.exists?(phone: phone)
38
- phone = "+251977111#{rand(100..999)}"
39
- end
40
-
41
- retailer_user = Dscf::Core::User.create!(
42
- email: "antigravity.retailer@example.com",
43
- phone: phone,
44
- password: "password",
45
- verified_at: Time.current,
46
- temp_password: false
47
- )
48
- end
49
-
50
- supplier_user = Dscf::Core::User.find_by(email: "antigravity.supplier@example.com")
51
- unless supplier_user
52
- phone = "+251977222222"
53
- # Avoid phone collisions if already taken
54
- while Dscf::Core::User.exists?(phone: phone)
55
- phone = "+251977222#{rand(100..999)}"
56
- end
57
-
58
- supplier_user = Dscf::Core::User.create!(
59
- email: "antigravity.supplier@example.com",
60
- phone: phone,
61
- password: "password",
62
- verified_at: Time.current,
63
- temp_password: false
64
- )
65
- end
66
-
67
- # Assign default USER role
68
- user_role = Dscf::Core::Role.find_or_create_by!(code: "USER") { |r| r.name = "User"; r.active = true }
69
- Dscf::Core::UserRole.find_or_create_by!(user: retailer_user, role: user_role)
70
- Dscf::Core::UserRole.find_or_create_by!(user: supplier_user, role: user_role)
71
-
72
- # Assign marketplace permissions to USER role
73
- Dscf::Core::Permission.where(engine: "dscf-marketplace").find_each do |perm|
74
- Dscf::Core::RolePermission.find_or_create_by!(role: user_role, permission: perm)
75
- end
76
-
77
- puts "✅ Custom users verified/created."
78
-
79
- # ── 3. Find or Create Custom Businesses safely ──
80
- bt_manufacturer = Dscf::Core::BusinessType.find_or_create_by!(name: "Manufacturer")
81
- bt_retailer = Dscf::Core::BusinessType.find_or_create_by!(name: "Retailer")
82
-
83
- retailer_biz = Dscf::Core::Business.find_by(tin_number: "TIN-AG-RET-001")
84
- unless retailer_biz
85
- phone = "+251977111112"
86
- while Dscf::Core::Business.exists?(contact_phone: phone)
87
- phone = "+251977111#{rand(100..999)}"
88
- end
89
-
90
- retailer_biz = Dscf::Core::Business.create!(
91
- name: "Antigravity Supermarket",
92
- user: retailer_user,
93
- business_type: bt_retailer,
94
- contact_phone: phone,
95
- description: "Antigravity Premium Retailer Store",
96
- tin_number: "TIN-AG-RET-001"
97
- )
98
- end
99
-
100
- supplier_biz = Dscf::Core::Business.find_by(tin_number: "TIN-AG-SUP-001")
101
- unless supplier_biz
102
- phone = "+251977222223"
103
- while Dscf::Core::Business.exists?(contact_phone: phone)
104
- phone = "+251977222#{rand(100..999)}"
105
- end
106
-
107
- supplier_biz = Dscf::Core::Business.create!(
108
- name: "Antigravity Coffee & Textile Wholesaler",
109
- user: supplier_user,
110
- business_type: bt_manufacturer,
111
- contact_phone: phone,
112
- description: "Premium Antigravity Wholesaler Export",
113
- tin_number: "TIN-AG-SUP-001"
114
- )
115
- end
116
-
117
- aggregator_biz = Dscf::Core::Business.find_by(tin_number: "TIN-AG-AGG-001")
118
- unless aggregator_biz
119
- phone = "+251977333333"
120
- while Dscf::Core::Business.exists?(contact_phone: phone)
121
- phone = "+251977333#{rand(100..999)}"
122
- end
123
-
124
- aggregator_biz = Dscf::Core::Business.create!(
125
- name: "Antigravity Aggregators",
126
- user: admin,
127
- business_type: bt_manufacturer,
128
- contact_phone: phone,
129
- description: "Official Antigravity Marketplace Aggregator Hub",
130
- tin_number: "TIN-AG-AGG-001"
131
- )
132
- end
133
-
134
- puts "✅ Custom businesses verified/created."
135
-
136
- # ── 4. Categories & Units ──
137
- cat_coffee = Dscf::Marketplace::Category.find_or_create_by!(name: "Antigravity Coffee") do |c|
138
- c.description = "Specialty roasted Ethiopian coffee"
139
- end
140
-
141
- cat_textile = Dscf::Marketplace::Category.find_or_create_by!(name: "Antigravity Textiles") do |c|
142
- c.description = "Premium handwoven fabrics"
143
- end
144
-
145
- u_kg = Dscf::Marketplace::Unit.find_or_create_by!(code: "KG") do |u|
146
- u.name = "Kilogram"
147
- u.unit_type = :weight
148
- end
149
-
150
- u_meter = Dscf::Marketplace::Unit.find_or_create_by!(code: "M") do |u|
151
- u.name = "Meter"
152
- u.unit_type = :dimension
153
- end
154
-
155
- puts "✅ Categories & Units verified/created."
156
-
157
- # ── 5. Products ──
158
- p1 = Dscf::Marketplace::Product.find_or_create_by!(sku: "AG-COF-SID") do |p|
159
- p.name = "Antigravity Sidamo Roasted Coffee"
160
- p.description = "Premium washed Sidamo — Medium Roast"
161
- p.category = cat_coffee
162
- p.unit = u_kg
163
- p.base_quantity = 1.0
164
- p.gross_weight = 1.2
165
- end
166
-
167
- p2 = Dscf::Marketplace::Product.find_or_create_by!(sku: "AG-TEX-GAB") do |p|
168
- p.name = "Antigravity Traditional Gabi Fabric"
169
- p.description = "Handwoven thick cotton Gabi"
170
- p.category = cat_textile
171
- p.unit = u_meter
172
- p.base_quantity = 1.0
173
- p.gross_weight = 0.8
174
- end
175
-
176
- puts "✅ Products verified/created."
177
-
178
- # ── 6. Supplier Record ──
179
- supplier_record = Dscf::Marketplace::Supplier.find_or_create_by!(business_id: supplier_biz.id) do |s|
180
- s.name = "Antigravity Wholesaler Outlet"
181
- s.business_type = :manufacturer
182
- s.contact_phone = supplier_biz.contact_phone
183
- s.address = "Bole Sub-city, Addis Ababa"
184
- end
185
-
186
- # ── 7. Supplier Products ──
187
- sp1 = Dscf::Marketplace::SupplierProduct.find_or_create_by!(business_id: supplier_biz.id, product_id: p1.id) do |sp|
188
- sp.supplier = supplier_record
189
- sp.supplier_price = 400
190
- sp.available_quantity = 1000
191
- sp.minimum_order_quantity = 5
192
- sp.status = :active
193
- end
194
-
195
- sp2 = Dscf::Marketplace::SupplierProduct.find_or_create_by!(business_id: supplier_biz.id, product_id: p2.id) do |sp|
196
- sp.supplier = supplier_record
197
- sp.supplier_price = 300
198
- sp.available_quantity = 500
199
- sp.minimum_order_quantity = 2
200
- sp.status = :active
201
- end
202
-
203
- puts "✅ Supplier Products verified/created."
204
-
205
- # ── 8. Aggregator Listings (Sprint 2 Core Target) ──
206
- al1 = Dscf::Marketplace::AggregatorListing.find_or_create_by!(aggregator_id: aggregator_biz.id, supplier_product_id: sp1.id) do |al|
207
- al.price = 550
208
- al.quantity = 200
209
- al.status = 0 # active/published
210
- end
211
-
212
- al2 = Dscf::Marketplace::AggregatorListing.find_or_create_by!(aggregator_id: aggregator_biz.id, supplier_product_id: sp2.id) do |al|
213
- al.price = 420
214
- al.quantity = 150
215
- al.status = 0 # active/published
216
- end
217
-
218
- puts "✅ Aggregator Listings verified/created."
219
-
220
- # ── 9. Direct Listings ──
221
- Dscf::Marketplace::Listing.find_or_create_by!(business_id: supplier_biz.id, supplier_product_id: sp1.id) do |l|
222
- l.price = 500
223
- l.quantity = 300
224
- l.status = :active
225
- l.description = "Direct Sidamo Roasted Coffee from Antigravity Outlet"
226
- end
227
-
228
- Dscf::Marketplace::Listing.find_or_create_by!(business_id: supplier_biz.id, supplier_product_id: sp2.id) do |l|
229
- l.price = 380
230
- l.quantity = 200
231
- l.status = :active
232
- l.description = "Direct Traditional Handwoven Gabi from Antigravity Outlet"
233
- end
234
-
235
- puts "✅ Direct Listings verified/created."
236
-
237
- # ── 10. Demo Addresses & Agents ──
238
- address = Dscf::Core::Address.find_by(user_id: retailer_user.id)
239
- unless address
240
- address = Dscf::Core::Address.create!(
241
- user: retailer_user,
242
- address_type: :shipping,
243
- country: "Ethiopia",
244
- city: "Addis Ababa",
245
- sub_city: "Bole Sub-city",
246
- woreda: "Woreda 03",
247
- house_numbers: "Suite 4B"
248
- )
249
- end
250
-
251
- agent = Dscf::Marketplace::Agent.find_by(onboarded_by_id: aggregator_biz.id)
252
- unless agent
253
- agent_phone = "+251977444444"
254
- while Dscf::Marketplace::Agent.exists?(phone: agent_phone)
255
- agent_phone = "+251977444#{rand(100..999)}"
256
- end
257
-
258
- Dscf::Marketplace::Agent.create!(
259
- name: "Antigravity Logistics Agent",
260
- phone: agent_phone,
261
- service_area: "Bole Sub-city",
262
- status: :active,
263
- verification_status: :verified,
264
- onboarded_by: aggregator_biz
265
- )
266
- end
267
-
268
- puts "🎉 ALL ANTIGRAVITY SEEDS COMPLETED SUCCESSFULLY WITHOUT DELETING ANY DATA."
269
- puts "--------------------------------------------------------"
270
- puts "🔑 CREDENTIALS TO USE:"
271
- puts "Buyer (Retailer): antigravity.retailer@example.com / password"
272
- puts "Supplier (Wholesaler): antigravity.supplier@example.com / password"
273
- puts "Super Admin: admin@dscf.com / Admin@2024"
274
- puts "--------------------------------------------------------"