API v1 order_articles endpoints

This commit is contained in:
wvengen 2018-10-13 16:21:37 +02:00 committed by wvengen
parent 127ae83f04
commit ed9192c47f
14 changed files with 323 additions and 4 deletions

View file

@ -43,6 +43,12 @@ class Article < ApplicationRecord
# @!attribute article_prices
# @return [Array<ArticlePrice>] Price history (current price first).
has_many :article_prices, -> { order("created_at DESC") }
# @!attribute order_articles
# @return [Array<OrderArticle>] Order articles for this article.
has_many :order_articles
# @!attribute order
# @return [Array<Order>] Orders this article appears in.
has_many :orders, through: :order_articles
# Replace numeric seperator with database format
localize_input_of :price, :tax, :deposit
@ -68,6 +74,14 @@ class Article < ApplicationRecord
before_save :update_price_history
before_destroy :check_article_in_use
def self.ransackable_attributes(auth_object = nil)
%w(id name supplier_id article_category_id unit note manufacturer origin unit_quantity order_number)
end
def self.ransackable_associations(auth_object = nil)
%w(article_category supplier order_articles orders)
end
# Returns true if article has been updated at least 2 days ago
def recently_updated
updated_at > 2.days.ago

View file

@ -20,6 +20,14 @@ class OrderArticle < ApplicationRecord
before_create :init_from_balancing
after_destroy :update_ordergroup_prices
def self.ransackable_attributes(auth_object = nil)
%w(id order_id article_id quantity tolerance units_to_order)
end
def self.ransackable_associations(auth_object = nil)
%w(order article)
end
# This method returns either the ArticlePrice or the Article
# The first will be set, when the the order is finished
def price

View file

@ -13,7 +13,8 @@ class Ordergroup < Group
has_many :financial_transactions
has_many :group_orders
has_many :orders, :through => :group_orders
has_many :orders, through: :group_orders
has_many :group_order_articles, through: :group_orders
validates_numericality_of :account_balance, :message => I18n.t('ordergroups.model.invalid_balance')
validate :uniqueness_of_name, :uniqueness_of_members

View file

@ -9,6 +9,16 @@ class StockArticle < Article
before_destroy :check_quantity
ransack_alias :quantity_available, :quantity # in-line with {StockArticleSerializer}
def self.ransackable_attributes(auth_object = nil)
super(auth_object) - %w(supplier_id) + %w(quantity)
end
def self.ransackable_associations(auth_object = nil)
super(auth_object) - %w(supplier)
end
# Update the quantity of items in stock
def update_quantity!
update_attribute :quantity, stock_changes.collect(&:quantity).sum