Permalink
Browse files

Fix some bugs and improve code

  * refactor callbacks on Invoice to correctly update invoice_step
    and payment_step statuses (#231)
  * use single submit button on query's forms (#236)
  * fix minor bugs (#126, #206, #221)
  * optimize JobContractsController
  * replace some "humanize" calls by l()
  • Loading branch information...
1 parent f43a428 commit 399e9c66fd101b7507d7c1da3f0a68205f165359 @spidou committed Mar 7, 2012
View
@@ -151,7 +151,7 @@
equipments = ChecklistOption.create! :checklist_id => checklist1.id, :title => "6- Équipements particuliers"
ChecklistOption.create! :checklist_id => checklist1.id, :parent_id => equipments.id, :title => "Groupe éléctrogène"
ChecklistOption.create! :checklist_id => checklist1.id, :parent_id => equipments.id, :title => "Rallonge"
-ChecklistOption.create! :checklist_id => checklist1.id, :parent_id => equipments.id, :title => "Échaffaudage"
+ChecklistOption.create! :checklist_id => checklist1.id, :parent_id => equipments.id, :title => "Échafaudage"
ChecklistOption.create! :checklist_id => checklist1.id, :parent_id => equipments.id, :title => "Locations"
set_default_permissions
@@ -23,7 +23,7 @@ class SupplierSupply < ActiveRecord::Base
validates_persistence_of :supply_id
validates_persistence_of :supplier_id, :unless => :should_destroy?
- journalize :attributes => [:supplier_id, :supplier_reference, :lead_time, :fob_unit_price, :taxes],
+ journalize :attributes => [:supplier_id, :supplier_reference, :fob_unit_price, :taxes, :lead_time],
:identifier_method => Proc.new{ |s| "#{s.supplier.name}" }
attr_accessor :should_destroy
@@ -41,6 +41,7 @@ def should_destroy?
end
def unit_price
+ return 0.0 if fob_unit_price.nil?
return fob_unit_price if taxes.nil? or taxes.zero?
fob_unit_price * ( 1 + ( taxes / 100 ) )
end
@@ -6,7 +6,7 @@
<%= form.label :delay_type, "Définir :" %>
<select name='delay_type' id='delay_type'>
<option value='0' disabled='disabled'>Une date</option>
- <option value='1'>Un d&eacute;lais</option>
+ <option value='1'>Un d&eacute;lai</option>
</select>
</p>
<% end %>
@@ -50,26 +50,28 @@ fr:
consumable_sub_category:
<<: *supply_sub_category
supply: &supply
- supply_category: "Famille"
- supply_sub_category: "Sous-famille"
- supply_type: "Type"
- name: "Type"
- reference: "Référence"
- supplier: "Fournisseur principal"
- measure: "Grandeur/U"
- unit_mass: "Masse/U"
- average_unit_price: "PU TTC moyen"
average_measure_price: "PG TTC moyen"
- higher_unit_price: "PU TTC plus cher"
+ average_unit_price: "PU TTC moyen"
+ average_unit_value: "Valeur unitaire moyenne"
+ enabled: "Actif"
higher_measure_price: "PG TTC cher"
- threshold: "Seuil d'alerte"
+ higher_unit_price: "PU TTC plus cher"
+ measure: "Grandeur/U"
+ name: "Type"
+ reference: "Référence"
+ stock_mass: "Poids total"
+ stock_measure: "Grandeur totale"
stock_quantity: "Quantité"
stock_quantity_at_last_inventory: "Quantité au dernier inventaire"
- stock_measure: "Grandeur totale"
stock_value: "Valeur totale"
- stock_mass: "Poids total"
+ supplier: "Fournisseur principal"
suppliers: "Fournisseurs"
- average_unit_value: "Valeur unitaire moyenne"
+ supplier_supply: "Fournisseur"
+ supply_category: "Famille"
+ supply_sub_category: "Sous-famille"
+ supply_type: "Type"
+ threshold: "Seuil d'alerte"
+ unit_mass: "Masse/U"
commodity:
<<: *supply
consumable:
@@ -1,22 +1,22 @@
class JobContractsController < ApplicationController
helper :employees, :documents, :numbers
+ before_filter :find_employee
+ before_filter :find_or_build_job_contract, :only => [:edit, :update]
+
# GET /employees/:employee_id/job_contracts
def index
- @employee = Employee.find(params[:employee_id])
@job_contracts = @employee.job_contracts.all(:order => 'start_date Desc, created_at DESC')
@hide_selector_column = true
end
# GET /employees/:employee_id/job_contracts/new
def new
- @employee = Employee.find(params[:employee_id])
@job_contract = @employee.job_contracts.build
end
# POST /employees/:employee_id/job_contracts
def create
- @employee = Employee.find(params[:employee_id])
@job_contract = @employee.job_contracts.build(params[:job_contract])
if @job_contract.valid?
@@ -32,15 +32,10 @@ def create
# GET /employees/:employee_id/job_contracts/:id/edit
def edit
@employee_departure ||= true if params['employee_departure']
- @employee = Employee.find(params[:employee_id])
- @job_contract = @employee.job_contracts.detect {|n| n.id == params[:id].to_i}
end
# PUT /employees/:employee_id/job_contracts/:id
def update
- @employee = Employee.find(params[:employee_id])
- @job_contract = @employee.job_contracts.detect {|n| n.id == params[:id].to_i}
-
if @job_contract.update_attributes(params[:job_contract])
flash[:notice] = 'Le contrat de travail a été modifié avec succès.'
redirect_to(employee_job_contract_path(@employee, @job_contract))
@@ -49,4 +44,13 @@ def update
render(:action => 'edit')
end
end
+
+ def find_employee
+ @employee = Employee.find(params[:employee_id])
+ end
+
+ def find_or_build_job_contract
+ #@job_contract = @employee.job_contracts.detect {|n| n.id == params[:id].to_i}
+ @job_contract = @employee.job_contracts.find_by_id(params[:id]) || @employee.job_contracts.build
+ end
end
@@ -2,12 +2,12 @@
<%= javascript_include_tag 'rh/job_contract' %>
<% end %>
-<%= render :partial => 'employees/employee_summary', :locals => {:employee => @employee}%>
+<%= render :partial => 'employees/employee_summary', :locals => { :employee => @employee } %>
<% title_context "Ressources Humaines" %>
<% title_context @employee.fullname %>
<%= title "Modifier le contrat de travail" %>
<div class="presentation_medium">
- <%= render :partial => 'job_contracts/job_contract', :object => @job_contract%>
+ <%= render :partial => @job_contract %>
</div>
@@ -4,13 +4,13 @@ def display_product_dimensions(form, product, text_field_options = {})
if form.form_view?
'<span class="product_dimensions">
<span class="product_width">' +
- '<span title="Largeur">l :</span>' + form.text_field(:width, { :value => product.width_before_type_cast, :size => 6, :autocomplete => :off }.merge(text_field_options)) +
+ '<span title="Largeur">l :</span>' + form.text_field(:width, { :value => product.width, :size => 6, :autocomplete => :off }.merge(text_field_options)) +
'</span>' +
'<span class="product_length">' +
- '<span title="Longueur">L :</span>' + form.text_field(:length, { :value => product.length_before_type_cast, :size => 6, :autocomplete => :off }.merge(text_field_options)) +
+ '<span title="Longueur">L :</span>' + form.text_field(:length, { :value => product.length, :size => 6, :autocomplete => :off }.merge(text_field_options)) +
'</span>' +
'<span class="product_height">' +
- '<span title="Hauteur">H :</span>' + form.text_field(:height, { :value => product.height_before_type_cast, :size => 6, :autocomplete => :off }.merge(text_field_options)) +
+ '<span title="Hauteur">H :</span>' + form.text_field(:height, { :value => product.height, :size => 6, :autocomplete => :off }.merge(text_field_options)) +
'</span>&nbsp;mm
</span>'
else
@@ -33,7 +33,7 @@ def validates_source_attachment_content_type
end
def formatted_created_at
- created_at.humanize
+ I18n.l(created_at, :format => :long) if created_at
end
def formatted_image_for_press_proof_path
@@ -28,7 +28,7 @@ class Invoice < ActiveRecord::Base
# status
STATUS_CONFIRMED = 'confirmed'
STATUS_CANCELLED = 'cancelled'
- STATUS_SENDED = 'sended' # rename 'sended' to 'sent'
+ STATUS_SENDED = 'sended' # TODO rename 'sended' to 'sent'
STATUS_ABANDONED = 'abandoned'
STATUS_DUE_DATE_PAID = 'due_date_paid'
STATUS_TOTALLY_PAID = 'totally_paid'
@@ -364,7 +364,7 @@ class Invoice < ActiveRecord::Base
after_save :save_due_date_to_pay
after_save :save_delivery_note_invoices
- after_update :update_invoice_step_status
+ after_save :update_invoice_step_status
after_update :update_payment_step_status
before_destroy :can_be_deleted?
@@ -986,17 +986,32 @@ def totally_pay(attributes)
end
end
+ def invoice_step(force_reload = false)
+ @invoice_step = nil if force_reload
+ @invoice_step ||= (order && order.invoicing_step && order.invoicing_step.invoice_step)
+ end
+
+ def payment_step(force_reload = false)
+ @payment_step = nil if force_reload
+ @payment_step ||= (order && order.invoicing_step && order.invoicing_step.payment_step)
+ end
+
#TODO test this method
def invoice_step_open?
- order && order.invoicing_step && order.invoicing_step.invoice_step && !order.invoicing_step.invoice_step.terminated?
+ invoice_step && !invoice_step.terminated?
+ end
+
+ #TODO test this method
+ def payment_step_open?
+ payment_step && !payment_step.terminated?
end
def factorised?
- factor_id
+ !factor_id.nil?
end
def was_factorised?
- factor_id_was
+ !factor_id_was.nil?
end
def deposit_invoice?
@@ -1173,35 +1188,35 @@ def can_be_confirmed?
end
def can_be_cancelled?
- !new_record? and ( was_confirmed? or was_sended? ) and invoice_step_open?
+ !new_record? and ( was_confirmed? or was_sended? ) and (invoice_step_open? or payment_step_open?)
end
def can_be_sended?
was_confirmed? and invoice_step_open?
end
def can_be_abandoned?
- ( was_factorised? and was_factoring_recovered? ) or ( !was_factorised? and ( was_sended? or was_due_date_paid? ) ) and invoice_step_open?
+ ( was_factorised? and was_factoring_recovered? ) or ( !was_factorised? and ( was_sended? or was_due_date_paid? ) ) and payment_step_open?
end
def can_be_factoring_paid?
- was_factorised? and was_sended? and invoice_step_open?
+ was_factorised? and was_sended? and payment_step_open?
end
def can_be_factoring_recovered?
- was_factoring_paid? and invoice_step_open?
+ was_factoring_paid? and payment_step_open?
end
def can_be_factoring_balance_paid?
- invoice_step_open? and was_factoring_paid? or was_factoring_recovered? or ( was_factorised? and was_abandoned? )
+ payment_step_open? and was_factoring_paid? or was_factoring_recovered? or ( was_factorised? and was_abandoned? )
end
def can_be_due_date_paid?
- invoice_step_open? and !was_factorised? and ( was_sended? or was_due_date_paid? or was_abandoned? ) and unpaid_due_dates.count > 1
+ payment_step_open? and !was_factorised? and ( was_sended? or was_due_date_paid? or was_abandoned? ) and unpaid_due_dates.count > 1
end
def can_be_totally_paid?
- invoice_step_open? and !was_factorised? and ( was_sended? or was_due_date_paid? or was_abandoned? ) and unpaid_due_dates.count == 1
+ payment_step_open? and !was_factorised? and ( was_sended? or was_due_date_paid? or was_abandoned? ) and unpaid_due_dates.count == 1
end
def dunning_level
@@ -1284,18 +1299,28 @@ def awaiting_payment_total_counter # @override (active_counter)
end
private
- def update_invoice_step_status
- # if was_totally_paid? and order.unpaid_amount <= 0
- if totally_paid? and !was_totally_paid? and order.unbilled_amount < 1 and (order.unpaid_amount - already_paid_amount) < 1 # we put '<1' instead of '<=0' because sometimes, difference between the 2 values is very small and condition is false
- order.invoicing_step.invoice_step.terminated!
- order.invoicing_step.payment_step.terminated!
-
- order.complete!
+ def update_invoice_step_status #OPTIMIZE it would be more appropriate and logical to move this method to InvoiceStep, and to call the method from here (or anywhere)
+ if invoice_step.unstarted? || invoice_step.pending?
+ invoice_step.in_progress!
+
+ elsif !invoice_step.terminated?
+ invoice_step.terminated! if order.unbilled_amount < 1 && order.invoices(true).billed.reject(&:sended_on_was).empty? # we put '<1' instead of '<=0' because sometimes, difference between the 2 values is very small and condition is false
end
end
- def update_payment_step_status
- #TODO split invoice_step on invoice_step + payment_step
+ def update_payment_step_status #OPTIMIZE it would be more appropriate and logical to move this method to PaymentStep, and to call the method from here (or anywhere)
+ if payment_step.unstarted?
+ payment_step.pending! if sended?
+
+ elsif payment_step.pending?
+ payment_step.in_progress! if due_date_paid? || totally_paid? || factoring_paid?
+
+ elsif !payment_step.terminated?
+ if totally_paid? && order.unbilled_amount < 1 and (order.unpaid_amount - already_paid_amount) < 1 # we put '<1' instead of '<=0' because sometimes, difference between the 2 values is very small and condition is false
+ payment_step.terminated!
+ order.complete!
+ end
+ end
end
def message_for_validates_date(attribute, error_type, context, restriction)
@@ -85,7 +85,7 @@ class Quote < ActiveRecord::Base
x.validates_presence_of :commercial_actor, :if => :commercial_actor_id
x.validates_numericality_of :prizegiving, :carriage_costs, :validity_delay
- x.validates_numericality_of :deposit, :greater_than_or_equal_to => 0, :less_than_or_equal_to => 100
+ x.validates_numericality_of :deposit, :greater_than_or_equal_to => 0, :less_than => 100
x.validates_inclusion_of :validity_delay_unit, :in => VALIDITY_DELAY_UNITS.values
@@ -5,7 +5,7 @@ graphic_item = graphic_item_additional_infos
<p>
<%= form.label :created_at %>
- <%= form.strong(graphic_item.created_at.humanize) if graphic_item.created_at %>
+ <%= form.strong(l(graphic_item.created_at, :format => :long)) if graphic_item.created_at %>
</p>
<p>
<%= form.label :creator %>
@@ -51,7 +51,7 @@ graphic_item = graphic_item_infos
<% unless graphic_item.new_record? %>
<p>
<%= form.label :version %>
- <%= form.strong graphic_item.current_version.created_at.humanize %>
+ <%= form.strong l(graphic_item.current_version.created_at, :format => :long) %>
</p>
<div class="resource document">
<div class="thumb">
@@ -9,16 +9,16 @@ due_date = invoice.upcoming_due_date || invoice.due_dates.last
<tr class="invoice <%= invoice.status %>_invoice" title="<%= h(status) %>">
<td class="selector"><%= context_menu(invoice, 'invoice') %></td>
<td class="reference text"><%= link_to(invoice.reference_or_id, order_invoicing_step_invoice_step_invoice_path(order, invoice)) %></td>
- <td class="published_on"><%= invoice.published_on.humanize if invoice.published_on and invoice.confirmed_at %></td>
+ <td class="published_on"><%= l(invoice.published_on, :format => :short) if invoice.published_on and invoice.confirmed_at %></td>
<td class="invoice_type"><%= invoice.invoice_type.title %></td>
<td class="net_to_paid"><%= invoice.net_to_paid.to_f.round_to(2).to_s(2) %></td>
<td class="number_of_due_dates"><%= invoice.number_of_due_dates %></td>
- <td class="due_date"><%= due_date.date.humanize %></td>
+ <td class="due_date"><%= l(due_date.date, :format => :short) %></td>
<td class="due_date_net_to_paid"><%= due_date.net_to_paid.to_f.round_to(2).to_s(2) %></td>
- <td class="sended_on"><%= invoice.sended_on.humanize if invoice.sended_on %></td>
+ <td class="sended_on"><%= l(invoice.sended_on, :format => :short) if invoice.sended_on %></td>
<% if order.customer.factorised? %>
<td>#TODO</td>
<% end %>
- <td class="totally_paid_on"><%= invoice.was_totally_paid_on.humanize if invoice.was_totally_paid? %></td>
+ <td class="totally_paid_on"><%= l(invoice.was_totally_paid_on, :format => :short) if invoice.was_totally_paid? %></td>
<td class="status"><%= status %></td>
</tr>
@@ -5,13 +5,13 @@ quote = quote_footer
<p>
<%= form.label :deposit, 'Acompte (%) :' %>
- <%= form.form_or_view(form.text_field(:deposit, :value => (quote.deposit ? quote.deposit.to_f.round_to(2).to_s(2) : ''), :size => 5, :placeholder => "0 - 100"), strong(quote.deposit.to_f.round_to(2).to_s(2))) %>
+ <%= form.form_or_view(form.text_field(:deposit, :value => (quote.deposit ? quote.deposit.to_f.round_to(2).to_s(2) : ''), :size => 3), strong(quote.deposit.to_f.round_to(2).to_s(2))) %>
</p>
<p>
<%= form.label :validity_delay %>
<% if form.form_view? %>
- <%= form.text_field :validity_delay, :size => 2 %> <%= form.select :validity_delay_unit, Quote::VALIDITY_DELAY_UNITS %>
+ <%= form.text_field :validity_delay, :size => 3 %> <%= form.select :validity_delay_unit, Quote::VALIDITY_DELAY_UNITS %>
<% else %>
<%= strong display_validity_delay_and_unit_for(quote) %>
<% end %>
@@ -142,6 +142,7 @@ fr:
created_at: "Date de création"
customer: "Client"
customer_needs: "Besoins du client"
+ order_contact: "Contact"
order_type: "Type de dossier"
previsional_delivery: "Date prévisionnelle de livraison"
quotation_deadline: "Date butoir d'envoi du devis"
@@ -340,7 +340,8 @@
map.resources :end_products
map.product_reference_manager "product_reference_manager", :controller => "product_reference_manager"
- map.goods 'goods', :controller => 'products_catalog' #default page for products
+ map.products_catalog 'products_catalog', :controller => 'products_catalog'
+ map.goods 'goods', :controller => 'product_reference_manager' #default page for products
# AJAX REQUESTS
map.update_product_reference_sub_categories 'update_product_reference_sub_categories', :controller => 'product_reference_categories',
Oops, something went wrong.

0 comments on commit 399e9c6

Please sign in to comment.