app/controllers/sales_controller.rb
# Actualizar valores de la venta (valor, valor total, descuento)
Actualizar valores de la venta (valor, valor total, descuento)
Actualizar valores de la venta ( valor valor total descuento )
def update_totals
		set_sale
		@sale.amount = 0
		for line_item in @sale.items
			@sale.amount += line_item.total_price
		end
		total_amount = @sale.amount
		if @sale.discount.blank?
			@sale.total_amount = total_amount
		else
			discount_amount = total_amount * @sale.discount
			@sale.total_amount = total_amount - discount_amount
		end
		@sale.save
	end
def update_totals set_sale @sale . amount = 0 for line_item in @sale . items @sale . amount += line_item . total_price end total_amount = @sale . amount if @sale . discount . blank? @sale . total_amount = total_amount else discount_amount = total_amount * @sale . discount @sale . total_amount = total_amount - discount_amount end @sale . save end
Actualizar valores de la venta (valor, valor total, descuento)
Actualizar valores de la venta ( valor valor total descuento )