Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New receive screen (ready) #222

Merged
merged 85 commits into from
Jan 20, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
bd1b932
add receive screen, quantities for model, redistribution
wvengen Nov 25, 2013
9c340ec
more clarity whether a number is number units or boxes
wvengen Nov 25, 2013
9990e05
fix i18n
wvengen Nov 25, 2013
853e8ba
add package images [ci skip]
wvengen Nov 25, 2013
9cb9bf6
focus newly added input in receive
wvengen Nov 26, 2013
beabe22
simplify model
wvengen Nov 26, 2013
2d99141
only allow to add articles not already present in receive
wvengen Nov 26, 2013
c900cf4
make product redistribution work!
wvengen Nov 26, 2013
a0c6cf8
fix warning without text
wvengen Dec 18, 2013
2b511ee
Merge branch 'master' into fresh-flow
wvengen Dec 18, 2013
1ab09b4
fix articles_for_select2 helper
wvengen Dec 18, 2013
94b4454
add receive to order screen, and distinguish between finished and clo…
wvengen Dec 18, 2013
d299fa4
move receive screen to orders
wvengen Dec 18, 2013
82d1c41
update show order
wvengen Dec 18, 2013
4fede30
hide invoice columns until implemented
wvengen Dec 18, 2013
873a1ff
update texts
wvengen Dec 18, 2013
84fe791
update balancing screen
wvengen Dec 18, 2013
88f2dad
language change
wvengen Dec 18, 2013
7f813f2
fix order add_article
wvengen Dec 18, 2013
3d511ea
only show receive in finance when access to ordering
wvengen Dec 18, 2013
68c4aff
better disabled button
wvengen Dec 18, 2013
54e9847
remove unused helper [ci skip]
wvengen Dec 18, 2013
bb331f9
fix units_to_order display [ci skip]
wvengen Dec 18, 2013
aa6041d
show all articles in receive screen (not just of this order)
wvengen Dec 21, 2013
41ea9ed
hide receive screen for stock orders
wvengen Dec 21, 2013
a28c603
fix receive exception when input is set to nil
wvengen Dec 21, 2013
03bb83e
show different warning signs for mismatch with ordered and received
wvengen Dec 23, 2013
f5bd7a4
update balancing order article edit screen to support received units
wvengen Dec 23, 2013
27a73be
Merge remote-tracking branch 'foodcoops/master' into feature-receive
wvengen Jan 2, 2014
81dfe81
Apply publish/subscribe for OrderArticle#update
Dec 30, 2013
cf1e68f
Allow to edit OrderArticle in Order#receive form
Dec 30, 2013
9ed906f
Correct haml comment from '#' to '-#'
Dec 31, 2013
baa5f16
Free order_article resource from finance namespace; also unlock for r…
Dec 31, 2013
01264bc
Clean up OrderArticle#new form and related stuff
Dec 31, 2013
5349ee1
Offer _undeleted_ StockArticles for new OrderArticle only
Dec 31, 2013
59c118a
Apply publish/subscribe for OrderArticle#create
Dec 31, 2013
033aa90
Use OrderArticle#create in receive form instead of Order#add_article
Dec 31, 2013
a384532
Revert some changes of 20adce8a4e2d32548e7d7016dace250dd3e2eb9b
Jan 1, 2014
8e52fca
Do not set quantity of newly created OrderArticles to 1
Jan 1, 2014
dd138da
Change comment according to 9d61e2e61569159489098eda1bd6c30d7322ce76
Jan 1, 2014
a439f26
ui design update
wvengen Jan 2, 2014
7aae7f4
Add result_computed to GroupOrderArticle
wvengen Jan 3, 2014
98f59a3
Readonly receive input if GroupOrderArticle result has manually been …
wvengen Jan 3, 2014
2ec3d38
Set readonly property with javascript by .prop instead of .attr
Jan 2, 2014
0af8a06
Fix calculation of OrderArticle.total_price and .total_gross_price
Jan 2, 2014
f230d39
Merge price columns in receive form into one
Jan 2, 2014
5ead0fb
show correct price
wvengen Jan 3, 2014
f1ae272
fix unit quantity display after ajax update
wvengen Jan 3, 2014
014a62a
use disabled property for input and fix style
wvengen Jan 3, 2014
4c9e84e
change layout of receive unlock
wvengen Jan 3, 2014
9219d09
ui update for packages display
wvengen Jan 3, 2014
ebe2966
fix migration, complements 7aae7f4d5564cdf6e7e7bdd51657b560ad8f8b8e
wvengen Jan 3, 2014
438de97
fix non-closed order display
wvengen Jan 3, 2014
1a5dc3e
consider group_order_article without result not manually changed
wvengen Jan 3, 2014
1334297
old price display tweaks
wvengen Jan 3, 2014
b800da9
use helper in ajax update too
wvengen Jan 3, 2014
aa57cee
do not show units fields in receive edit order article screen
wvengen Jan 3, 2014
a8e604c
When receiving: hide OrderArticle unit fields also after failed valid…
Jan 4, 2014
8479678
Improve unlock button for receiving OrderArticles manually adjusted
Jan 3, 2014
d7c771d
Continue I18n of receive screen
Jan 6, 2014
563993f
Complete I18n of current receive screen
Jan 7, 2014
d01d1bc
add integration tests for receive
wvengen Jan 8, 2014
ccdb1e8
Merge remote-tracking branch 'foodcoop-rostock/feature-receive-i18n' …
wvengen Jan 8, 2014
6e60f94
small receive-related i18n updates
wvengen Jan 8, 2014
8f14ab3
cleanup and expand receive integration test
wvengen Jan 8, 2014
ce17bf3
complete and improve receive i18n
wvengen Jan 8, 2014
d1c3c83
use plural in table headings by default
wvengen Jan 8, 2014
65e79d7
small receive usability changes
wvengen Jan 8, 2014
b331d9a
better css responsiveness [ci skip]
wvengen Jan 8, 2014
5a7c9b8
fix receive js for document updates [ci skip]
wvengen Jan 9, 2014
56bd527
keep white input background with package class [ci skip]
wvengen Jan 9, 2014
90c81de
update receive delta column + responsive css
wvengen Jan 9, 2014
124341c
receive helper and i18n cleanup
wvengen Jan 9, 2014
bea2706
fix receive dynamic update (complements 90c81de872b0500325dfead20c579…
wvengen Jan 9, 2014
2b97ca0
i18n oops
wvengen Jan 9, 2014
dcb17e0
do not show article hint in order view after all, since "old price" is
wvengen Jan 9, 2014
0b4cfde
put footer below body, now that is allowed in html5
wvengen Jan 9, 2014
b30b424
Merge branch 'master' into feature-receive
wvengen Jan 9, 2014
9db8cb7
Synchronize German and English locales
Jan 10, 2014
c0dfb88
Merge pull request #6 from foodcoop-rostock/feature-receive-en-de
wvengen Jan 11, 2014
cb3e2f7
Merge branch 'master' into feature-receive
wvengen Jan 11, 2014
45e529b
revert i18n attributes pluralisation
wvengen Jan 11, 2014
3b2d50b
make receive delta work when unit_quantity changes
wvengen Jan 13, 2014
8760d87
fix receive notice
wvengen Jan 13, 2014
bab28d2
i18n update
wvengen Jan 13, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added app/assets/images/package-bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/package.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ $(function() {
return false;
});

// Disable action of disabled buttons
$(document).on('click', 'a.disabled', function() {
return false;
});

// Show and hide loader on ajax callbacks
$('*[data-remote]').bind('ajax:beforeSend', function() {
$('#loader').show();
Expand Down
103 changes: 93 additions & 10 deletions app/assets/stylesheets/bootstrap_and_overrides.css.less
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,19 @@ body {
// Example:
// @linkColor: #ff0000;

// Custom styles

// main ui colours
@mainRedColor: #ED0606;

// article status
@articleUsedColor: green;
@articleUnusedColor: red;
@articleUnavailColor: #999;
@articleUpdatedColor: #468847;

// dim colors by this amount when the information is less important
@nonessentialDim: 35%;


// Fix empty dd tags in horizontal dl, see https://github.com/twitter/bootstrap/issues/4062
.dl-horizontal {
Expand All @@ -39,7 +51,8 @@ body {

// Do not use additional margin for input in table
.form-horizontal .control-group.control-group-intable,
.form-horizontal .controls.controls-intable {
.form-horizontal .controls.controls-intable,
.input-prepend.intable {
margin: 0;
}

Expand All @@ -53,7 +66,6 @@ body {
margin-bottom: 0;
}

@mainRedColor: #ED0606;

.logo {
margin: 10px 0 0 30px;
Expand Down Expand Up @@ -134,11 +146,11 @@ table {
}

// ordering
span.used {
color: green;
.used {
color: @articleUsedColor;
}
span.unused {
color: red;
.unused {
color: @articleUnusedColor;
}

#order-footer, .article-info {
Expand Down Expand Up @@ -202,11 +214,11 @@ tr.order-article:hover .article-info {
// ********* Articles

tr.just-updated {
color: #468847;
color: @articleUpdatedColor;
}

tr.unavailable {
color: #999;
color: @articleUnavailColor;
}

// articles edit all
Expand All @@ -216,6 +228,16 @@ tr.unavailable {
}
}

// editable article list can be more compact
.ordered-articles input {
margin-bottom: 0;
}

// allow content to appear without sudden table change (receive)
.units_delta {
min-width: 3.5em;
}

// ********* Tweaks & fixes

// need more space for supplier&order information (in German, at least)
Expand All @@ -242,11 +264,60 @@ tr.unavailable {
}
}

// it's a bit distracting
.icon-asterisk {
font-size: 80%;
vertical-align: middle;
padding-bottom: 0.4ex;
}

// allow buttons as input add-on (with proper height)
.input-append button.add-on {
height: inherit;
}

// inline form elements
.inline {
display: inline;
}

// show package icon after amount of wholesale units
.package-image (@align) {
background-image: url(package-bg.png);
background-repeat: no-repeat;
background-position: @align center;
}
input.package {
.package-image(right);
// disabled and readonly definitions though
&[disabled], &[readonly] {
background-color: @inputDisabledBackground;
}
}
i.package {
.package-image(left);
min-width: 18px;
min-height: 18px;
vertical-align: baseline;
font-style: normal;
padding-left: 20px;
@media (max-width: 979px) { padding-left: 0; }
}
i.package.icon-only {
padding-left: 6px;
background-position: right;
display: inline-block;
}
.package { color: tint(@textColor, @nonessentialDim); }
.used .package { color: tint(@articleUsedColor, @nonessentialDim); }
.unused .package { color: tint(@articleUnusedColor, @nonessentialDim); }
.unavailable .package { color: @articleUnavailColor; }

// very small inputs - need !important for responsive selectors
.input-nano {
width: 30px !important;
}

// get rid of extra space on bottom of dialog with form
.modal form {
margin: 0;
Expand Down Expand Up @@ -281,10 +352,22 @@ tr.unavailable {
float: none;
}
}
// allow to add a hint for the whole line
> .help-block {
clear: both;
margin-left: 180px;
position: relative;
top: -2.5ex;
}
}
}
// allow to have indicator text instead of input with same markup
.control-text {
margin-top: 5px;
}


// unlock button same size as warning sign
.input-prepend button.unlocker {
padding-right: 6px;
padding-left: 7px;
}
5 changes: 5 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def authenticate(role = 'any')
when "article_meta" then current_user.role_article_meta?
when "suppliers" then current_user.role_suppliers?
when "orders" then current_user.role_orders?
when "finance_or_orders" then (current_user.role_finance? || current_user.role_orders?)
when "any" then true # no role required
else false # any unknown role will always fail
end
Expand Down Expand Up @@ -78,6 +79,10 @@ def authenticate_orders
authenticate('orders')
end

def authenticate_finance_or_orders
authenticate('finance_or_orders')
end

# checks if the current_user is member of given group.
# if fails the user will redirected to startpage
def authenticate_membership_or_admin(group_id = params[:id])
Expand Down
12 changes: 12 additions & 0 deletions app/controllers/finance/balancing_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ def new

render layout: false if request.xhr?
end

def new_on_order_article_create # See publish/subscribe design pattern in /doc.
@order_article = OrderArticle.find(params[:order_article_id])

render :layout => false
end

def new_on_order_article_update # See publish/subscribe design pattern in /doc.
@order_article = OrderArticle.find(params[:order_article_id])

render :layout => false
end

def update_summary
@order = Order.find(params[:id])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
class Finance::OrderArticlesController < ApplicationController
class OrderArticlesController < ApplicationController

before_filter :authenticate_finance
before_filter :authenticate_finance_or_orders

layout false # We only use this controller to serve js snippets, no need for layout rendering

def new
@order = Order.find(params[:order_id])
@order_article = @order.order_articles.build
@order_article = @order.order_articles.build(params[:order_article])
end

def create
@order = Order.find(params[:order_id])
# The article may with zero units ordered - in that case find and set amount to nonzero.
# The article may be ordered with zero units - in that case do not complain.
# If order_article is ordered and a new order_article is created, an error message will be
# given mentioning that the article already exists, which is desired.
@order_article = @order.order_articles.where(:article_id => params[:order_article][:article_id]).first
if @order_article and @order_article.units_to_order == 0
@order_article.units_to_order = 1
else
unless (@order_article and @order_article.units_to_order == 0)
@order_article = @order.order_articles.build(params[:order_article])
end
unless @order_article.save
render action: :new
end
@order_article.save!
rescue
render action: :new
end

def edit
Expand Down
70 changes: 68 additions & 2 deletions app/controllers/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class OrdersController < ApplicationController

# List orders
def index
@open_orders = Order.open
@open_orders = Order.open.includes(:supplier)
@finished_orders = Order.finished_not_closed.includes(:supplier)
@per_page = 15
if params['sort']
sort = case params['sort']
Expand All @@ -20,7 +21,7 @@ def index
else
sort = "ends DESC"
end
@orders = Order.page(params[:page]).per(@per_page).order(sort).where("state != 'open'").includes(:supplier)
@orders = Order.closed.page(params[:page]).per(@per_page).includes(:supplier).order(sort)
end

# Gives a view for the results to a specific order
Expand Down Expand Up @@ -105,6 +106,29 @@ def finish
redirect_to orders_url, alert: I18n.t('errors.general_msg', :msg => error.message)
end

def receive
@order = Order.find(params[:id])
unless request.post?
@order_articles = @order.order_articles.ordered.includes(:article)
else
s = update_order_amounts
flash[:notice] = (s ? I18n.t('orders.receive.notice', :msg => s) : I18n.t('orders.receive.notice_none'))
redirect_to @order
end
end

def receive_on_order_article_create # See publish/subscribe design pattern in /doc.
@order_article = OrderArticle.find(params[:order_article_id])

render :layout => false
end

def receive_on_order_article_update # See publish/subscribe design pattern in /doc.
@order_article = OrderArticle.find(params[:order_article_id])

render :layout => false
end

protected

# Renders the fax-text-file
Expand All @@ -131,4 +155,46 @@ def text_fax_template
end
text
end

def update_order_amounts
return if not params[:order_articles]
# where to leave remainder during redistribution
rest_to = []
rest_to << :tolerance if params[:rest_to_tolerance]
rest_to << :stock if params[:rest_to_stock]
rest_to << nil
# count what happens to the articles:
# changed, rest_to_tolerance, rest_to_stock, left_over
counts = [0] * 4
cunits = [0] * 4
OrderArticle.transaction do
params[:order_articles].each do |oa_id, oa_params|
unless oa_params.blank?
oa = OrderArticle.find(oa_id)
# update attributes; don't use update_attribute because it calls save
# which makes received_changed? not work anymore
oa.attributes = oa_params
if oa.units_received_changed?
counts[0] += 1
unless oa.units_received.blank?
cunits[0] += oa.units_received * oa.article.unit_quantity
oacounts = oa.redistribute oa.units_received * oa.price.unit_quantity, rest_to
oacounts.each_with_index {|c,i| cunits[i+1]+=c; counts[i+1]+=1 if c>0 }
end
end
oa.save!
end
end
end
return nil if counts[0] == 0
notice = []
notice << I18n.t('orders.update_order_amounts.msg1', count: counts[0], units: cunits[0])
notice << I18n.t('orders.update_order_amounts.msg2', count: counts[1], units: cunits[1]) if params[:rest_to_tolerance]
notice << I18n.t('orders.update_order_amounts.msg3', count: counts[2], units: cunits[2]) if params[:rest_to_stock]
if counts[3]>0 or cunits[3]>0
notice << I18n.t('orders.update_order_amounts.msg4', count: counts[3], units: cunits[3])
end
notice.join(', ')
end

end
4 changes: 2 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ def sort_link_helper(text, key, options = {})
# heading, with an abbreviation title of 'foo'.
# Other options are passed through to I18n.
def heading_helper(model, attribute, options = {})
i18nopts = options.select {|a| !['short'].include?(a) }
i18nopts = options.select {|a| !['short'].include?(a) }.merge({count: 2})
s = model.human_attribute_name(attribute, i18nopts)
if options[:short]
sshort = model.human_attribute_name("#{attribute}_short".to_sym, options.merge({fallback: true, default: ''}))
sshort = model.human_attribute_name("#{attribute}_short".to_sym, options.merge({fallback: true, default: '', count: 2}))
s = raw "<abbr title='#{s}'>#{sshort}</abbr>" unless sshort.blank?
end
s
Expand Down
13 changes: 9 additions & 4 deletions app/helpers/deliveries_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ def link_to_invoice(delivery)
end
end

def articles_for_select2(supplier)
supplier.articles.undeleted.reorder('articles.name ASC').map {|a| {:id => a.id, :text => "#{a.name} (#{number_to_currency a.price}/#{a.unit})"} }
def articles_for_select2(articles, except = [], &block)
articles = articles.reorder('articles.name ASC')
articles.reject! {|a| not except.index(a.id).nil? } if except
block_given? or block = Proc.new {|a| "#{a.name} (#{number_to_currency a.price}/#{a.unit})" }
articles.map do |a|
{:id => a.id, :text => block.call(a)}
end.unshift({:id => '', :text => ''})
end

def stock_articles_for_table(supplier)
supplier.stock_articles.undeleted.reorder('articles.name ASC')
def articles_for_table(articles)
articles.undeleted.reorder('articles.name ASC')
end

def stock_change_remove_link(stock_change_form)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Finance::OrderArticlesHelper
module OrderArticlesHelper

def new_order_articles_collection
if @order.stockit?
Expand Down
Loading