Merge latest changes in master of http://github.com/foodcoops/foodsoft

This commit is contained in:
Julius 2013-06-26 20:23:11 +02:00
commit d0ccf07bc5
20 changed files with 139 additions and 125 deletions

View File

@ -11,6 +11,19 @@
//= require_self
//= require ordering
// allow touch devices to work on click events
// http://stackoverflow.com/a/16221066
$.fn.extend({ _on: (function(){ return $.fn.on; })() });
$.fn.extend({
on: (function(){
var isTouchSupported = 'ontouchstart' in window || window.DocumentTouch && document instanceof DocumentTouch;
return function( types, selector, data, fn, one ) {
if (typeof types == 'string' && isTouchSupported && !(types.match(/touch/gi))) types = types.replace(/click/gi, 'touchstart');
return this._on( types, selector, data, fn, one );
};
}()),
});
// function for sorting DOM elements
$.fn.sorter = (function(){
// Thanks to James Padolsey and Avi Deitcher

View File

@ -7,7 +7,9 @@
var modified = false // indicates if anything has been clicked on this page
var groupBalance = 0; // available group money
var decimalSeparator = "."; // default decimal separator
var currencySeparator = "."; // default decimal separator
var currencyPrecision = 2; // default digits behind comma
var currencyUnit = "€"; // default currency
var toleranceIsCostly = true; // default tolerance behaviour
var isStockit = false; // Wheter the order is from stock oder normal supplier
@ -20,8 +22,10 @@ var toleranceOthers = new Array();
var itemsAllocated = new Array(); // how many items the group has been allocated and should definitely get
var quantityAvailable = new Array(); // stock_order. how many items are currently in stock
function setDecimalSeparator(character) {
decimalSeparator = character;
function setCurrencyFormat(separator, precision, unit) {
currencySeparator = separator;
currencyPrecision = precision;
currencyUnit = unit;
}
function setToleranceBehaviour(value) {
@ -129,7 +133,7 @@ function update(item, quantity, tolerance) {
}
function asMoney(amount) {
return String(amount.toFixed(2)).replace(/\./, ",");
return String(amount.toFixed(currencyPrecision)).replace(/\./, currencySeparator) + ' ' + currencyUnit;
}
function calcUnits(unitSize, quantity, tolerance) {

View File

@ -11,7 +11,15 @@ class Finance::OrderArticlesController < ApplicationController
def create
@order = Order.find(params[:order_id])
@order_article = @order.order_articles.build(params[:order_article])
# The article may with zero units ordered - in that case find and set amount to nonzero.
# 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
@order_article = @order.order_articles.build(params[:order_article])
end
unless @order_article.save
render action: :new
end

View File

@ -37,8 +37,8 @@ class GroupOrder < ActiveRecord::Base
:quantity => (goa ? goa.quantity : 0),
:others_quantity => order_article.quantity - (goa ? goa.quantity : 0),
:used_quantity => (goa ? goa.result(:quantity) : 0),
:tolerance => (goa ? goa.result(:tolerance) : 0),
:others_tolerance => order_article.tolerance - (goa ? goa.result(:tolerance) : 0),
:tolerance => (goa ? goa.tolerance : 0),
:others_tolerance => order_article.tolerance - (goa ? goa.tolerance : 0),
:used_tolerance => (goa ? goa.result(:tolerance) : 0),
:total_price => (goa ? goa.total_price : 0),
:missing_units => order_article.missing_units,

View File

@ -5,7 +5,7 @@
= f.input :contact_person
= f.input :contact_phone
= f.input :contact_address
= f.input :ignore_apple_restriction
= f.input :ignore_apple_restriction, :label => false, :inline_label => true
.form-actions
= f.button :submit
= link_to t('ui.or_cancel'), :back

View File

@ -22,20 +22,20 @@
= link_to "-", update_result_finance_group_order_article_path(group_order_article, modifier: '-'),
method: :put, remote: true, class: 'btn btn-mini'
%td.numeric
= number_to_currency(group_order_article.order_article.price.fc_price * group_order_article.result, :unit => "")
= number_to_currency(group_order_article.order_article.price.fc_price * group_order_article.result)
%td.actions{:style=>"width:1em"}
= link_to "Bearbeiten", edit_finance_group_order_article_path(group_order_article), remote: true,
= link_to t('ui.edit'), edit_finance_group_order_article_path(group_order_article), remote: true,
class: 'btn btn-mini'
%td.actions{:style=>"width:1em"}
= link_to "Löschen", finance_group_order_article_path(group_order_article), method: :delete,
= link_to t('ui.delete'), finance_group_order_article_path(group_order_article), method: :delete,
remote: true, class: 'btn btn-mini btn-danger'
%td
%tfoot
%tr
%td
%td{:style => "width:8em"}= t('total_fc')
%td{:style => "width:8em"}= t('.total_fc')
%td{:id => "group_orders_sum_quantity_#{order_article.id}"}
= order_article.group_orders_sum[:quantity]
%td.numeric{:id => "group_orders_sum_price_#{order_article.id}"}
= number_to_currency(order_article.group_orders_sum[:price], :unit => "")
%td{:colspan => "3"}
= number_to_currency(order_article.group_orders_sum[:price])
%td{:colspan => "3"}

View File

@ -7,4 +7,4 @@
%td.numeric= number_to_currency(group_order.price)
.form-actions
= link_to t('.clear'), close_finance_order_path(@order), method: :put, class: 'btn btn-primary'
= link_to t('.or_cancle'), new_finance_order_path(order_id: @order.id)
= link_to t('.or_cancel'), new_finance_order_path(order_id: @order.id)

View File

@ -3,9 +3,9 @@
= f.hidden_field :order_id
- if @invoice.delivery
%p= t('.linked', what_link: link_to(t('.delivery'), [@invoice.supplier,@invoice.delivery])).html_safe
%p= t('finance.invoices.linked', what_link: link_to(t('finance.invoices.linked_delivery'), [@invoice.supplier,@invoice.delivery])).html_safe
- if @invoice.order
%p= t('.linked', what_link: link_to(t('.order'), @invoice.order)).html_safe
%p= t('finance.invoices.linked', what_link: link_to(t('finance.invoices.linked_order'), @invoice.order)).html_safe
= f.association :supplier, hint: false
= f.input :number

View File

@ -1,12 +1,18 @@
- title t('.title', number: @invoice.number)
%p
%b= t 'simple_form.labels.invoice.supplier'
%b= t('simple_form.labels.invoice.supplier') + ':'
= @invoice.supplier.name
- if @invoice.delivery
%p
%b= t('simple_form.labels.invoice.delivery') + ':'
= t('.linked', what_link: link_to(t('.delivery'), [@invoice.supplier,@invoice.delivery])).html_safe
= t('finance.invoices.linked', what_link: link_to(t('finance.invoices.linked_delivery'), [@invoice.supplier,@invoice.delivery])).html_safe
- if @invoice.order
%p
%b= t('simple_form.labels.invoice.order') + ':'
= t('finance.invoices.linked', what_link: link_to(t('finance.invoices.linked_order'), @invoice.order)).html_safe
%p
%b= t('simple_form.labels.invoice.number') + ':'
= @invoice.number

View File

@ -3,7 +3,7 @@
$(function() {
#{data_to_js(@ordering_data)}
setGroupBalance(#{@ordering_data[:available_funds]});
setDecimalSeparator(",");
setCurrencyFormat("#{t('number.currency.format.separator')}", #{t('number.currency.format.precision')}, "#{t('number.currency.format.unit')}");
setToleranceBehaviour(#{FoodsoftConfig[:tolerance_is_costly]});
setStockit(#{@order.stockit?});
});
@ -97,8 +97,7 @@
%input{type: 'button', value: '-', 'data-decrease_tolerance' => order_article.id}
%td{id: "td_price_#{order_article.id}", style: "text-align:right; padding-right:10px; width:4em"}
%span{id: "price_#{order_article.id}_display"}= number_to_currency(@ordering_data[:order_articles][order_article.id][:total_price], unit: "")
%span{id: "price_#{order_article.id}_display"}= number_to_currency(@ordering_data[:order_articles][order_article.id][:total_price])
.article-info
.article-name= order_article.article.name
.pull-right
@ -125,8 +124,7 @@
%tr
%td= t('.total_sum_amount') + ':'
%td.currency
%span#total_price= @group_order.price
%span#total_price= number_to_currency(@group_order.price)
%tr
%td= t('.available_funds') + ':'
%td.currency= number_to_currency(@ordering_data[:available_funds])
@ -134,8 +132,7 @@
%td= t('.new_funds') + ':'
%td.currency
%strong
%span#new_balance= @ordering_data[:available_funds] - @group_order.price
%span#new_balance= number_to_currency(@ordering_data[:available_funds] - @group_order.price)
#order-button
= submit_tag( t('.action_save'), id: 'submit_button', class: 'btn btn-primary' )
#{link_to t('ui.or_cancel'), group_orders_path}

View File

@ -14,12 +14,12 @@
.control-group
%label(for='nick' class='control-label')= t '.user'
.controls
= text_field_tag 'nick'
= text_field_tag 'nick', nil, autocapitalize: 'off', autocorrect: 'off'
.control-group
%label(for='password' class='control-label')= t '.password'
.controls
= password_field_tag 'password'
= password_field_tag 'password', nil, autocapitalize: 'off', autocorrect: 'off'
.control-group
.controls

View File

@ -559,8 +559,8 @@ de:
confirm:
clear: Abschließen
first_paragraph: ! 'Wenn die Bestellung abgeschlossen wird, werden ebenfalls alle Gruppenkonten aktualisiert.<br />Die Konten werden wie folgt belastet:'
or_cancle: oder zurück zur Abrechnung
title: Bestellung abschließen
or_cancel: oder zurück zur Abrechnung
title: Bestellung abrechnen
edit_results_by_articles:
add_article: Artikel hinzufügen
amount: Menge
@ -585,7 +585,7 @@ de:
invoice_date: ! 'Rechnungsdatum:'
invoice_number: ! 'Rechnungsnummer:'
minus_refund_calculated: ! '- Pfand berechnet:'
new: Neue Rechnung erstellen
new: neue Rechnung erstellen
new_body: ! 'Eine Rechnung für diese Bestellung anlegen:'
plus_refund_credited: ! '+ Pfand gutgeschrieben:'
refund_adjusted_amount: ! 'pfandbereinigter Betrag:'
@ -682,23 +682,20 @@ de:
invoices:
edit:
title: Rechnung bearbeiten
form:
delivery: Lieferung
linked: Diese Rechnung ist mit einer %{what_link} verknüpft.
order: Bestellung
index:
action_new: Neue Rechnung anlegen
title: Rechnungen
invoices:
confirm_delete: Bist Du sicher?
delivery: Lieferung
linked: Diese Rechnung ist mit %{what_link} verknüpft.
linked_delivery: einer Lieferung
linked_order: einer Bestellung
new:
back: Züruck
title: Neue Rechnung anlegen
show:
back: Züruck
delivery: Lieferung
linked: Diese Rechnung ist mit einer %{what_link} verknüpft.
title: Rechnung %{number}
order_articles:
edit:
@ -799,7 +796,7 @@ de:
account_balance: Kontostand
available_funds: verfügbares Guthaben
finished_orders: nicht abgerechnete Bestellungen
open_orders: laufende Bestellungen
open_orders: Laufende Bestellungen
title: Guthaben
title: Bestellüberblick
messages:

View File

@ -557,12 +557,12 @@ en:
notice: Order was accounted succesfully, the balance of the account was updated.
close_direct:
alert: ! 'Order can not be closed: %{message}'
notice: Order was closed
notice: Order was closed.
confirm:
clear: Close
first_paragraph: ! 'When the order is closed, all group accounts will be updated.<br />The accounts will be charged as follows:'
or_cancle: or back to accounting
title: Close order
or_cancel: or back to accounting
title: Settle order
edit_results_by_articles:
add_article: Add article
amount: Amount
@ -577,7 +577,7 @@ en:
add_group: Add group
group: Group
total: Total costs
total_fc: Sum (FC-Price)
total_fc: Sum (FC-price)
units: Units
index:
title: Closed orders
@ -587,7 +587,7 @@ en:
invoice_date: ! 'Invoice date:'
invoice_number: ! 'Invoice number:'
minus_refund_calculated: ! '- deposit charged:'
new: Create new invoice
new: create new invoice
new_body: ! 'Create an invoice for this order:'
plus_refund_credited: ! '+ deposit returned:'
refund_adjusted_amount: ! 'amount adjusted for refund:'
@ -617,7 +617,7 @@ en:
ended: ended
last_edited_by: Last edited by
name: Supplier
no_closed_orders: At the moment there are no ended orders.
no_closed_orders: At the moment there are no closed orders.
state: State
summary:
changed: Data was changed!
@ -676,7 +676,7 @@ en:
group: Group
last_transactions: Last transactions
note: Note
open_transactions: not yet accounted
open_transactions: not yet settled
show_all: show all
supplier: supplier
title: Finances
@ -684,23 +684,20 @@ en:
invoices:
edit:
title: Edit invoice
form:
delivery: delivery
linked: This invoice is linked to a %{what_link}.
order: order
index:
action_new: Create new invoice
title: Invoices
invoices:
confirm_delete: Are you sure?
delivery: Delivery
linked: This invoice is linked to %{what_link}.
linked_delivery: a delivery
linked_order: an order
new:
back: Back
title: Create new invoice
show:
back: Back
delivery: delivery
linked: This invoice is linked to a %{what_link}.
title: Invoice %{number}
order_articles:
edit:
@ -753,8 +750,8 @@ en:
desc: View all %{link} here.
open_orders: current orders
title: Orders of %{group}
title_closed: Accounted
title_open: Completed/not accounted
title_closed: settled
title_open: closed/not settled
create:
error_general: The order couldnt be updated due to a bug.
error_stale: Someone else has ordered in the meantime, couldn't update the order.
@ -793,14 +790,14 @@ en:
index:
closed_orders:
more: more...
title: Closed orders
title: Settled orders
finished_orders:
title: Unaccounted orders
title: Unsettled orders
total_sum: Total sum
funds:
account_balance: Account balance
available_funds: Available credit
finished_orders: Unaccounted orders
finished_orders: unsettled orders
open_orders: Current orders
title: Credit
title: Orders overview
@ -830,7 +827,7 @@ en:
total_price: Total price
unit_price: Unit price
units: Units
closed_by: Accounted by %{user}
closed_by: Settled by %{user}
comment: Comment
comments:
title: Comments
@ -1319,13 +1316,13 @@ en:
ended_orders: Closed orders
ending: End
new_order: Create new order
no_open_orders: There are no current orders.
no_open_orders: There are currently no open orders.
note: Note
open_orders: Current orders
supplier: Supplier
title: Manage orders
model:
error_closed: Order was already accounted for
error_closed: Order was already settled
error_nosel: At least one article must be selected
error_starts_before_ends: must be after the start date (or remain empty)
notice_close: ! 'Order: %{name}, until %{ends}'
@ -1366,10 +1363,10 @@ en:
sort_group: Sorted in groups
supplier: ! 'Supplier:'
title: ! 'Order: %{name}'
warn_not_closed: Warning, order is not accounted yet.
warn_not_closed: Warning, order is not yet settled.
state:
closed: closed
finished: finished
closed: settled
finished: closed
open: open
update:
notice: The order was updated.

View File

@ -523,8 +523,8 @@ nl:
confirm:
clear: Sluiten
first_paragraph: ! 'Wanneer de bestelling gesloten wordt, worden alle tegoeden van huishoudens bijgewerkt.<br />De tegoeden worden als volgt belast:'
or_cancle: of terug naar afrekenen
title: Order sluiten
or_cancel: of terug naar afrekenen
title: Order afrekenen
edit_results_by_articles:
add_article: Artikel toevoegen
amount: Aantal
@ -549,7 +549,7 @@ nl:
invoice_date: ! 'Factuurdatum:'
invoice_number: ! 'Factuurnummer:'
minus_refund_calculated: ! '- statiegeld berekend:'
new: Factuur toevoegen
new: factuur toevoegen
new_body: ! 'Een factuur aan deze rekening toevoegen:'
plus_refund_credited: ! '+ statiegeld teruggekregen:'
refund_adjusted_amount: ! 'bedrag gecorrigeerd voor statiegeld:'
@ -579,7 +579,7 @@ nl:
ended: beëindigd
last_edited_by: Laatst aangepast door
name: Leverancier
no_closed_orders: Momenteel zijn er geen beëindigde bestellingen.
no_closed_orders: Momenteel zijn er geen gesloten bestellingen.
state: Status
summary:
changed:
@ -646,23 +646,20 @@ nl:
invoices:
edit:
title: Factuur bewerken
form:
delivery: levering
linked: Deze factuur is met aan %{what_link} gekoppeld.
order: bestelling
index:
action_new: Nieuwe factuur toevoegen
title: Facturen
invoices:
confirm_delete: Weet je het zeker?
delivery: Levering
linked: Deze factuur is aan %{what_link} gekoppeld.
linked_delivery: een levering
linked_order: een bestelling
new:
back: Terug
title: Nieuwe factuur toevoegen
show:
back: Terug
delivery: levering
linked: Deze factuur is aan een %{what_link} gekoppeld.
title: Factuur %{number}
order_articles:
edit:
@ -715,7 +712,7 @@ nl:
desc: Bekijk hier alle %{link}.
open_orders: lopende bestellingen
title: Bestellingen van %{group}
title_closed: Afgerekend
title_closed: afgerekend
title_open: gesloten/niet afgerekend
create:
error_general: De bestelling kon niet bijgewerkt worden vanwege een fout.
@ -757,12 +754,12 @@ nl:
more: meer...
title: Afgerekende bestellingen
finished_orders:
title:
title: Niet afgerekende bestellingen
total_sum:
funds:
account_balance:
available_funds:
finished_orders:
finished_orders: niet afgerekende bestellingen
open_orders: Lopende bestellingen
title: Credit
title: Besteloverzicht
@ -1040,7 +1037,7 @@ nl:
email_is_public:
name_is_public:
negative_balance:
order_finished:
order_finished: Informeer me over mijn bestelresultaat (wanneer de bestelling gesloten wordt).
phone_is_public:
send_as_email:
upcoming_tasks:
@ -1175,16 +1172,16 @@ nl:
action_end:
confirm_delete:
confirm_end:
ended_orders:
ended_orders: Gesloten bestellingen
ending:
new_order:
no_open_orders:
no_open_orders: Er zijn momenteel geen lopende bestellingen.
note:
open_orders:
open_orders: Lopende bestellingen
supplier:
title:
model:
error_closed:
error_closed: Bestelling was al afgerekend
error_nosel:
error_starts_before_ends:
notice_close:
@ -1223,11 +1220,11 @@ nl:
sort_group:
supplier:
title:
warn_not_closed:
warn_not_closed: Opgelet, bestelling is nog niet afgerekend.
state:
closed:
finished:
open:
closed: afgerekend
finished: gesloten
open: lopend
update:
notice:
pages:

View File

@ -1,8 +1,4 @@
# == Schema Information
<<<<<<< HEAD:test/fixtures/articles.yml
=======
# Schema version: 20090325175756
>>>>>>> wiki:test/fixtures/articles.yml
#
# Table name: articles
#

View File

@ -3,6 +3,7 @@ admins:
type: Workgroup
name: Administrators
description: System administrators.
created_on: <%= 5.weeks.ago.to_s(:db) %>
role_admin: true
role_suppliers: true
role_article_meta: true
@ -11,12 +12,8 @@ admins:
bananas:
type: Ordergroup
name: Banangroup
created_on: <%= 4.weeks.ago.to_s(:db) %>
account_balance: 100.00
account_updated: <%= 1.weeks.ago.to_s(:db) %>
contact_person: Tim
contact_phone: 030 123132456
contact_address: Waldermarstrasse 43, 10988 Berlin

View File

@ -1,8 +1,4 @@
# == Schema Information
<<<<<<< HEAD:test/fixtures/suppliers.yml
=======
# Schema version: 20090325175756
>>>>>>> wiki:test/fixtures/suppliers.yml
#
# Table name: suppliers
#
@ -38,12 +34,3 @@ terra:
Terra possibly delivers also on other days than tuesday. Don't
hesitate to ask for it.
min_order_quantity: 80,-€ (gross)

View File

@ -9,5 +9,15 @@ class ActiveSupport::TestCase
# -- they do not yet inherit this setting
fixtures :all
# Add more helper methods to be used by all tests here...
def login(nick='admin', pass='secret')
open_session do |session|
session.post '/f/login', nick: nick, password: pass
end
end
def logout
open_session do |session|
session.post '/f/logout'
end
end
end

View File

@ -1,18 +1,18 @@
require File.dirname(__FILE__) + '/../test_helper'
class SupplierTest < Test::Unit::TestCase
class SupplierTest < ActiveSupport::TestCase
fixtures :suppliers
def setup
@supplier = Supplier.find_by_name("Terra")
end
def test_read
test 'read' do
assert_equal "Terra", @supplier.name
assert_equal "www.terra-natur.de", @supplier.url
end
def test_update
test 'update' do
assert_equal "tuesday", @supplier.delivery_days
@supplier.delivery_days = 'wednesday'
assert @supplier.save, @supplier.errors.full_messages.join("; ")

View File

@ -1,13 +1,13 @@
require File.dirname(__FILE__) + '/../test_helper'
class UserTest < Test::Unit::TestCase
class UserTest < ActiveSupport::TestCase
fixtures :users
def setup
@admin = users(:admin)
end
def test_read_user
test 'read_user' do
assert_kind_of User, @admin
assert_equal "Anton", @admin.first_name
assert_equal "Admininistrator", @admin.last_name
@ -15,20 +15,25 @@ class UserTest < Test::Unit::TestCase
assert @admin.role_admin?
end
def test_create_and_read_password
@admin.set_password({:required => true}, "secret", "secret")
test 'create_and_read_password' do
@admin.password = "some_secret"
@admin.password_confirmation = @admin.password
assert @admin.valid?
assert @admin.has_password("some_secret")
end
test 'invalid_password' do
@admin.password = "foo"
@admin.password_confirmation = @admin.password
assert @admin.invalid?
assert_equal [I18n.t('activemodel.errors.messages.too_short', count: 5)], @admin.errors[:password]
end
test 'password_not_match' do
@admin.password = "foobar"
@admin.password_confirmation = "foobor"
@admin.save
assert @admin.has_password("secret")
end
def test_invalid_password
@admin.set_password({:required => true}, "foo", "foo")
assert_equal 'Passwort muss zwischen 6 u. 25 Zeichen haben', @admin.errors.on_base
end
def test_password_not_match
@admin.set_password({:required => true}, "foobar", "foobor")
assert_equal 'Passworteingaben stimmen nicht überein', @admin.errors.on_base
assert_equal [I18n.t('activemodel.errors.messages.confirmation')], @admin.errors[:password]
end
end