Created
February 21, 2018 11:01
-
-
Save cpfarher/bfde79dd9c3772575b03712c0a397110 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # app/admin/recipe.rb | |
| index do | |
| #... | |
| column "Peso1/Peso2" do |f| | |
| div status_tag "#{f.peso} kg." if f.peso | |
| setpoint_lines=[f.sum_setpoints] | |
| setpoint_lines<< ((setpoint_lines[0]!=f.peso_batch)? "error" : "ok") | |
| title_error="Error" if setpoint_lines[1]=="error" | |
| div status_tag "#{setpoint_lines[0]} kg.", setpoint_lines[1], title: title_error || "" unless setpoint_lines[0].blank? | |
| end | |
| column :tiempo_mezclado do |f| | |
| "#{f.tiempo_mezclado/60} min." if f.tiempo_mezclado.present? | |
| end | |
| #... | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # app/models/recipe.rb | |
| class Line < ApplicationRecord | |
| #... | |
| form do |f| | |
| f.inputs "Details" do | |
| f.input :recipe, :collection=> Recipe.collection_for_order_outs(f.try(:object).try(:recipe_id)) | |
| end | |
| f.actions | |
| end | |
| #... | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # app/models/recipe.rb | |
| # fail! | |
| class Recipe < ApplicationRecord | |
| has_many :lines, -> { where(:is_expedition => true, :is_internal=>[false, '0', nil]) } | |
| #... | |
| def self.collection_for_order_outs recipe_id=nil | |
| if !recipe_id.blank? | |
| selected_recipe=Recipe.unscoped.where(id:recipe_id).try(:first) | |
| end | |
| recipe_collections=Recipe.unscoped.select("distinct on (code_number) code_number, nombre, id, top_code").to_a | |
| recipe_collections<<selected_recipe unless selected_recipe.blank? | |
| recipe_collections.sort_by {|e| e[:nombre]}.map{|e| [e.to_order_out_string, e.try(:id)] } | |
| end | |
| #... | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # app/models/recipe.rb | |
| # OK | |
| class Recipe < ApplicationRecord | |
| #... | |
| def self.collection_for_order_outs recipe_id=nil | |
| if recipe_id.present? | |
| selected_recipe=Recipe.unscoped.where(id:recipe_id).try(:first) | |
| end | |
| recipe_collections=Recipe.unscoped.with_slot_plc.uniq{|x| x.code_number}.to_a | |
| recipe_collections<<selected_recipe unless selected_recipe.blank? | |
| recipe_collections.sort_by {|e| e[:nombre]}.collect{|e| [e.to_order_out_string, e.try(:id)] } | |
| end | |
| #... | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment