<< | Index | >>
tomorrow
To access to users from bin/admin
ch.bbmb.globopharm> users.class -> BBMB::ValueList ch.bbmb.globopharm> users.length -> 6 ch.bbmb.globopharm> users['0'] -> #<BBMB::RootUser:0x7f8129b63440> ch.bbmb.globopharm> users['3'] -> #<BBMB::HospitalUser:0x7f81282a02f0> ch.bbmb.globopharm> users.values[0] -> #<BBMB::RootUser:0x7f8129b63440> ch.bbmb.globopharm> users.values[3] -> #<BBMB::HospitalUser:0x7f81282a02f0>
To update user's data (-> call save_user method)
ch.bbmb.globopharm> save_user(users.values[3], {:customer_id => 1234}, users.values[3].modifier)
Experiment (Updating customer_id)
1. Before
2. Run admin command
ch.bbmb.globopharm> save_user(users.values[3], {:customer_id => 9876}, users.values[3].modifier)
3. After
Experiment (src/util/bbmbapp.rb#)
def replace_customer_ids_gag_to_alloga(map_file = nil) unless map_file return 'set the path to the mapping file' end count = 0 File.readlines(map_file).each do |line| ids = line.chomp.split(/;/) gag_id = ids[0] ean_code = ids[1] alloga_id = ids[2] if user = users.filter(gag_id).values[0] and alloga_id updates = {:customer_id => alloga_id, :customer_ean13 => ean_code} save_user(user, updates, user.modifier) count += 1 end end count end
Run
masa@masa ~/ywesee/bbmb.ch $ bin/admin ch.bbmb.globopharm> replace_customer_ids_gag_to_alloga '/home/masa/work/gagallkd_new.csv' -> 168
Note
Experiment
def update_stock(gid, updates) #@prevalence.executeTransaction(BBMB::Transaction.new(UpdateStockCommand.new(gid, updates))) @prevalence.executeTransaction(BBMB::Transaction.new(UpdateStockCommand2.new(gid, updates))) end
class UpdateStockCommand2 def initialize(gid, values) @values = values @gid = gid end def execute(app) reseller = app.resellers[@gid] reseller.update_products2(@values) end end
def update_products2(values) stock.adjust(product_key, searchable) stock.update_products2(values) end
def update_products2(values) values.each { |value| key = value[:uid] product = @products[key] value.delete(:uid) product.update(value) } if values end
Run
masa@masa ~/ywesee/bbmb.ch $ bin/admin ch.bbmb.globopharm> update_stock('1', [{:uid => '946005', :article_number => '123456'}]) -> 0
Result
Note
masa@masa ~/ywesee/bbmb.ch $ bin/admin ch.bbmb.globopharm> update_stock('1', [{:uid => '123456', :article_number => '946005'}])