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