diff --git a/app/controllers/partners/family_requests_controller.rb b/app/controllers/partners/family_requests_controller.rb index 04c8d17583..eee8f60fc2 100644 --- a/app/controllers/partners/family_requests_controller.rb +++ b/app/controllers/partners/family_requests_controller.rb @@ -68,6 +68,8 @@ def validate for_families: true ).create_only if @partner_request.valid? + @total_items = @partner_request.total_items_fromstr + @quota_exceeded = @total_items > current_partner.quota.to_i body = render_to_string(template: 'partners/requests/validate', formats: [:html], layout: false) render json: {valid: true, body: body} else diff --git a/app/controllers/partners/individuals_requests_controller.rb b/app/controllers/partners/individuals_requests_controller.rb index 04487de05e..ed32c57912 100644 --- a/app/controllers/partners/individuals_requests_controller.rb +++ b/app/controllers/partners/individuals_requests_controller.rb @@ -39,6 +39,8 @@ def validate family_requests_attributes: individuals_request_params[:items_attributes]&.values ).create_only if @partner_request.valid? + @total_items = @partner_request.total_items_fromstr + @quota_exceeded = @total_items > current_partner.quota.to_i body = render_to_string(template: 'partners/requests/validate', formats: [:html], layout: false) render json: {valid: true, body: body} else diff --git a/app/controllers/partners/requests_controller.rb b/app/controllers/partners/requests_controller.rb index 59415fed24..ed088a68f2 100644 --- a/app/controllers/partners/requests_controller.rb +++ b/app/controllers/partners/requests_controller.rb @@ -49,6 +49,8 @@ def validate ).create_only if @partner_request.valid? + @total_items = @partner_request.total_items_fromstr + @quota_exceeded = @total_items > current_partner.quota.to_i body = render_to_string(template: 'partners/requests/validate', formats: [:html], layout: false) render json: {valid: true, body: body} else diff --git a/app/models/request.rb b/app/models/request.rb index 19bc2ee7fa..bdd51e3aab 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -56,6 +56,10 @@ def total_items request_items.sum { |item| item["quantity"] } end + def total_items_fromstr + request_items.sum { |item| item["quantity"].to_i } + end + def user_email partner_user_id ? User.find_by(id: partner_user_id).email : Partner.find_by(id: partner_id).email end diff --git a/app/views/partners/requests/validate.html.erb b/app/views/partners/requests/validate.html.erb index 8270c169b3..97cd8c2ca1 100644 --- a/app/views/partners/requests/validate.html.erb +++ b/app/views/partners/requests/validate.html.erb @@ -5,27 +5,40 @@