Skip to content

Commit

Permalink
Allow plugins to override some document prices
Browse files Browse the repository at this point in the history
  • Loading branch information
wvengen committed Oct 20, 2016
1 parent 1ba84f0 commit c92cf69
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
13 changes: 12 additions & 1 deletion app/documents/order_by_groups.rb
Expand Up @@ -26,7 +26,7 @@ def body
dimrows = []

each_group_order_article_for(group_order) do |goa|
price = goa.order_article.price.fc_price
price = order_article_price(goa.order_article)
sub_total = price * goa.result
total += sub_total
rows << [goa.order_article.article.name,
Expand Down Expand Up @@ -73,6 +73,17 @@ def body

private

# Return price for order_article.
#
# This is a separate method so that plugins can override it.
#
# @param article [OrderArticle]
# @return [Number] Price to show
# @see https://github.com/foodcoops/foodsoft/issues/445
def order_article_price(order_article)
order_article.price.fc_price
end

def group_orders
order.group_orders.ordered.
joins(:ordergroup).order('groups.name').
Expand Down
15 changes: 14 additions & 1 deletion app/documents/order_matrix.rb
Expand Up @@ -26,7 +26,7 @@ def body
order_articles_data << [a.article.name,
a.article.unit,
a.price.unit_quantity,
number_with_precision(a.price.fc_price, precision: 2),
number_with_precision(article_price(a), precision: 2),
a.units]
end

Expand Down Expand Up @@ -84,4 +84,17 @@ def body
end
end

private

# Return price for article.
#
# This is a separate method so that plugins can override it.
#
# @param article [Article]
# @return [Number] Price to show
# @see https://github.com/foodcoops/foodsoft/issues/445
def article_price(article)
article.price.fc_price
end

end

0 comments on commit c92cf69

Please sign in to comment.