   setExchange: ->
     rate = ($(@el).find("#exchange_rate").val() * 1).round(4)
     @model.set({exchange_rate: rate})
-    @.closeDialog()
   # present dialog
   openDialog: ->
-    $(@el).find("#exchange_rate").val(@model.get("exchange_rate"))
-    $(@el).find("span.currency_symbol").html(@model.get("currency_symbol"))
-    $( @el ).dialog("open")
+    @el.find("#exchange_rate").val(@model.get("exchange_rate"))
+    @el.find("span.currency_symbol").html(@model.get("currency_symbol"))
+    @el.dialog("open")
   closeDialog: ->
-    $( @el ).dialog("close")
+    @.setExchange()
+    @el.dialog("close")
 
 window.ExchangeRateDialog = ExchangeRateDialog
 

    @model.bind("change:currency_id", (model, name)->
      unless self.model.get("currency_id") == self.model.get("default_currency")
        self.openDialog()
      else
        self.model.set({exchange_rate: 1})
        self.setLabel()

    self = @
    $('#transaction_currency_id').bind 'change keyup', (event)->
      self.set({currency_id: $(this).val() * 1})
  # Sets the discount
  setDiscount: ->
    discount = @.get("subtotal") * @.get("discount")
