xsys 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a827bdbae0d2ad9595a966e968404f083f61b5ab
4
- data.tar.gz: 21f0a0a3917fcac505deaa3e44625842729d6bdd
3
+ metadata.gz: 6fb62153eeb269bd03c7b39b09742eae6a861d32
4
+ data.tar.gz: 67e032fb51aa2be9d634cbf8759a70b7cc1965ed
5
5
  SHA512:
6
- metadata.gz: a1f6e51742a4d44094f8bf14d0332356e7a1afe7e3d9d21978c312644a5ea05cc45fcbacdcda8c411153fe940d30f51cd8d0f1c2f315bac64e41c118486ec2d2
7
- data.tar.gz: bd9dc492e2315e52630e516275ac7146e5ffcb9a5aacdf692968b42bfbeba7502cb9124547f43979b20bf75ca70209b735b18d1912ede0087bebd02dacb09167
6
+ metadata.gz: 491249a982193eecb15d80fc61da96b4b87dc6fdb194b1d37f83684b175df6a8f70c970b7df685d5efaaddcd319763a095aa9dfc4e53b88f0368a91a034f411f
7
+ data.tar.gz: 224a735d55669453c63d5228a8d942cc3a63d1508d5b050bd41e06b327a020550f63e1264ec11ab529b0d24690a2029053da7a220b35854b26e9acb25cb30cbf
data/CHANGELOG.md CHANGED
@@ -313,3 +313,7 @@
313
313
  ## v0.12.0
314
314
 
315
315
  * Fixes for products and stocks
316
+
317
+ ## v0.13.0
318
+
319
+ * Refactor on product fields
@@ -40,27 +40,39 @@ module Xsys
40
40
  end
41
41
  end
42
42
 
43
- def stock_quantity(shop_codes=[])
44
- if shop_codes.empty?
43
+ def stock_quantity(shop_code_or_array=nil)
44
+ if shop_code_or_array.nil?
45
45
  stocks.map(&:quantity).sum
46
+ elsif shop_code_or_array.is_a?(Array)
47
+ stocks.find_all { |s| shop_code_or_array.include?(s.code) }.map(&:quantity).sum
48
+ elsif shop_code_or_array.is_a?(String)
49
+ stocks.find_all { |s| shop_code_or_array.upcase == s.code }.map(&:quantity).sum
46
50
  else
47
- stocks.find_all { |s| shop_codes.include?(s.code) }.map(&:quantity).sum
51
+ raise 'invalid input!'
48
52
  end
49
53
  end
50
54
 
51
- def stock_available(shop_codes=[])
52
- if shop_codes.empty?
55
+ def stock_available(shop_code_or_array=nil)
56
+ if shop_code_or_array.nil?
53
57
  stocks.map(&:available).sum
58
+ elsif shop_code_or_array.is_a?(Array)
59
+ stocks.find_all { |s| shop_code_or_array.include?(s.code) }.map(&:available).sum
60
+ elsif shop_code_or_array.is_a?(String)
61
+ stocks.find_all { |s| shop_code_or_array.upcase == s.code }.map(&:available).sum
54
62
  else
55
- stocks.find_all { |s| shop_codes.include?(s.code) }.map(&:available).sum
63
+ raise 'invalid input!'
56
64
  end
57
65
  end
58
66
 
59
- def stock_reserved(shop_codes=[])
60
- if shop_codes.empty?
67
+ def stock_reserved(shop_code_or_array=nil)
68
+ if shop_code_or_array.nil?
61
69
  stocks.map(&:reserved).sum
70
+ elsif shop_code_or_array.is_a?(Array)
71
+ stocks.find_all { |s| shop_code_or_array.include?(s.code) }.map(&:reserved).sum
72
+ elsif shop_code_or_array.is_a?(String)
73
+ stocks.find_all { |s| shop_code_or_array.upcase == s.code }.map(&:reserved).sum
62
74
  else
63
- stocks.find_all { |s| shop_codes.include?(s.code) }.map(&:reserved).sum
75
+ raise 'invalid input!'
64
76
  end
65
77
  end
66
78
 
@@ -74,7 +86,25 @@ module Xsys
74
86
  stocks.find_all { |x| x.sellable }
75
87
  end
76
88
 
77
- def price_date_for_list(price_list_id)
89
+ def sellable_stocks_quantity
90
+ sellable_stocks.map(&:quantity).sum
91
+ end
92
+
93
+ def sellable_stocks_reserved
94
+ sellable_stocks.map(&:reserved).sum
95
+ end
96
+
97
+ def sellable_stocks_available
98
+ sellable_stocks.map(&:available).sum
99
+ end
100
+
101
+ def price_list(price_list_id)
102
+ prices.find { |p|
103
+ p.price_list_id.to_i == price_list_id.to_i
104
+ }
105
+ end
106
+
107
+ def price_date_with_list(price_list_id)
78
108
  prices.find { |p|
79
109
  p.price_list_id.to_i == price_list_id.to_i
80
110
  }.try(:price_update_date)
@@ -86,7 +116,7 @@ module Xsys
86
116
  }.try(:markup) || BigDecimal.new('0.0')
87
117
  end
88
118
 
89
- def price_in_list(price_list_id)
119
+ def total_price_with_list(price_list_id)
90
120
  prices.find { |p|
91
121
  p.price_list_id.to_i == price_list_id.to_i
92
122
  }.try(:total_price) || BigDecimal.new('0.0')
data/lib/xsys/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Xsys
2
- VERSION = "0.12.0"
2
+ VERSION = "0.13.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xsys
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matias Hick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-01 00:00:00.000000000 Z
11
+ date: 2017-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler