rawgento_models 0.0.5 → 0.0.6

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: ce5d769ebb6496b1e817bee1f6dfc3397f9ac233
4
- data.tar.gz: c3ea174c2f298c302ddde34690f6ddfa1efa9b8c
3
+ metadata.gz: 793dd871abd2dc8aaaa8d61d3c1b5c891289bb07
4
+ data.tar.gz: b1e49fa0dfe82736482214003fa51ecbb696eec3
5
5
  SHA512:
6
- metadata.gz: 47d051303163b025478762691fec60a341981658e86e559a0ac4ccf22dd80c768ecda63310e75e047e51797fd3664d4653bf1358439a52f943f52c237544e3ad
7
- data.tar.gz: cdcd199b75ae3f3a80208486407b87a9df249ff642c86a2acc8dbaccecbb27e08c0da2de5294a474ccd050495b89046f11f4accb0d2ab03074234cff8bfff08b
6
+ metadata.gz: 38d42218aadea78b2b1f9e1f8a66dfe10de61f07da3b3cb90a201579722a264546ce7db1945efcc043b3a5e9025f709b9d0190bbadc1510cafce0fb5a1996685
7
+ data.tar.gz: df54c2a7752c21b3eba78bd0b72478500929eb62d8328f06bfa5565481a7238d0b5905f0ddeb5ac36b7e6f98361a4faa6a16ae700864b8c9c25f7117fb5ae59a
@@ -1,14 +1,14 @@
1
1
  class CreateOrders < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :orders do |p|
4
- p.string "state"
4
+ p.string "state", default: :new
5
5
  p.datetime "created_at", null: false
6
6
  p.datetime "updated_at", null: false
7
7
  end
8
8
 
9
9
  create_table :order_items do |p|
10
10
  p.references :order, null: false
11
- p.string "state"
11
+ p.string "state", default: :new
12
12
  p.integer "num_wished"
13
13
  p.integer "num_ordered"
14
14
  p.references :remote_product
@@ -2,6 +2,8 @@ module RawgentoModels
2
2
  class LocalProduct < ActiveRecord::Base
3
3
  has_one :remote_product
4
4
  has_many :stock_items
5
+ has_many :order_items
6
+ has_many :orders, through: :order_items
5
7
 
6
8
  default_scope { order("name ASC") }
7
9
 
@@ -1,5 +1,10 @@
1
1
  module RawgentoModels
2
2
  class Order < ActiveRecord::Base
3
3
  has_many :order_items
4
+ scope :queued, -> { where(state: "queued") }
5
+
6
+ def self.current
7
+ find_by(state: "new")
8
+ end
4
9
  end
5
10
  end
@@ -2,5 +2,21 @@ module RawgentoModels
2
2
  class OrderItem < ActiveRecord::Base
3
3
  belongs_to :order
4
4
  belongs_to :local_product
5
+
6
+ delegate :name, to: :local_product
7
+
8
+ scope :processible, -> { where("num_wished > 0") }
9
+
10
+ def remote_product_id
11
+ local_product.remote_product.try(:product_id)
12
+ end
13
+
14
+ def all_ordered?
15
+ num_wished == num_ordered
16
+ end
17
+
18
+ def out_of_stock?
19
+ num_ordered == 0
20
+ end
5
21
  end
6
22
  end
@@ -1,3 +1,3 @@
1
1
  module RawgentoModels
2
- VERSION = "0.0.5".freeze
2
+ VERSION = "0.0.6".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rawgento_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix Wolfsteller
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-29 00:00:00.000000000 Z
11
+ date: 2016-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord