# File lib/Helpers/AccountInvoice.rb, line 51
      def self.create_invoice_with_currency(name, partner, options={}, *args)
          o = {:type=>'out_invoice', :currency_code=>'EUR', :date=>false, :amount=>false, :account=>false}.merge(options)
           if o[:date] :
                date_invoice = Date.parse(str=o[:date]).to_s
            else
                date_invoice = Date.today.to_s
            end
          
          toreturn = AccountInvoice.new()
          
          unless partner.class  == ResPartner :
              raise "!!! --- HELPER ERROR :create_cust_invoice_with_currency received a #{partner.class.to_s} instead of ResPartner" 
          end 
          # Set partner
          if (partner.address.length >0) :
              toreturn.partner_id = partner.id
          else
              raise "!!! --- HELPER ERROR :create_cust_invoice_with_currency received a partner : #{partner.name} without adresses"
          end
          toreturn.on_change('onchange_partner_id', :partner_id ,1, o[:type], partner.id, date_invoice, false, false)
          
          # Set name & date
          toreturn.name = name
          toreturn.date_invoice=date_invoice

          # Set type of invoice
          toreturn.type = o[:type]
          curr =  ResCurrency.find(:first, :domain=>[['code','=',o[:currency_code]]])
          # Set currency
          if curr : 
              toreturn.currency_id = curr.id
          else
              raise "!!! --- HELPER ERROR :#{o[:currency_code]} currency not found"
          end
          
          # Set amount and line if asked for
          toreturn.create

          # toreturn.type = o[:type]
          # toreturn.save
          if o[:amount] :
              
              if ['in_invoice', 'in_refund'].include? o[:type] :
                  toreturn.check_total = o[:amount]
              end
              if o[:account] :
                  unless account.class  == AccountAccount :
                      raise "!!! --- HELPER ERROR :create_cust_invoice_with_currency received a #{o[:account].class.to_s} instead of AccountAccount" 
                  end
                  account_id = o[:account].id
              else
                  # If no account, take on of type 'other' and a non-reconciliable account
                  account_id = AccountAccount.find(:first, :domain=>[['type','=','other'],['reconcile','=',false]]).id
                  # Create a line = amount for the created invoice
                  line=AccountInvoiceLine.new(
                    :account_id => account_id,
                    :quantity => 1,
                    :name => name+' line',
                    :price_unit => o[:amount],
                    :invoice_id => toreturn.id
                  )
                  line.create
              end
          end
          toreturn.save 
          return toreturn
      end