Sha256: 6c0081ce7ddff4a6dc24c501a27086d5ba8495fec5d94b4c88e80a6dd600db3b
Contents?: true
Size: 1.02 KB
Versions: 9
Compression:
Stored size: 1.02 KB
Contents
module Xsys module Model class Product attr_accessor :id, :name, :cost, :active, :sellable, :list_price_1, :list_price_6, :list_price_35, :markup_1, :markup_6, :markup_35, :category, :provider, :stocks, :remaining_quantity, :sales, :value_added_tax, :list_price_1_date, :list_price_6_date, :list_price_35_date, :cost_date def initialize(attributes={}) attributes.each do |k,v| if k == 'category' @category = ProductCategory.new(v) elsif k == 'provider' @provider = ProductProvider.new(v) elsif k == 'stocks' @stocks = v.map { |s| Stock.new(s) } else self.send("#{k}=", v) if self.respond_to?(k) end end end def sellable_stock stocks.find_all { |s| ![:ser, :ext].include?(s.shop_code.to_sym) }.map(&:quantity).sum end def stock_in(shop_code) stocks.find { |s| s.shop_code.to_sym == shop_code.to_sym }.try(:quantity) end end end end
Version data entries
9 entries across 9 versions & 1 rubygems