rawgento_models 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/db/migrate/201601251100_extend_order_items.rb +9 -0
- data/db/schema.rb +70 -0
- data/lib/rawgento_models/local_product.rb +25 -0
- data/lib/rawgento_models/order.rb +1 -1
- data/lib/rawgento_models/order_item.rb +3 -2
- data/lib/rawgento_models/version.rb +1 -1
- data/lib/rawgento_models.rb +5 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fff3563decf85914571c8610becc7b5fb285af8a
|
4
|
+
data.tar.gz: eff0f653af0142cb5e2efb8d3387860f54eea424
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f407ada163fa0303617a395b8b821c062b708580a462cf429b8a3fea6e19823d1541f181aa5c6cc82243e617aeacf57f7509a5db5107447e2c98af2d6a11ed7b
|
7
|
+
data.tar.gz: cf68a93be167a13825f8069bc415f6fb5f87c9dd60adf06ff3e604816937326261194a4409e2c06b52decb20591c511f7c9a2907b65ebc2eefd72c30bfb2b089
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class ExtendOrderItems < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
add_reference :order_items, :local_product, index: true
|
4
|
+
add_foreign_key :order_items, :local_products
|
5
|
+
add_column :order_items, :current_stock, :integer
|
6
|
+
add_column :order_items, :min_stock, :integer
|
7
|
+
remove_column :order_items, :remote_product_id
|
8
|
+
end
|
9
|
+
end
|
data/db/schema.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# This file is auto-generated from the current state of the database. Instead
|
3
|
+
# of editing this file, please use the migrations feature of Active Record to
|
4
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
+
#
|
6
|
+
# Note that this schema.rb definition is the authoritative source for your
|
7
|
+
# database schema. If you need to create the application database on another
|
8
|
+
# system, you should be using db:schema:load, not running all the migrations
|
9
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
+
#
|
12
|
+
# It's strongly recommended that you check this file into your version control system.
|
13
|
+
|
14
|
+
ActiveRecord::Schema.define(version: 201601251100) do
|
15
|
+
|
16
|
+
create_table "local_products", force: :cascade do |t|
|
17
|
+
t.string "name"
|
18
|
+
t.string "supplier"
|
19
|
+
t.integer "product_id"
|
20
|
+
t.datetime "created_at", null: false
|
21
|
+
t.datetime "updated_at", null: false
|
22
|
+
t.integer "shelve_nr"
|
23
|
+
t.integer "packsize"
|
24
|
+
t.boolean "active", default: true
|
25
|
+
end
|
26
|
+
|
27
|
+
add_index "local_products", ["product_id"], name: "index_local_products_on_product_id", unique: true
|
28
|
+
|
29
|
+
create_table "order_items", force: :cascade do |t|
|
30
|
+
t.integer "order_id", null: false
|
31
|
+
t.string "state"
|
32
|
+
t.integer "num_wished"
|
33
|
+
t.integer "num_ordered"
|
34
|
+
t.datetime "created_at", null: false
|
35
|
+
t.datetime "updated_at", null: false
|
36
|
+
t.integer "local_product_id"
|
37
|
+
t.integer "current_stock"
|
38
|
+
t.integer "min_stock"
|
39
|
+
end
|
40
|
+
|
41
|
+
add_index "order_items", ["local_product_id"], name: "index_order_items_on_local_product_id"
|
42
|
+
|
43
|
+
create_table "orders", force: :cascade do |t|
|
44
|
+
t.string "state"
|
45
|
+
t.datetime "created_at", null: false
|
46
|
+
t.datetime "updated_at", null: false
|
47
|
+
end
|
48
|
+
|
49
|
+
create_table "remote_products", force: :cascade do |t|
|
50
|
+
t.string "name"
|
51
|
+
t.string "supplier"
|
52
|
+
t.integer "local_product_id"
|
53
|
+
t.integer "product_id"
|
54
|
+
t.datetime "created_at", null: false
|
55
|
+
t.datetime "updated_at", null: false
|
56
|
+
end
|
57
|
+
|
58
|
+
add_index "remote_products", ["local_product_id"], name: "index_remote_products_on_local_product_id"
|
59
|
+
|
60
|
+
create_table "stock_items", force: :cascade do |t|
|
61
|
+
t.integer "local_product_id"
|
62
|
+
t.integer "qty"
|
63
|
+
t.datetime "date"
|
64
|
+
t.datetime "created_at", null: false
|
65
|
+
t.datetime "updated_at", null: false
|
66
|
+
end
|
67
|
+
|
68
|
+
add_index "stock_items", ["local_product_id"], name: "index_stock_items_on_local_product_id"
|
69
|
+
|
70
|
+
end
|
@@ -2,5 +2,30 @@ module RawgentoModels
|
|
2
2
|
class LocalProduct < ActiveRecord::Base
|
3
3
|
has_one :remote_product
|
4
4
|
has_many :stock_items
|
5
|
+
|
6
|
+
default_scope { order("name ASC") }
|
7
|
+
|
8
|
+
scope :linked, -> {
|
9
|
+
joins("LEFT OUTER JOIN " +
|
10
|
+
" remote_products " +
|
11
|
+
" ON remote_products.local_product_id = local_products.id").where("remote_products.id IS NOT null")
|
12
|
+
}
|
13
|
+
# scope :with_photos, -> { joins(:photos).distinct }
|
14
|
+
|
15
|
+
scope :unlinked, -> {
|
16
|
+
joins("LEFT OUTER JOIN " +
|
17
|
+
" remote_products " +
|
18
|
+
" ON remote_products.local_product_id = local_products.id").where("remote_products.id IS null")
|
19
|
+
}
|
20
|
+
# City.includes(:photos).where(photos: { city_id: nil }) # slower
|
21
|
+
scope :supplied_by, ->(supplier_name) { where(supplier: supplier_name) }
|
22
|
+
|
23
|
+
def link_suggestions
|
24
|
+
guesses = []
|
25
|
+
guesses << RemoteProduct.supplied_by(self.supplier).where(name: self.name).to_a
|
26
|
+
guesses << RemoteProduct.supplied_by(self.supplier).where("lower(name) like ?",
|
27
|
+
"%#{self.name.downcase[0..self.name.size/2]}%").to_a
|
28
|
+
guesses.flatten
|
29
|
+
end
|
5
30
|
end
|
6
31
|
end
|
data/lib/rawgento_models.rb
CHANGED
@@ -5,6 +5,8 @@ require "rawgento_models/version"
|
|
5
5
|
require "rawgento_models/stock_item"
|
6
6
|
require "rawgento_models/local_product"
|
7
7
|
require "rawgento_models/remote_product"
|
8
|
+
require "rawgento_models/order"
|
9
|
+
require "rawgento_models/order_item"
|
8
10
|
|
9
11
|
require 'yaml'
|
10
12
|
require 'ostruct'
|
@@ -14,8 +16,10 @@ module RawgentoModels
|
|
14
16
|
MIGRATION_PATH = File.expand_path(File.join __dir__, '..', 'db', 'migrate')
|
15
17
|
ActiveRecordMigrations.configure {|c| c.migrations_paths = [MIGRATION_PATH] }
|
16
18
|
|
19
|
+
CONF_FILE = "db/config.yml"
|
20
|
+
|
17
21
|
# Reads config and wires up AR
|
18
|
-
def self.establish_connection(config_file_path=
|
22
|
+
def self.establish_connection(config_file_path=CONF_FILE)
|
19
23
|
config = OpenStruct.new YAML.load_file(config_file_path)
|
20
24
|
ActiveRecord::Base.establish_connection(config.default)
|
21
25
|
#ActiveRecord::Base.establish_connection({
|
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.
|
4
|
+
version: 0.0.4
|
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-
|
11
|
+
date: 2016-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -99,6 +99,8 @@ files:
|
|
99
99
|
- db/migrate/201601171700_create_base.rb
|
100
100
|
- db/migrate/201601201700_extend_product.rb
|
101
101
|
- db/migrate/201601221500_create_orders.rb
|
102
|
+
- db/migrate/201601251100_extend_order_items.rb
|
103
|
+
- db/schema.rb
|
102
104
|
- exe/rawgento_models
|
103
105
|
- lib/rawgento_models.rb
|
104
106
|
- lib/rawgento_models/local_product.rb
|