Class: StockitController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- StockitController
- Defined in:
- app/controllers/stockit_controller.rb
Instance Method Summary collapse
-
#articles_search ⇒ Object
TODO: Fix this!!.
-
#copy ⇒ Object
(2) StockArticle as template.
- #create ⇒ Object
-
#derive ⇒ Object
(3) non-stock Article as template.
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
-
#index_on_stock_article_create ⇒ Object
See publish/subscribe design pattern in /doc.
-
#index_on_stock_article_update ⇒ Object
See publish/subscribe design pattern in /doc.
-
#new ⇒ Object
three possibilites to fill a new_stock_article form (1) start from blank or use params.
- #show ⇒ Object
-
#show_on_stock_article_update ⇒ Object
See publish/subscribe design pattern in /doc.
- #update ⇒ Object
Methods inherited from ApplicationController
Methods included from PathHelper
#finance_group_transactions_path
Instance Method Details
#articles_search ⇒ Object
TODO: Fix this!!
96 97 98 99 |
# File 'app/controllers/stockit_controller.rb', line 96 def articles_search @articles = Article.not_in_stock.limit(8).where('name LIKE ?', "%#{params[:term]}%") render json: @articles.map(&:name) end |
#copy ⇒ Object
(2) StockArticle as template
35 36 37 38 39 40 41 |
# File 'app/controllers/stockit_controller.rb', line 35 def copy stock_article = StockArticle.find(params[:stock_article_id]) @stock_article = stock_article.dup @stock_article.latest_article_version = stock_article.latest_article_version.duplicate_including_article_unit_ratios render layout: false end |
#create ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/controllers/stockit_controller.rb', line 56 def create valid = false StockArticle.transaction do @stock_article = StockArticle.create(quantity: 0, supplier_id: @supplier_id) @stock_article.attributes = { latest_article_version_attributes: params[:article_version] } raise ActiveRecord::Rollback unless @stock_article.valid? valid = @stock_article.save end if valid render layout: false else load_article_units(@stock_article.current_article_units) render action: 'new', layout: false end end |
#derive ⇒ Object
(3) non-stock Article as template
44 45 46 47 48 49 50 |
# File 'app/controllers/stockit_controller.rb', line 44 def derive article = Article.find(params[:old_article_id]) @stock_article = article.becomes(StockArticle).dup @stock_article.latest_article_version = article.latest_article_version.duplicate_including_article_unit_ratios render layout: false end |
#destroy ⇒ Object
87 88 89 90 91 92 93 |
# File 'app/controllers/stockit_controller.rb', line 87 def destroy @stock_article.mark_as_deleted render layout: false rescue StandardError => e render partial: 'destroy_fail', layout: false, locals: { fail_msg: I18n.t('errors.general_msg', msg: e.) } end |
#edit ⇒ Object
52 53 54 |
# File 'app/controllers/stockit_controller.rb', line 52 def edit render layout: false end |
#index ⇒ Object
9 10 11 |
# File 'app/controllers/stockit_controller.rb', line 9 def index @stock_articles = StockArticle.with_latest_versions_and_categories.joins(:supplier).order('suppliers.name, article_categories.name, article_versions.name').undeleted end |
#index_on_stock_article_create ⇒ Object
See publish/subscribe design pattern in /doc.
13 14 15 |
# File 'app/controllers/stockit_controller.rb', line 13 def index_on_stock_article_create # See publish/subscribe design pattern in /doc. render layout: false end |
#index_on_stock_article_update ⇒ Object
See publish/subscribe design pattern in /doc.
17 18 19 |
# File 'app/controllers/stockit_controller.rb', line 17 def index_on_stock_article_update # See publish/subscribe design pattern in /doc. render layout: false end |
#new ⇒ Object
three possibilites to fill a new_stock_article form (1) start from blank or use params
27 28 29 30 31 32 |
# File 'app/controllers/stockit_controller.rb', line 27 def new @stock_article = StockArticle.new(params[:stock_article]) @stock_article.latest_article_version = ArticleVersion.new render layout: false end |
#show ⇒ Object
21 22 23 |
# File 'app/controllers/stockit_controller.rb', line 21 def show @stock_changes = @stock_article.stock_changes.order('stock_changes.created_at DESC') end |
#show_on_stock_article_update ⇒ Object
See publish/subscribe design pattern in /doc.
83 84 85 |
# File 'app/controllers/stockit_controller.rb', line 83 def show_on_stock_article_update # See publish/subscribe design pattern in /doc. render layout: false end |
#update ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'app/controllers/stockit_controller.rb', line 74 def update article_version_attributes = params[:article_version] @stock_article.update!(supplier_id: @supplier_id, latest_article_version_attributes: article_version_attributes) render layout: false rescue ActiveRecord::RecordInvalid render action: 'edit', layout: false end |