class AddImpSaleAccountToPProducts < ActiveRecord::Migration[6.0]
  def change
    add_column :p_products, :imp_sale_account, :string
    
    PProduct.all.each do |p_product|
      hist = OrderHistLine.order("date_facture DESC").where(:code_article =>  p_product.code).first
      if hist
        p_product.imp_sale_account = hist.compte_vente
        p_product.save
        puts hist.id
      end
    end
  end
end
