Odoo Help


Create new invoice by code

on 4/18/13, 1:01 PM 3,618 views

Hi...I need to call the method write of account invoice from a button. I have a form with information and i want to create a draft invoice when the button is clicked passing the values for the invoice for parameter. Thanks


Francesco OpenCode

--Francesco OpenCode--

| 6 8 9
Grottaglie, Italy
--Francesco OpenCode--

Italian Odoo (OpenERP) Modules Developer LINKEDIN: http://www.linkedin.com/in/francescoapruzzese

Francesco OpenCode
On 4/18/13, 1:21 PM

The method to create a new invoice is not write but create. Write is used to change values in existing record.

This is a basilar code to create an invoice

your_class_records = self.browse(cr, uid, ids)
for record in your_class_records:
    invoice_id = self.pool.get('account.invoice').create(cr, uid,{
        'name' : record.name,
        'date_invoice' : record.date,
    for line in record.line:
        self.pool.get('account.invoice.line).create(cr, uid,{
            'invoice_id' : invoice_id,
            'name' : line.name,
            'product_id' : line.product_id.id,


On 4/18/13, 5:35 PM

Thanks. It worked!

If my answer is the correct one, please, set it as correct so you can help user that will search the some problem in the future. If you want you can give a +1 to the answer, too...:)

Francesco OpenCode
on 4/19/13, 5:20 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 4/18/13, 1:01 PM
Seen: 3618 times
Last updated: 5/15/18, 11:36 AM