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
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)
toreturn.name = name
toreturn.date_invoice=date_invoice
toreturn.type = o[:type]
curr = ResCurrency.find(:first, :domain=>[['code','=',o[:currency_code]]])
if curr :
toreturn.currency_id = curr.id
else
raise "!!! --- HELPER ERROR :#{o[:currency_code]} currency not found"
end
toreturn.create
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
account_id = AccountAccount.find(:first, :domain=>[['type','=','other'],['reconcile','=',false]]).id
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