Ruby on Rails
Friday, October 12, 2018
Have not found in settings for shipping, since it just a status. I would like it to automatic archive if it was shipped after 3 yeaars
On Thursday, August 16, 2018 at 12:55:47 PM UTC-5, Stephanie_Snowflake wrote:
-- On Thursday, August 16, 2018 at 12:55:47 PM UTC-5, Stephanie_Snowflake wrote:
I'm looking for a way to split a group of data (ex. Sales Orders)Currently split (In Progress, On Hold, Shipped, Cancelled)I would like to split Shipped into twoShipped (before 1 year)Archive Shipped (after 1 year)I believe I should add the following line to sales_orders.html.erb<%= sidebar_link_to(:status, 'archive_shipped') {"Archive"} %>and add the following lines in the sales_order.rbwhen "recent_shipped"active.shipped.shipped_date_after(1.year.ago) when "achive_shipped"active.shipped.shipped_date_before(1.year.ago) But I'm not sure where to place this in the file, since I didn't have all the phases (in progress, on hold, shipped, and cancelled) labeled out like :PhaseI didn't write this application, so I'm trying to make changes that have been requested.Please see sales_order.rb belowclass SalesOrder < ActiveRecord::Baseinclude Filterableinclude Tenancyenum status: [ :in_progress, :on_hold, :cancelled, :shipped ]has_many :line_items, dependent: :destroyhas_many :filmsaccepts_nested_attributes_for :line_items, allow_destroy: truevalidates :code, presence: true,uniqueness: { case_sensitive: false,scope: :tenant_code }validates :ship_date, presence: true, if: Proc.new { |o| o.shipped? }validate :ship_date_after_release?validates :release_date, presence: truevalidates :due_date, presence: trueinclude PgSearchpg_search_scope :search, against: [:code, :customer, :ship_to, :note],:using => { tsearch: { prefix: true } }scope :order_by, ->(col, dir) { order("#{col} #{dir}") }scope :status, ->(status) { where(status: statuses[status]) }scope :due_date_equals, ->(date) { where(due_date: date) }scope :type, ->(prefix) { where('code ILIKE ?', prefix) }scope :ship_date_before, ->(date) { where("ship_date <= ?", date) }scope :ship_date_after, ->(date) { where("ship_date >= ?", date) }scope :text_search, ->(query) { reorder('').search(query) }scope :code_like, ->(code) { where('code ILIKE ?', code.gsub('*', '%')) }scope :status_not, ->(status) { where("status <> ?", statuses[status]) }def lead_days(ship_date - release_date).to_ienddef total_quantityline_items.total_quantityenddef assigned_film_count(phase = nil)assigned = phase ? films.phase(phase) : filmsassigned.total_order_fill_count enddef assigned_film_percentagereturn 0 if total_quantity == 0100*assigned_film_count/total_quantity enddef total_custom_arealine_items.total_areaenddef total_assigned_areafilms.map{ |f| f.area }.sumenddef past_due?Date.current > due_dateenddef shipped_late?ship_date ? ship_date > due_date : falseenddef utilization100*total_custom_area/total_assigned_area if total_custom_area && total_assigned_area && total_assigned_area > 0 enddef self.avg_utilization100*total_custom_area/total_assigned_area if total_custom_area && total_assigned_area && total_assigned_area > 0 enddef self.total_custom_arealine_items.total_areaenddef self.total_assigned_areafilms.map{ |f| f.area }.sumenddef self.line_itemsLineItem.where(sales_order_id: all.map(&:id))enddef self.filmsFilm.where(sales_order_id: all.map(&:id))enddef self.to_csv(options = {})CSV.generate(options) do |csv|csv << %w(SO# Customer Released Due Ship-to Status Shipped Note)all.each do |o|csv << [o.code, o.customer, o.release_date, o.due_date, o.ship_to, o.status, o.ship_date, o.note]endendendprivatedef ship_date_after_release?if ship_date.present? && ship_date < release_dateerrors.add(:base, "Must be shipped after release")endendend
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/0f1d95bb-d43d-498a-b37d-f9d97f510d82%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment