10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/postprocess/bbmb2.rb', line 10
def Bbmb2.inject(drb_url, idtype, transaction=nil)
if transaction.nil?
transaction, idtype = idtype, nil
end
if(bdd = transaction.model)
bbmb = DRbObject.new(nil, drb_url)
messages = []
bdd.deliveries.each_with_index { |delivery, idx|
inject_id, order, info = nil
begin
customer = delivery.customer
inject_id = customer.acc_id
name = customer.name
if ship = customer.ship_to
name = ship.name
if addr = ship.address
name = addr.lines.first
end
inject_id ||= ship.acc_id
end
inject_id ||= customer.party_id
order = order(delivery)
info = info(delivery)
options = {
:deliver => true,
:create_missing_customer => idtype.to_s,
:transaction => transaction.transaction_id.to_s,
:customer_name => name.to_s,
}
resp = bbmb.inject_order(inject_id, order, info, options)
transaction.respond(idx, resp)
rescue Exception => e
transaction.respond(idx, :products => order)
message = "Bestellung OK, Eintrag in BBMB Fehlgeschlagen:\n" \
<< e.class.to_s << "\n" \
<< e.message << "\n\n" \
<< e.backtrace.join("\n") << "\n\n" \
<< "hospital: #{inject_id}\n"
if(order)
message << "\norder: \n"
order.each { |k| message << "#{k.inspect}\n" }
end
if(info)
message << "\ninfo: \n"
info.each { |k,v| message << "#{k} => #{v}\n" }
end
messages.push message
end
}
unless messages.empty?
raise messages.join("\n\n")
end
transaction.status = :bbmb_ok
end
end
|