Skip to content

Commit

Permalink
Adapted order fax (though this is still a matter of debate)
Browse files Browse the repository at this point in the history
  • Loading branch information
lentschi committed Apr 23, 2022
1 parent 98f6bbf commit 4ecf7d4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
12 changes: 8 additions & 4 deletions app/documents/order_fax.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class OrderFax < OrderPdf
include ArticlesHelper

BATCH_SIZE = 250

def filename
Expand Down Expand Up @@ -59,14 +61,16 @@ def body
total = 0
data = [I18n.t('documents.order_fax.rows')]
each_order_article do |oa|
subtotal = oa.units_to_order * oa.price.unit_quantity * oa.price.price
price = oa.article.get_price(oa.price.supplier_order_unit)
subtotal = oa.units_to_order * price
total += subtotal
data << [oa.article.order_number,
oa.units_to_order,
oa.article.name,
oa.price.unit_quantity,
oa.article.unit,
number_to_currency(oa.price.price),
# TODO-article-units: Why should we show the supplier the group order unit quantity?:
oa.article.convert_quantity(1, oa.price.supplier_order_unit, oa.price.group_order_unit),
format_supplier_article_unit(oa.article),
number_to_currency(price),
number_to_currency(subtotal)]
end
data << [I18n.t('documents.order_fax.total'), nil, nil, nil, nil, nil, number_to_currency(total)]
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/price_calculation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_unit_ratio_quantity(unit)
self.article_unit_ratios.find_by_unit(unit).quantity
end

def get_unit_ratio(quantity, input_unit, output_unit)
def convert_quantity(quantity, input_unit, output_unit)
quantity / self.get_unit_ratio_quantity(input_unit) * self.get_unit_ratio_quantity(output_unit)
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/group_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def load_data
:used_tolerance => (goa ? goa.result(:tolerance) : 0),
:total_price => (goa ? goa.total_price : 0),
:missing_units => order_article.missing_units,
:ratio_group_order_unit_supplier_unit => order_article.article.get_unit_ratio(1, order_article.article.supplier_order_unit, order_article.article.group_order_unit),
:ratio_group_order_unit_supplier_unit => order_article.article.convert_quantity(1, order_article.article.supplier_order_unit, order_article.article.group_order_unit),
:quantity_available => (order.stockit? ? order_article.article.quantity_available : 0)
}
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/order_article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,12 @@ def update_global_price=(value)

# @return [Number] Units missing for the last +unit_quantity+ of the article.
def missing_units
unit_ratio = price.get_unit_ratio(1, price.supplier_order_unit, price.group_order_unit)
unit_ratio = price.convert_quantity(1, price.supplier_order_unit, price.group_order_unit)
_missing_units(unit_ratio, quantity, tolerance)
end

def missing_units_was
unit_ratio = price.get_unit_ratio(1, price.supplier_order_unit, price.group_order_unit)
unit_ratio = price.convert_quantity(1, price.supplier_order_unit, price.group_order_unit)
_missing_units(unit_ratio, quantity_was, tolerance_was)
end

Expand Down

0 comments on commit 4ecf7d4

Please sign in to comment.