Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Ostler, Leonard committed Feb 20, 2022
2 parents 979eebc + f371f70 commit 57cb7c1
Show file tree
Hide file tree
Showing 5 changed files with 11,222 additions and 49 deletions.
11 changes: 11 additions & 0 deletions app/models/article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class Article < ApplicationRecord
# @return [Array<Order>] Orders this article appears in.
has_many :orders, through: :order_articles

has_many :article_unit_conversions

# Replace numeric seperator with database format
localize_input_of :price, :tax, :deposit
# Get rid of unwanted whitespace. {Unit#new} may even bork on whitespace.
Expand Down Expand Up @@ -232,6 +234,15 @@ def mark_as_deleted
update_column :deleted_at, Time.now
end

def unit_quantity
first_conversion = article_unit_conversions.first
if first_conversion.nil?
'1'
else
first_conversion.amount
end
end

protected

# Checks if the article is in use before it will deleted
Expand Down
3 changes: 3 additions & 0 deletions app/models/article_unit_conversion.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ArticleUnitConversion < ApplicationRecord
belongs_to :article
end
Loading

0 comments on commit 57cb7c1

Please sign in to comment.