Created
June 13, 2011 00:17
-
-
Save xenda/1022153 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SendList < ActiveRecord::Base | |
belongs_to :destination, :polymorphic => true | |
belongs_to :store | |
has_many :send_list_items | |
has_many :products, :through => :send_list_items | |
after_initialize :setup_identifier | |
def total_items | |
self.send_list_items.inject(0){|result,item| result + item.product_total} | |
end | |
def shoes | |
self.send_list_items.select{|i| i.product.shoe?} | |
end | |
def not_shoes | |
self.send_list_items.select{|i| !i.product.shoe?} | |
end | |
def update_stock | |
Product.transaction do | |
self.products.each(&:update_stock_from_send_list) | |
end | |
end | |
def setup_identifier | |
unless self.identifier | |
self.identifier = SendList.last.identifier.next | |
end | |
rescue | |
self.identifier = "000001" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SendList < ActiveRecord::Base | |
# modules | |
include Bentou::Models::Openable | |
include Bentou::Models::AutoIdentifier | |
include Bentou::Models::CategoryFiltrable | |
include Bentou::Models::ItemsManager | |
include Bentou::Models::ProductStockReflectable | |
belongs_to :destination, :polymorphic => true | |
belongs_to :store | |
has_many :send_list_items | |
has_many :products, :through => :send_list_items | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment