update for order process
Add activereocrd-import gem for bulk insert
This commit is contained in:
@@ -5,29 +5,23 @@ class Product < ApplicationRecord
|
||||
mount_uploader :image_path, ProductImageUploader
|
||||
|
||||
def self.search_by_product_code(item_code)
|
||||
account = Account.find_by_title('Product')
|
||||
if !account.nil?
|
||||
account_id = account.id
|
||||
else
|
||||
account_id = 1
|
||||
end
|
||||
|
||||
menu_item_hash = Hash.new
|
||||
mt_instance = Product.find_by_item_code(item_code)
|
||||
if (!mt_instance.nil?)
|
||||
menu_item_hash[:type] = 'Product'
|
||||
menu_item_hash[:account_id] = account_id
|
||||
menu_item_hash[:item_code] = mt_instance.item_code
|
||||
menu_item_hash[:item_instance_code] = mt_instance.item_code
|
||||
menu_item_hash[:name] = mt_instance.name.to_s
|
||||
menu_item_hash[:alt_name] = mt_instance.alt_name.to_s
|
||||
menu_item_hash[:price] = mt_instance.unit_price
|
||||
menu_item_hash[:promotion_price] = 0
|
||||
menu_item_hash[:is_on_promotion] = 0
|
||||
menu_item_hash[:is_available] = 0
|
||||
menu_item_hash[:taxable] = mt_instance.taxable
|
||||
|
||||
return menu_item_hash
|
||||
end
|
||||
end
|
||||
Product.joins("JOIN accounts ON accounts.title = 'Product'")
|
||||
.where(item_code: item_code)
|
||||
.pluck("accounts.id AS account_id", :item_code, :name, :alt_name, :unit_price, :taxable)
|
||||
.map { |account_id, item_code, item_name, item_alt_name, price, taxable|
|
||||
{
|
||||
type: 'Product',
|
||||
account_id: account_id,
|
||||
item_code: item_code,
|
||||
item_instance_code: item_code,
|
||||
name: item_name || '',
|
||||
alt_name: item_name || '',
|
||||
price: price,
|
||||
promotion_price: 0,
|
||||
is_on_promotion: 0,
|
||||
is_available: 0,
|
||||
taxable: taxable
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user