Skip to content

Commit

Permalink
Started with billing
Browse files Browse the repository at this point in the history
  • Loading branch information
lentschi committed Jun 12, 2022
1 parent 1b484f3 commit 12228da
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 28 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ group :development do
gem 'mailcatcher'
gem 'web-console'
gem 'listen'
gem 'byebug'

# Better error output
gem 'better_errors'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ GEM
bullet (7.0.1)
activesupport (>= 3.0.0)
uniform_notifier (~> 1.11)
byebug (11.1.3)
capybara (3.36.0)
addressable
matrix
Expand Down Expand Up @@ -577,6 +578,7 @@ DEPENDENCIES
bootsnap
bootstrap-datepicker-rails
bullet
byebug
capybara
connection_pool
daemons
Expand Down
2 changes: 2 additions & 0 deletions HACKATHON_TODOS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- articles form bugfixing (too many units in dropdowns, ...)
- investigate goa result content change after reducing received number for beer with ordered amount 59 and tolerance 1
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
web: bundle exec rails server --binding=0.0.0.0 --port=$PORT
web: bundle exec rails server --binding=0.0.0.0 --port=$PORT; tail -f log/development.log
worker: QUEUE=* bundle exec rake resque:work
mail: bundle exec rake foodsoft:reply_email_smtp_server
cron: supercronic crontab
16 changes: 10 additions & 6 deletions app/assets/javascripts/receive-order-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
this.updateDelta(e.target);
});

$(document).on('touchclick', '#order_articles .unlocker', () => this.unlockReceiveInputField());
$(document).on('touchclick', '#order_articles .unlocker', (e) => this.unlockReceiveInputField($(e.target)));

