diff --git a/.rbenv-version b/.rbenv-version index 0ca8caf7..546d4d8a 100644 --- a/.rbenv-version +++ b/.rbenv-version @@ -1 +1 @@ -1.9.3-p327 +1.9.3-p327 \ No newline at end of file diff --git a/VERSION b/VERSION new file mode 100644 index 00000000..94ff29cc --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +3.1.1 diff --git a/app/controllers/finance/order_articles_controller.rb b/app/controllers/finance/order_articles_controller.rb index 435d1712..13c1106c 100644 --- a/app/controllers/finance/order_articles_controller.rb +++ b/app/controllers/finance/order_articles_controller.rb @@ -26,7 +26,7 @@ class Finance::OrderArticlesController < ApplicationController @order = Order.find(params[:order_id]) @order_article = OrderArticle.find(params[:id]) begin - @order_article.update_article_and_price!(params[:article], params[:price], params[:order_article]) + @order_article.update_article_and_price!(params[:article], params[:article_price], params[:order_article]) rescue render action: :edit end diff --git a/app/models/order_article.rb b/app/models/order_article.rb index 65d19577..102cfa01 100644 --- a/app/models/order_article.rb +++ b/app/models/order_article.rb @@ -1,6 +1,8 @@ # An OrderArticle represents a single Article that is part of an Order. class OrderArticle < ActiveRecord::Base + attr_reader :update_current_price + belongs_to :order belongs_to :article belongs_to :article_price @@ -82,26 +84,35 @@ class OrderArticle < ActiveRecord::Base # Updates order_article and belongings during balancing process def update_article_and_price!(article_attributes, price_attributes, order_article_attributes) OrderArticle.transaction do + # Updates self + self.update_attributes!(order_article_attributes) + # Updates article article.update_attributes!(article_attributes) + # Updates article_price belonging to current order article article_price.attributes = price_attributes if article_price.changed? - # Creates a new article_price if neccessary - price = build_article_price(price_attributes) - price.created_at = order.ends - price.save! + # Updates also price attributes of article if update_current_price is selected + if update_current_price + article.update_attributes!(price_attributes) + self.article_price = article.article_prices.first # Assign new created article price to order article + else + # Creates a new article_price if neccessary + # Set created_at timestamp to order ends, to make sure the current article price isn't changed + create_article_price!(price_attributes.merge(created_at: order.ends)) and save + end # Updates ordergroup values - group_order_articles.each { |goa| goa.group_order.update_price! } + update_ordergroup_prices end - - # Updates units_to_order - self.attributes = order_article_attributes - self.save! end end + def update_current_price=(value) + @update_current_price = (value == true or value == '1') ? true : false + end + # Units missing for the next full unit_quantity of the article def missing_units units = article.unit_quantity - ((quantity % article.unit_quantity) + tolerance) @@ -123,10 +134,10 @@ class OrderArticle < ActiveRecord::Base end end - #TODO: Delayed job maybe?? def update_ordergroup_prices group_order_articles.each { |goa| goa.group_order.update_price! } end + handle_asynchronously :update_ordergroup_prices end diff --git a/app/views/finance/order_articles/_edit.html.haml b/app/views/finance/order_articles/_edit.html.haml index acda7fce..13432620 100644 --- a/app/views/finance/order_articles/_edit.html.haml +++ b/app/views/finance/order_articles/_edit.html.haml @@ -9,11 +9,14 @@ = f.input :name = f.input :order_number = f.input :unit + = simple_fields_for @order_article.article_price do |f| = f.input :unit_quantity = f.input :price = f.input :tax = f.input :deposit + = form.input :update_current_price, as: :boolean + .modal-footer = button_tag "Schließen", class: 'btn', data: {dismiss: 'modal'} = form.submit class: 'btn btn-primary' \ No newline at end of file diff --git a/config/locales/de.yml b/config/locales/de.yml index d53e9593..b5a30be4 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -284,6 +284,11 @@ de: amount: 'Betrag' phone: "Telefon" user_tokens: 'Mitglieder' + price: 'Preis (netto)' + unit_quantity: 'Gebindegröße' + order_number: 'Bestellnummer' + tax: 'MwSt' + deposit: 'Pfand' user: nick: "Benutzerinnenname" first_name: "Vorname" @@ -342,11 +347,6 @@ de: unit: 'Einheit' note: 'Notiz' article_category: 'Kategorie' - price: 'Preis (netto)' - unit_quantity: 'Gebindegröße' - order_number: 'Bestellnummer' - tax: 'MwSt' - deposit: 'Pfand' stock_article: supplier: 'Lieferant' delivery: @@ -373,7 +373,7 @@ de: deposit_credit: Pfand gutgeschrieben order_article: units_to_order: Menge - + update_current_price: Globalen Preis aktualisieren hints: tax: 'In Prozent, Standard sind 7,0' @@ -390,3 +390,4 @@ de: private: Nachricht erscheint nicht im Foodsoft Posteingang order_article: units_to_order: Anzahl gelieferter Gebinde + update_current_price: Ändert auch den Preis für aktuelle Bestellungen diff --git a/lib/tasks/foodsoft.rake b/lib/tasks/foodsoft.rake index ebfecbc1..0c8f0755 100644 --- a/lib/tasks/foodsoft.rake +++ b/lib/tasks/foodsoft.rake @@ -22,7 +22,9 @@ namespace :foodsoft do workgroups = Workgroup.where(weekly_task: true) for workgroup in workgroups puts "Create weekly tasks for #{workgroup.name}" - workgroup.next_weekly_tasks[3..5].each do |date| + # Loop through next tasks weekly tasks method, + # skip the next 3 weeks, to allow manually deleting tasks + workgroup.next_weekly_tasks[3..-1].each do |date| unless workgroup.tasks.exists?({:due_date => date, :weekly => true}) workgroup.tasks.create(workgroup.task_attributes(date)) end