Last part of order refactoring. Now order_article create/update is possible.
This commit is contained in:
parent
4d796b8e73
commit
6202e05841
|
@ -5,3 +5,4 @@ db/*.sqlite3
|
||||||
nbproject/
|
nbproject/
|
||||||
config/environments/development.rb
|
config/environments/development.rb
|
||||||
capfile
|
capfile
|
||||||
|
config/environments/fcschinke09.rb
|
||||||
|
|
|
@ -42,70 +42,86 @@ class Finance::BalancingController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#TODO: Implement create/update of articles/article_prices...
|
def new_order_article
|
||||||
# def new_order_article
|
@order = Order.find(params[:id])
|
||||||
# @order = Order.find(params[:id])
|
render :update do |page|
|
||||||
# order_article = @order.order_articles.build(:tax => 7, :deposit => 0)
|
page["edit_box"].replace_html :partial => "new_order_article"
|
||||||
# render :update do |page|
|
page["edit_box"].show
|
||||||
# page["edit_box"].replace_html :partial => "new_order_article", :locals => {:order_article => order_article}
|
end
|
||||||
# page["edit_box"].show
|
end
|
||||||
# end
|
|
||||||
# end
|
def auto_complete_for_article_name
|
||||||
#
|
order = Order.find(params[:order_id])
|
||||||
# def create_order_article
|
type = order.stockit? ? "type = 'StockArticle'" : "type IS NULL"
|
||||||
# @order = Order.find(params[:order_article][:order_id])
|
@articles = Article.find(:all,
|
||||||
# order_article = OrderArticle.new(params[:order_article])
|
:conditions => [ "supplier_id = ? AND #{type} AND LOWER(name) LIKE ?",
|
||||||
#
|
order.supplier_id,
|
||||||
# render :update do |page|
|
'%' + params[:article][:name].downcase + '%' ],
|
||||||
# if order_article.save
|
:order => 'name ASC',
|
||||||
# page["edit_box"].hide
|
:limit => 8)
|
||||||
# page["summary"].replace_html :partial => 'summary'
|
render :partial => 'shared/auto_complete_articles'
|
||||||
# page.insert_html :bottom, "result_table", :partial => "order_article_result", :locals => {:order_article => order_article}
|
|
||||||
# page["order_article_#{order_article.id}"].visual_effect :highlight, :duration => 2
|
end
|
||||||
# page["group_order_articles_#{order_article.id}"].show
|
|
||||||
# else
|
def create_order_article
|
||||||
# page["edit_box"].replace_html :partial => "new_order_article", :locals => {:order_article => order_article}
|
@order = Order.find(params[:order_id])
|
||||||
# end
|
order_article = @order.order_articles.find_by_article_id(params[:order_article][:article_id])
|
||||||
# end
|
|
||||||
# end
|
unless order_article
|
||||||
#
|
# Article wasn't already assigned with this order, lets create a new one
|
||||||
# def editArticleResult
|
order_article = @order.order_articles.build(params[:order_article])
|
||||||
# @article = OrderArticleResult.find(params[:id])
|
order_article.article_price = order_article.article.article_prices.first
|
||||||
# render :update do |page|
|
end
|
||||||
# page["edit_box"].replace_html :partial => 'editArticleResult'
|
# Set units to order to 1, so the article is visible on page
|
||||||
# page["edit_box"].show
|
order_article.units_to_order = 1
|
||||||
# end
|
|
||||||
# end
|
render :update do |page|
|
||||||
#
|
if order_article.save
|
||||||
# def updateArticleResult
|
page["edit_box"].hide
|
||||||
# @article = OrderArticleResult.find(params[:id])
|
page.insert_html :top, "result_table", :partial => "order_article_result", :locals => {:order_article => order_article}
|
||||||
# @article.attributes=(params[:order_article_result]) # update attributes but doesn't save
|
page["order_article_#{order_article.id}"].visual_effect :highlight, :duration => 2
|
||||||
# @article.make_gross
|
page["group_order_articles_#{order_article.id}"].show
|
||||||
# @order = @article.order
|
else
|
||||||
# @ordered_articles = @order.order_article_results
|
page["edit_box"].replace_html :partial => "new_order_article"
|
||||||
# @group_orders = @order.group_order_results
|
end
|
||||||
# render :update do |page|
|
end
|
||||||
# if @article.save
|
end
|
||||||
# page["edit_box"].hide
|
|
||||||
# page["summary"].replace_html :partial => 'summary'
|
def edit_order_article
|
||||||
# page["summary"].visual_effect :highlight, :duration => 2
|
@order_article = OrderArticle.find(params[:id])
|
||||||
# page["order_article_result_#{@article.id}"].replace_html :partial => 'articleResult'
|
render :update do |page|
|
||||||
# page['order_article_result_'+@article.id.to_s].visual_effect :highlight, :delay => 0.5, :duration => 2
|
page["edit_box"].replace_html :partial => 'edit_order_article'
|
||||||
# page["group_order_article_results_#{@article.id}"].replace_html :partial => "groupOrderArticleResults"
|
page["edit_box"].show
|
||||||
# else
|
end
|
||||||
# page['edit_box'].replace_html :partial => 'editArticleResult'
|
end
|
||||||
# end
|
|
||||||
# end
|
# Update this article and creates a new articleprice if neccessary
|
||||||
# end
|
def update_order_article
|
||||||
|
@order_article = OrderArticle.find(params[:id])
|
||||||
|
begin
|
||||||
|
@order_article.update_article_and_price!(params[:article], params[:price], params[:order_article])
|
||||||
|
render :update do |page|
|
||||||
|
page["edit_box"].hide
|
||||||
|
page["summary"].replace_html :partial => 'summary', :locals => {:order => @order_article.order}
|
||||||
|
page["summary"].visual_effect :highlight, :duration => 2
|
||||||
|
page["order_article_#{@order_article.id}"].replace_html :partial => 'order_article', :locals => {:order_article => @order_article}
|
||||||
|
page["order_article_#{@order_article.id}"].visual_effect :highlight, :delay => 0.5, :duration => 2
|
||||||
|
page["group_order_articles_#{@order_article.id}"].replace_html :partial => "group_order_articles", :locals => {:order_article => @order_article}
|
||||||
|
end
|
||||||
|
rescue => @error
|
||||||
|
render :update do |page|
|
||||||
|
page['edit_box'].replace_html :partial => 'edit_order_article'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def destroy_order_article
|
def destroy_order_article
|
||||||
order_article = OrderArticle.find(params[:id])
|
order_article = OrderArticle.find(params[:id])
|
||||||
order_article.destroy
|
order_article.destroy
|
||||||
@order = order_article.order
|
|
||||||
render :update do |page|
|
render :update do |page|
|
||||||
page["order_article_#{order_article.id}"].remove
|
page["order_article_#{order_article.id}"].remove
|
||||||
page["group_order_articles_#{order_article.id}"].remove
|
page["group_order_articles_#{order_article.id}"].remove
|
||||||
page["summary"].replace_html :partial => 'summary', :locals => {:order => @order}
|
page["summary"].replace_html :partial => 'summary', :locals => {:order => order_article.order}
|
||||||
page["summary"].visual_effect :highlight, :duration => 2
|
page["summary"].visual_effect :highlight, :duration => 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -139,6 +155,7 @@ class Finance::BalancingController < ApplicationController
|
||||||
goa.group_order.update_price! # Update the price attribute of new GroupOrder
|
goa.group_order.update_price! # Update the price attribute of new GroupOrder
|
||||||
order_article.update_results! if order_article.article.is_a?(StockArticle) # Update units_to_order of order_article
|
order_article.update_results! if order_article.article.is_a?(StockArticle) # Update units_to_order of order_article
|
||||||
page["edit_box"].hide
|
page["edit_box"].hide
|
||||||
|
page["order_article_#{order_article.id}"].replace_html :partial => 'order_article', :locals => {:order_article => order_article}
|
||||||
|
|
||||||
page["group_order_articles_#{order_article.id}"].replace_html :partial => 'group_order_articles',
|
page["group_order_articles_#{order_article.id}"].replace_html :partial => 'group_order_articles',
|
||||||
:locals => {:order_article => order_article}
|
:locals => {:order_article => order_article}
|
||||||
|
@ -168,6 +185,7 @@ class Finance::BalancingController < ApplicationController
|
||||||
goa.order_article.update_results! if goa.order_article.article.is_a?(StockArticle) # Update units_to_order of order_article
|
goa.order_article.update_results! if goa.order_article.article.is_a?(StockArticle) # Update units_to_order of order_article
|
||||||
|
|
||||||
page["edit_box"].hide
|
page["edit_box"].hide
|
||||||
|
page["order_article_#{goa.order_article.id}"].replace_html :partial => 'order_article', :locals => {:order_article => goa.order_article}
|
||||||
page["group_order_articles_#{goa.order_article.id}"].replace_html :partial => 'group_order_articles',
|
page["group_order_articles_#{goa.order_article.id}"].replace_html :partial => 'group_order_articles',
|
||||||
:locals => {:order_article => goa.order_article}
|
:locals => {:order_article => goa.order_article}
|
||||||
page["summary"].replace_html :partial => 'summary', :locals => {:order => goa.order_article.order}
|
page["summary"].replace_html :partial => 'summary', :locals => {:order => goa.order_article.order}
|
||||||
|
@ -186,6 +204,7 @@ class Finance::BalancingController < ApplicationController
|
||||||
|
|
||||||
render :update do |page|
|
render :update do |page|
|
||||||
page["edit_box"].hide
|
page["edit_box"].hide
|
||||||
|
page["order_article_#{goa.order_article.id}"].replace_html :partial => 'order_article', :locals => {:order_article => goa.order_article}
|
||||||
page["group_order_articles_#{goa.order_article.id}"].replace_html :partial => 'group_order_articles',
|
page["group_order_articles_#{goa.order_article.id}"].replace_html :partial => 'group_order_articles',
|
||||||
:locals => {:order_article => goa.order_article}
|
:locals => {:order_article => goa.order_article}
|
||||||
page["summary"].replace_html :partial => 'summary', :locals => {:order => goa.order_article.order}
|
page["summary"].replace_html :partial => 'summary', :locals => {:order => goa.order_article.order}
|
||||||
|
|
|
@ -16,6 +16,21 @@ class ArticlePrice < ActiveRecord::Base
|
||||||
|
|
||||||
belongs_to :article
|
belongs_to :article
|
||||||
has_many :order_articles
|
has_many :order_articles
|
||||||
|
|
||||||
|
# Custom attribute setter that accepts decimal numbers using localized decimal separator.
|
||||||
|
def price=(price)
|
||||||
|
self[:price] = String.delocalized_decimal(price)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Custom attribute setter that accepts decimal numbers using localized decimal separator.
|
||||||
|
def tax=(tax)
|
||||||
|
self[:tax] = String.delocalized_decimal(tax)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Custom attribute setter that accepts decimal numbers using localized decimal separator.
|
||||||
|
def deposit=(deposit)
|
||||||
|
self[:deposit] = String.delocalized_decimal(deposit)
|
||||||
|
end
|
||||||
|
|
||||||
# The financial gross, net plus tax and deposit.
|
# The financial gross, net plus tax and deposit.
|
||||||
def gross_price
|
def gross_price
|
||||||
|
|
|
@ -21,18 +21,11 @@ class OrderArticle < ActiveRecord::Base
|
||||||
belongs_to :article_price
|
belongs_to :article_price
|
||||||
has_many :group_order_articles, :dependent => :destroy
|
has_many :group_order_articles, :dependent => :destroy
|
||||||
|
|
||||||
validates_presence_of :order_id
|
validates_presence_of :order_id, :article_id
|
||||||
validates_presence_of :article_id
|
|
||||||
validates_uniqueness_of :article_id, :scope => :order_id # an article can only have one record per order
|
|
||||||
validate :article_and_price_exist
|
validate :article_and_price_exist
|
||||||
|
|
||||||
named_scope :ordered, :conditions => "units_to_order >= 1"
|
named_scope :ordered, :conditions => "units_to_order >= 1"
|
||||||
|
|
||||||
# TODO: How to create/update articles/article_prices during balancing
|
|
||||||
# # Accessors for easy create of new order_articles in balancing process
|
|
||||||
# attr_accessor :name, :order_number, :units_to_order, :unit_quantity, :unit, :net_price, :tax, :deposit
|
|
||||||
#
|
|
||||||
# before_validation_on_create :create_new_article
|
|
||||||
|
|
||||||
# This method returns either the ArticlePrice or the Article
|
# This method returns either the ArticlePrice or the Article
|
||||||
# The first will be set, when the the order is finished
|
# The first will be set, when the the order is finished
|
||||||
|
@ -88,16 +81,33 @@ class OrderArticle < ActiveRecord::Base
|
||||||
(units_to_order * price.unit_quantity) == group_orders_sum[:quantity]
|
(units_to_order * price.unit_quantity) == group_orders_sum[:quantity]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Updates order_article and belongings during balancing process
|
||||||
|
def update_article_and_price!(article_attributes, price_attributes, order_article_attributes)
|
||||||
|
OrderArticle.transaction do
|
||||||
|
# Updates article
|
||||||
|
article.update_attributes!(article_attributes)
|
||||||
|
|
||||||
|
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 ordergroup values
|
||||||
|
group_order_articles.each { |goa| goa.group_order.update_price! }
|
||||||
|
end
|
||||||
|
|
||||||
|
# Updates units_to_order
|
||||||
|
self.attributes = order_article_attributes
|
||||||
|
self.save!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def article_and_price_exist
|
def article_and_price_exist
|
||||||
errors.add(:article, "muss angegeben sein und einen aktuellen Preis haben") if !(article = Article.find(article_id)) || article.fc_price.nil?
|
errors.add(:article, "muss angegeben sein und einen aktuellen Preis haben") if !(article = Article.find(article_id)) || article.fc_price.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
# def create_new_article
|
|
||||||
# old_article = order.articles.find_by_name(name) # Check if there is already an Article with this name
|
|
||||||
# unless old_article
|
|
||||||
# self.article.build
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
%h2
|
|
||||||
Bearbeiten von
|
|
||||||
= @article.name
|
|
||||||
|
|
||||||
- remote_form_for 'order_article_result', @article, :url => {:action => 'updateArticleResult', :id => @article }, |
|
|
||||||
:before => "Element.show('loader')", :success => "Element.hide('loader')" do |@form| |
|
|
||||||
|
|
||||||
= render :partial => "articleResultForm"
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
%h2
|
||||||
|
Bearbeiten von
|
||||||
|
= @order_article.article.name
|
||||||
|
|
||||||
|
- remote_form_for :order_article, :url => {:action => 'update_order_article', :id => @order_article }, |
|
||||||
|
:before => "Element.show('loader')", :success => "Element.hide('loader')" do |
|
||||||
|
= render :partial => "order_article_form"
|
|
@ -1,7 +1,7 @@
|
||||||
%p{:style => "float:left"}
|
%p{:style => "float:left"}
|
||||||
%b Lieferung bearbeiten
|
%b Lieferung bearbeiten
|
||||||
%p{:style => "float:right"}
|
%p{:style => "float:right"}
|
||||||
//= remote_link_to "Artikel hinzufügen", :url => {:action => "newArticleResult", :id => @order}
|
= remote_link_to "Artikel hinzufügen", :url => {:action => "new_order_article", :id => @order}
|
||||||
|
|
||||||
%table{:class => "ordered_articles", :style => "clear:both"}
|
%table{:class => "ordered_articles", :style => "clear:both"}
|
||||||
%thead
|
%thead
|
||||||
|
|
|
@ -1,7 +1,15 @@
|
||||||
%h2
|
%h2
|
||||||
Neuer gelieferter Artikel die Bestellung
|
Neuer gelieferter Artikel die Bestellung
|
||||||
|
|
||||||
- remote_form_for order_article, :url => {:action => 'create_order_article' }, |
|
- remote_form_for :order_article, :url => {:action => 'create_order_article', :order_id => @order.id}, |
|
||||||
:before => "Element.show('loader')", :success => "Element.hide('loader')" do |form| |
|
:before => "Element.show('loader')", :success => "Element.hide('loader')" do |form| |
|
||||||
|
%p
|
||||||
= render :partial => 'order_article_form', :locals => {:form => form}
|
Suche im Katalog
|
||||||
|
= text_field_with_auto_complete :article, :name, {}, |
|
||||||
|
{:url => {:action => 'auto_complete_for_article_name', :order_id => @order.id}, |
|
||||||
|
:after_update_element => 'setHiddenId'} |
|
||||||
|
%p
|
||||||
|
= form.hidden_field :article_id, :id => 'hidden_id'
|
||||||
|
= submit_tag "Neuen Artikel hinzufügen"
|
||||||
|
|
|
||||||
|
= link_to_function "Abbrechen", "Element.hide('edit_box')"
|
|
@ -13,8 +13,8 @@
|
||||||
%td= order_article.price.tax
|
%td= order_article.price.tax
|
||||||
%td= order_article.price.deposit
|
%td= order_article.price.deposit
|
||||||
%td
|
%td
|
||||||
//= remote_link_to icon(:edit), |
|
= remote_link_to icon(:edit), |
|
||||||
//:url => {:action => 'edit_order_article', :id => order_article} |
|
:url => {:action => 'edit_order_article', :id => order_article} |
|
||||||
%td
|
%td
|
||||||
= remote_link_to icon(:delete), :confirm => 'Bist du sicher?', |
|
= remote_link_to icon(:delete), :confirm => 'Bist du sicher?', |
|
||||||
:url => {:action => 'destroy_order_article', :id => order_article}, |
|
:url => {:action => 'destroy_order_article', :id => order_article}, |
|
||||||
|
|
|
@ -1,25 +1,25 @@
|
||||||
= form.error_messages
|
- if @error
|
||||||
|
%b= @error
|
||||||
%table
|
%table
|
||||||
%tr
|
%tr
|
||||||
%th Name
|
%th Name
|
||||||
%th Nr.
|
%th Nr.
|
||||||
%th
|
%th
|
||||||
%abbr{:title=>"Anzahl gelieferter Gebinde"} Menge
|
%abbr{:title=>"Anzahl gelieferter Gebinde"} Menge
|
||||||
%th GebGr
|
|
||||||
%th Einheit
|
%th Einheit
|
||||||
|
%th GebGr
|
||||||
%th netto
|
%th netto
|
||||||
%th MwSt.
|
%th MwSt.
|
||||||
%th Pfand
|
%th Pfand
|
||||||
%tr
|
%tr
|
||||||
%td= form.text_field 'name', :size => 20
|
%td= text_field_tag 'article[name]', @order_article.article.name, :size => 20
|
||||||
%td= form.text_field 'order_number', :size => 3
|
%td= text_field_tag 'article[order_number]', @order_article.article.order_number, :size => 3
|
||||||
%td= form.text_field 'units_to_order', :size => 5
|
%td= text_field_tag 'order_article[units_to_order]', @order_article.units_to_order, :size => 5
|
||||||
%td= form.text_field 'unit_quantity', :size => 3
|
%td= text_field_tag 'article[unit]', @order_article.article.unit, :size => 5
|
||||||
%td= form.text_field 'unit', :size => 5
|
%td= text_field_tag 'price[unit_quantity]', @order_article.price.unit_quantity, :size => 3
|
||||||
%td= form.text_field 'net_price', :size => 3
|
%td= text_field_tag 'price[price]', @order_article.price.price, :size => 3
|
||||||
%td= form.text_field 'tax', :size => 3
|
%td= text_field_tag 'price[tax]', @order_article.price.tax, :size => 3
|
||||||
%td= form.text_field 'deposit', :size => 3
|
%td= text_field_tag 'price[deposit]', @order_article.price.deposit, :size => 3
|
||||||
= form.hidden_field "order_id"
|
|
||||||
%br/
|
%br/
|
||||||
= submit_tag "Speichern"
|
= submit_tag "Speichern"
|
||||||
|
|
|
|
||||||
|
|
|
@ -44,7 +44,9 @@
|
||||||
Aktionen:
|
Aktionen:
|
||||||
- if @order.open?
|
- if @order.open?
|
||||||
= link_to "Bearbeiten", edit_order_path(@order)
|
= link_to "Bearbeiten", edit_order_path(@order)
|
||||||
|
|
|
||||||
= link_to 'Beenden!', finish_order_path(@order), :method => :post, :confirm => "Willst Du wirklich die Bestellung beenden?\nEs gibt kein zurück.."
|
= link_to 'Beenden!', finish_order_path(@order), :method => :post, :confirm => "Willst Du wirklich die Bestellung beenden?\nEs gibt kein zurück.."
|
||||||
|
|
|
||||||
- unless @order.closed?
|
- unless @order.closed?
|
||||||
= link_to "Löschen", @order, :confirm => "Willst du wirklich die Bestellung löschen?", :method => :delete
|
= link_to "Löschen", @order, :confirm => "Willst du wirklich die Bestellung löschen?", :method => :delete
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
%ul.autocomplete
|
||||||
|
- for article in @articles
|
||||||
|
%li{:id => article.id.to_s}= "#{article.name} (#{article.unit_quantity} * #{article.unit} | #{number_to_currency(article.price)})"
|
|
@ -1,4 +1,4 @@
|
||||||
class RefactorOrderLogic < ActiveRecord::Migration
|
class RoadToVersionThree < ActiveRecord::Migration
|
||||||
def self.up
|
def self.up
|
||||||
# TODO: Combine migrations since foodsoft3-development into one file
|
# TODO: Combine migrations since foodsoft3-development into one file
|
||||||
# and try to build a migration path from old data.
|
# and try to build a migration path from old data.
|
|
@ -45,3 +45,10 @@ function redirectTo(newLoc) {
|
||||||
document.location.href = nextPage
|
document.location.href = nextPage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use with auto_complete to set a unique id,
|
||||||
|
// e.g. when the user selects a (may not unique) name
|
||||||
|
// There must be a hidden field with the id 'hidden_field'
|
||||||
|
function setHiddenId(text, li) {
|
||||||
|
$('hidden_id').value = li.id;
|
||||||
|
}
|
Loading…
Reference in New Issue