$(document).on('click', '#set_all_to_zero', () => {
$('tbody input').each((_, input) => {
Expand Down Expand Up @@ -37,7 +37,11 @@
return;
}

return field$.unitConversionField('getConverter').getUnitRatio(units, fromUnit, toUnit);
const converter = field$.unitConversionField('getConverter');
if (converter === undefined) {
return units;
}
return converter.getUnitRatio(units, fromUnit, toUnit);
}

convertToBillingUnit(field$) {
Expand Down Expand Up @@ -119,10 +123,10 @@
$(sel).val('').trigger('change');
}

unlockReceiveInputField() {
$('.units_received', $(this).closest('tr')).prop('disabled', false).focus();
$(this).closest('.input-prepend').prop('title', I18n.t('orders.edit_amount.field_unlocked_title'));
$(this).replaceWith('<i class="icon icon-warning-sign add-on"></i>');
unlockReceiveInputField(unlockButton$) {
$('.units_received', unlockButton$.closest('tr')).prop('disabled', false).focus();
unlockButton$.closest('.input-prepend').prop('title', I18n.t('orders.edit_amount.field_unlocked_title'));
unlockButton$.replaceWith('<i class="icon icon-warning-sign add-on"></i>');
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/order_articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def edit; end

def update
# begin
price_params = params.require(:article_price).permit(:id, :unit, :supplier_order_unit, :minimum_order_quantity, :billing_unit, :group_order_granularity, :group_order_unit, :price, :price_unit, :tax, :deposit, article_unit_ratios_attributes: [:sort, :quantity, :unit])
price_params = params.require(:article_price).permit(:id, :unit, :supplier_order_unit, :minimum_order_quantity, :billing_unit, :group_order_granularity, :group_order_unit, :price, :price_unit, :tax, :deposit, article_unit_ratios_attributes: [:sort, :quantity, :unit, :_destroy])
@order_article.update_article_and_price!(params[:order_article], params[:article], price_params)
# rescue
# render action: :edit
Expand Down
19 changes: 17 additions & 2 deletions app/helpers/orders_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ def units_history_line(order_article, options = {})
nil
else
units_info = []
price = order_article.price
[:units_to_order, :units_billed, :units_received].map do |unit|
if n = order_article.send(unit)
line = n.to_s + ' '
line += pkg_helper(order_article.price, options) + ' ' unless n == 0
converted_quantity = price.convert_quantity(n, price.supplier_order_unit, price.billing_unit.presence || price.supplier_order_unit)
line = converted_quantity.to_s + ' '
line += pkg_helper(price, options) + ' ' unless n == 0
line += OrderArticle.human_attribute_name("#{unit}_short", count: n)
units_info << line
end
Expand All @@ -41,6 +43,19 @@ def units_history_line(order_article, options = {})
end
end

def ordered_quantities_different_from_group_orders?(order_article, ordered_mark = "!", billed_mark = "?", received_mark = "?")
price = order_article.price
group_orders_sum_quantity = order_article.group_orders_sum[:quantity]
converted_quantity = price.convert_quantity(1, price.supplier_order_unit, price.group_order_unit)
if !order_article.units_received.nil?
(order_article.units_received * converted_quantity) == group_orders_sum_quantity ? false : received_mark
elsif !units_billed.nil?
(order_article.units_billed * converted_quantity) == group_orders_sum_quantity ? false : billed_mark
elsif !units_to_order.nil?
(order_article.units_to_order * converted_quantity) == group_orders_sum_quantity ? false : ordered_mark
end
end

# @param article [Article]
# @option options [String] :icon +false+ to hide the icon
# @option options [String] :plain +true+ to not use HTML (implies +icon+=+false+)
Expand Down
13 changes: 0 additions & 13 deletions app/models/order_article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,6 @@ def total_gross_price
units * price.convert_quantity(1, price.supplier_order_unit, price.group_order_unit) * price.gross_price
end

def ordered_quantities_different_from_group_orders?(ordered_mark = "!", billed_mark = "?", received_mark = "?")
converted_quantity = price.convert_quantity(1, price.supplier_order_unit, price.group_order_unit)
if not units_received.nil?
((units_received * converted_quantity) == group_orders_sum[:quantity]) ? false : received_mark
elsif not units_billed.nil?
((units_billed * converted_quantity) == group_orders_sum[:quantity]) ? false : billed_mark
elsif not units_to_order.nil?
((units_to_order * converted_quantity) == group_orders_sum[:quantity]) ? false : ordered_mark
else
nil # can happen in integration tests
end
end

# redistribute articles over ordergroups
# quantity Number of units to distribute
# surplus What to do when there are more articles than ordered quantity
Expand Down
8 changes: 4 additions & 4 deletions app/views/finance/balancing/_order_article.html.haml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
%td.closed.name
= link_to order_article.article.name, '#', 'data-toggle-this' => "#group_order_articles_#{order_article.id}"
%td= order_article.article.order_number
%td{title: units_history_line(order_article, :plain => true)}
= order_article.units
= pkg_helper order_article.article_price
- if s=order_article.ordered_quantities_different_from_group_orders?
%td{title: units_history_line(order_article, plain: true, unit: order_article.price.billing_unit)}
= order_article.price.convert_quantity(order_article.units, order_article.price.supplier_order_unit, order_article.price.billing_unit)
= pkg_helper order_article.article_price, unit: order_article.price.billing_unit
- if s=ordered_quantities_different_from_group_orders?(order_article)
%span{:style => "color:red;font-weight: bold"}= s
%td #{order_article.article.unit}
%td
Expand Down
2 changes: 1 addition & 1 deletion app/views/orders/_edit_amounts.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
popoverTemplate$: $('#unit_conversion_popover_content_template'),
useTargetUnitForStep: false
}));
$('table#order_articles').parents('form').receiveOrderForm({packageHelperIconOrAction: '#{j pkg_helper_icon}', newOrderArticlePath:'#{order_order_articles_path(@order)}'});
$('table#order_articles').parents('form').receiveOrderForm({packageHelperIcon: '#{j pkg_helper_icon}', newOrderArticlePath:'#{order_order_articles_path(@order)}'});
= render 'shared/js_templates/unit_conversion_popover_template'
%table#order_articles.ordered-articles.table.table-striped.stupidtable{style: 'margin-bottom: 0'}
%thead
Expand Down

0 comments on commit 12228da

Please sign in to comment.