Pārlūkot izejas kodu

[Issue #2] Fixed error when deleting supplier

Jacqueline Maldonado 7 gadi atpakaļ
vecāks
revīzija
30356b4a60

+ 5 - 6
app/controllers/suppliers_controller.rb

@@ -19,8 +19,7 @@ class SuppliersController < ApplicationController
 
   # GET /suppliers/1
   # GET /suppliers/1.json
-  def show
-  end
+  def show; end
 
   # GET /suppliers/new
   def new
@@ -28,8 +27,7 @@ class SuppliersController < ApplicationController
   end
 
   # GET /suppliers/1/edit
-  def edit
-  end
+  def edit; end
 
   # POST /suppliers
   # POST /suppliers.json
@@ -84,8 +82,9 @@ class SuppliersController < ApplicationController
   # DELETE /suppliers/1.json
   def destroy
     respond_to do |format|
-      if @supplier.update_attributes(:status => 'erased')
-        @supplier.contact.update_attributes(:status => 'erased')
+      if @supplier.update_attributes(status: 'erased')
+        @supplier.contact.update_attributes(status: 'erased') if @supplier.contact.present?
+        @supplier.billing_information.update_attributes(status: 'erased') if @supplier.billing_information.present?
         @supplier.audit_comment = "El proveedor " + @supplier.nick_name + " fue dado de baja."
         format.html { redirect_to suppliers_url, warning: "El proveedor " + @supplier.nick_name + " fue dado de baja." }
         format.json { head :no_content }

+ 24 - 22
app/models/billing_information.rb

@@ -1,27 +1,29 @@
 class BillingInformation < ActiveRecord::Base
-	##--- Associaciones
-	belongs_to :customer
-	belongs_to :supplier
-	belongs_to :spmx_county, :foreign_key => "county_id"
-	belongs_to :spmx_state, :foreign_key => "state_id"
+  ##--- Associaciones
+  belongs_to :customer
+  belongs_to :supplier
+  belongs_to :spmx_county, :foreign_key => "county_id"
+  belongs_to :spmx_state, :foreign_key => "state_id"
 
-	##--- Llevar registro de Actividad del usuario
-	# audited 
+  ##--- Llevar registro de Actividad del usuario
+  # audited
 
-	##--- Validaciones previas de guardar
-	validates_presence_of :name, message: "Debe capturar el nombre de la razón social."
-	validates :rfc, :presence => {message: "Debe capturar el RFC del cliente."}, length:{ maximum: 13, too_long: "El RFC no debe ser mayor a %{count} caracteres." }
-	validates_presence_of :state_id, message: "Debe especificar el estado."
-	validates_presence_of :county_id, message: "Debe especificar el municipio."
-	# validates_presence_of :city, message: "Debe especificar la ciudad o localidad."
-	# validates_presence_of :suburb, message: "Debe especificar la colonia."
-	# validates_presence_of :address, message: "Debe capturar la dirección de la Empresa."
-	validates :zipcode, :presence => { :message => "Debe especificar el código postal"},  :numericality => { :only_integer => true, :message => "El código postal debe ser numérico.", allow_nil: true }
-	validates :num_ext,  length: { maximum: 10, too_long: "El no. ext no debe ser mayor a %{count} caracteres." }, :unless => Proc.new {|c| c.num_ext.blank?}
-	validates :num_int, length: { maximum: 10, too_long: "El no. int no debe ser mayor a %{count} caracteres." }, :unless => Proc.new {|c| c.num_int.blank?}
+  enum status: [:erased, :active, :inactive]
 
-	##--- Funciones personalizadas
-	def address_complete
-		"#{self.address} No. #{num_ext}" + (self.num_int != '' ? "Int. #{num_int}," : ",") +" C.P. #{zipcode} \n #{suburb}, #{city}, #{spmx_county.name}, #{spmx_state.name} " 
-	end
+  ##--- Validaciones previas de guardar
+  validates_presence_of :name, message: "Debe capturar el nombre de la razón social."
+  validates :rfc, :presence => {message: "Debe capturar el RFC del cliente."}, length:{ maximum: 13, too_long: "El RFC no debe ser mayor a %{count} caracteres." }
+  validates_presence_of :state_id, message: "Debe especificar el estado."
+  validates_presence_of :county_id, message: "Debe especificar el municipio."
+  # validates_presence_of :city, message: "Debe especificar la ciudad o localidad."
+  # validates_presence_of :suburb, message: "Debe especificar la colonia."
+  # validates_presence_of :address, message: "Debe capturar la dirección de la Empresa."
+  validates :zipcode, :presence => { :message => "Debe especificar el código postal"},  :numericality => { :only_integer => true, :message => "El código postal debe ser numérico.", allow_nil: true }
+  validates :num_ext,  length: { maximum: 10, too_long: "El no. ext no debe ser mayor a %{count} caracteres." }, :unless => Proc.new {|c| c.num_ext.blank?}
+  validates :num_int, length: { maximum: 10, too_long: "El no. int no debe ser mayor a %{count} caracteres." }, :unless => Proc.new {|c| c.num_int.blank?}
+
+  ##--- Funciones personalizadas
+  def address_complete
+    "#{self.address} No. #{num_ext}" + (self.num_int != '' ? "Int. #{num_int}," : ",") +" C.P. #{zipcode} \n #{suburb}, #{city}, #{spmx_county.name}, #{spmx_state.name} "
+  end
 end