API v1 group_order_articles endpoints
This commit is contained in:
parent
ed9192c47f
commit
e1d50e5b9c
11 changed files with 646 additions and 10 deletions
|
|
@ -21,6 +21,14 @@ class GroupOrder < ApplicationRecord
|
|||
|
||||
scope :ordered, -> { includes(:ordergroup).order('groups.name') }
|
||||
|
||||
def self.ransackable_attributes(auth_object = nil)
|
||||
%w(id price)
|
||||
end
|
||||
|
||||
def self.ransackable_associations(auth_object = nil)
|
||||
%w(order group_order_articles)
|
||||
end
|
||||
|
||||
# Generate some data for the javascript methods in ordering view
|
||||
def load_data
|
||||
data = {}
|
||||
|
|
|
|||
|
|
@ -5,16 +5,25 @@ class GroupOrderArticle < ApplicationRecord
|
|||
|
||||
belongs_to :group_order
|
||||
belongs_to :order_article
|
||||
has_many :group_order_article_quantities, :dependent => :destroy
|
||||
has_many :group_order_article_quantities, dependent: :destroy
|
||||
|
||||
validates_presence_of :group_order, :order_article
|
||||
validates_uniqueness_of :order_article_id, :scope => :group_order_id # just once an article per group order
|
||||
validate :check_order_not_closed # don't allow changes to closed (aka settled) orders
|
||||
validates :quantity, :tolerance, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
|
||||
|
||||
scope :ordered, -> { includes(:group_order => :ordergroup).order('groups.name') }
|
||||
|
||||
localize_input_of :result
|
||||
|
||||
def self.ransackable_attributes(auth_object = nil)
|
||||
%w(id quantity tolerance result)
|
||||
end
|
||||
|
||||
def self.ransackable_associations(auth_object = nil)
|
||||
%w(order_article group_order)
|
||||
end
|
||||
|
||||
# Setter used in group_order_article#new
|
||||
# We have to create an group_order, if the ordergroup wasn't involved in the order yet
|
||||
def ordergroup_id=(id)
|
||||
|
|
@ -86,7 +95,7 @@ class GroupOrderArticle < ApplicationRecord
|
|||
|
||||
# Check if something went terribly wrong and quantites have not been adjusted as desired.
|
||||
if (self.quantity != quantity || self.tolerance != tolerance)
|
||||
raise 'Invalid state: unable to update GroupOrderArticle/-Quantities to desired quantities!'
|
||||
raise ActiveRecord::RecordNotSaved.new('Unable to update GroupOrderArticle/-Quantities to desired quantities!', self)
|
||||
end
|
||||
|
||||
# Remove zero-only items.
|
||||
|
|
|
|||
|
|
@ -30,9 +30,9 @@ class Order < ApplicationRecord
|
|||
|
||||
# Finders
|
||||
scope :started, -> { where('starts <= ?', Time.now) }
|
||||
scope :closed, -> { where(state: 'closed').order('ends DESC') }
|
||||
scope :stockit, -> { where(supplier_id: nil).order('ends DESC') }
|
||||
scope :recent, -> { order('starts DESC').limit(10) }
|
||||
scope :closed, -> { where(state: 'closed').order(ends: :desc) }
|
||||
scope :stockit, -> { where(supplier_id: nil).order(ends: :desc) }
|
||||
scope :recent, -> { order(starts: :desc).limit(10) }
|
||||
scope :stock_group_order, -> { group_orders.where(ordergroup_id: nil).first }
|
||||
scope :with_invoice, -> { where.not(invoice: nil) }
|
||||
|
||||
|
|
@ -42,9 +42,9 @@ class Order < ApplicationRecord
|
|||
# So orders can
|
||||
# 1. ...only transition in one direction (e.g. an order that has been `finished` currently cannot be reopened)
|
||||
# 2. ...be set to `closed` when having the `finished` state. (`received` is optional)
|
||||
scope :open, -> { where(state: 'open').order('ends DESC') }
|
||||
scope :finished, -> { where(state: %w[finished received closed]).order('ends DESC') }
|
||||
scope :finished_not_closed, -> { where(state: %w[finished received]).order('ends DESC') }
|
||||
scope :open, -> { where(state: 'open').order(ends: :desc) }
|
||||
scope :finished, -> { where(state: %w[finished received closed]).order(ends: :desc) }
|
||||
scope :finished_not_closed, -> { where(state: %w[finished received]).order(ends: :desc) }
|
||||
|
||||
# Allow separate inputs for date and time
|
||||
# with workaround for https://github.com/einzige/date_time_attribute/issues/14
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue