Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/run send to supplier as job #1084

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def receive

flash[:notice] = (s ? I18n.t('orders.receive.notice', msg: s) : I18n.t('orders.receive.notice_none'))
end
NotifyReceivedOrderJob.perform_later(@order)
NotifyReceivedOrderJob.perform_later(FoodsoftConfig.scope,@order)
if current_user.role_orders? || current_user.role_finance?
redirect_to @order
elsif current_user.role_pickups?
Expand Down
3 changes: 2 additions & 1 deletion app/jobs/notify_finished_order_job.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class NotifyFinishedOrderJob < ApplicationJob
def perform(order)
def perform(foodcoop,order)
FoodsoftConfig.select_multifoodcoop foodcoop
order.group_orders.each do |group_order|
next unless group_order.ordergroup

Expand Down
3 changes: 2 additions & 1 deletion app/jobs/notify_negative_balance_job.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class NotifyNegativeBalanceJob < ApplicationJob
def perform(ordergroup, transaction)
def perform(foodcoop,ordergroup, transaction)
FoodsoftConfig.select_multifoodcoop foodcoop
ordergroup.users.each do |user|
next unless user.settings.notify['negative_balance']

Expand Down
3 changes: 2 additions & 1 deletion app/jobs/notify_received_order_job.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class NotifyReceivedOrderJob < ApplicationJob
def perform(order)
def perform(foodcoop,order)
FoodsoftConfig.select_multifoodcoop foodcoop
order.group_orders.each do |group_order|
next unless group_order.ordergroup

Expand Down
8 changes: 8 additions & 0 deletions app/jobs/send_order_to_supplier_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class SendOrderToSupplierJob < ApplicationJob
def perform(order)
Mailer.deliver_now_with_default_locale do
Mailer.order_result_supplier(order.created_by, order)
end
order.update!(last_sent_mail: Time.now)
end
end
3 changes: 2 additions & 1 deletion app/mailers/mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,10 @@ def self.deliver_now_with_default_locale(&block)

def self.deliver_now
message = yield
message.deliver_now
message.deliver_now!
rescue StandardError => e
MailDeliveryStatus.create email: message.to[0], message: e.message
raise StandardError, e.message
end

# separate method to allow plugins to mess with the attachments
Expand Down
7 changes: 2 additions & 5 deletions app/models/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def finish!(user)
ordergroups.each(&:update_stats!)

# Notifications
NotifyFinishedOrderJob.perform_later(self)
NotifyFinishedOrderJob.perform_later(FoodsoftConfig.scope,self)
end
end

Expand Down Expand Up @@ -311,10 +311,7 @@ def close_direct!(user)
end

def send_to_supplier!(user)
Mailer.deliver_now_with_default_locale do
Mailer.order_result_supplier(user, self)
end
update!(last_sent_mail: Time.now)
SendOrderToSupplierJob.perform_later(FoodsoftConfig.scope,self)
end

def do_end_action!
Expand Down
2 changes: 1 addition & 1 deletion app/models/ordergroup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def add_financial_transaction!(amount, note, user, transaction_type, link = nil,
t.save!
update_balance!
# Notify only when order group had a positive balance before the last transaction:
NotifyNegativeBalanceJob.perform_later(self, t) if t.amount < 0 && account_balance < 0 && account_balance - t.amount >= 0
NotifyNegativeBalanceJob.perform_later(FoodsoftConfig.scope,self, t) if t.amount < 0 && account_balance < 0 && account_balance - t.amount >= 0
t
end
end
Expand Down
7 changes: 1 addition & 6 deletions config/initializers/active_job_select_foodcoop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@ def self.included(base) # :nodoc:
alias_method :orig_deserialize, :deserialize
alias_method :orig_serialize, :serialize

def serialize(arguments)
ret = orig_serialize(arguments)
ret.unshift FoodsoftConfig.scope
end

def deserialize(arguments)
FoodsoftConfig.select_multifoodcoop arguments.shift
FoodsoftConfig.select_multifoodcoop arguments[0]
orig_deserialize(arguments)
end
end
Expand Down
2 changes: 1 addition & 1 deletion plugins/messages/app/controllers/messages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def new
def create
@message = @current_user.send_messages.new(params[:message])
if @message.save
DeliverMessageJob.perform_later(@message)
DeliverMessageJob.perform_later(FoodsoftConfig.scope,@message)
redirect_to messages_url, notice: I18n.t('messages.create.notice')
else
render action: 'new'
Expand Down
3 changes: 2 additions & 1 deletion plugins/messages/app/jobs/deliver_message_job.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class DeliverMessageJob < ApplicationJob
def perform(message)
def perform(foodcoop,message)
FoodsoftConfig.select_multifoodcoop foodcoop
message.message_recipients.each do |message_recipient|
recipient = message_recipient.user
if recipient.receive_email?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def received(data)
message.add_recipients [@message.sender_id]

message.save!
DeliverMessageJob.perform_later(message)
DeliverMessageJob.perform_later(FoodsoftConfig.scope,message)
end

private
Expand Down
Loading