view · edit · sidebar · attach · print · history

20110721-replace-user-stock-ids-bbmb

<< | Index | >>


  1. Understand the algorithm of updating user stock
  2. Replace user ids
  3. Replace stock ids

Goal/Estimate/Evaluation
  • Replace user and stock ids / 80% / 70%
Milestones
  • replace user ids
  • replace stock ids tomorrow
Summary
Commits

Understand the algorithm of updating user stock

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

Replace user ids

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

Replace stock ids

Experiment

  • src/util/bbmbapp.rb
  def update_stock(gid, updates)
    #@prevalence.executeTransaction(BBMB::Transaction.new(UpdateStockCommand.new(gid, updates)))
    @prevalence.executeTransaction(BBMB::Transaction.new(UpdateStockCommand2.new(gid, updates)))
  end
  • src/transactions/stock.rb
class UpdateStockCommand2
  def initialize(gid, values)
    @values = values
    @gid = gid
  end
  def execute(app)
    reseller = app.resellers[@gid]
    reseller.update_products2(@values)
  end
end
  • src/model/reseller.rb
    def update_products2(values)
      stock.adjust(product_key, searchable)
      stock.update_products2(values)
    end
  • src/model/stock.rb
    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

  • Before
  • After

Note

  • But the this 'uid' remains after the updating
  • Namely, the following command does not work after the updating
masa@masa ~/ywesee/bbmb.ch $ bin/admin
ch.bbmb.globopharm> update_stock('1', [{:uid => '123456', :article_number => '946005'}])
  • I have to check why it does not work tomorrow.
view · edit · sidebar · attach · print · history
Page last modified on July 21, 2011, at 05:10 PM