1

I am developing a custom module.

I tried to add it through an object button with the following code but doesn't seem to work

    def create_invoice(self):
        rslt = self.env['account.invoice'].create({
                    'partner_id': self.instructor.id,
                    'name': 'customer invoice',
                    'type': 'out_invoice',
                    'date_invoice': 'create_date'
                })
        return rslt

How can I add a button that generates an invoice?

Ardent Coder
  • 3,777
  • 9
  • 27
  • 53
desu
  • 64
  • 8

1 Answers1

3

desu

From Odoo13 there is a change in invoice object, It is now account.move instead of account.invoice.You can take this reference demo example.

invoice = self.env['account.move'].create({
    'type': 'out_invoice', 
    'journal_id': journal.id,
    'partner_id': product_id.id,
    'invoice_date': date_invoice,
    'date': date_invoice,
    'invoice_line_ids': [(0, 0, {
        'product_id': product_id.id,
        'quantity': 40.0,
        'name': 'product test 1',
        'discount': 10.00,
        'price_unit': 2.27,
    })]
})
Kenly
  • 24,317
  • 7
  • 44
  • 60
Dipen Shah
  • 2,396
  • 2
  • 9
  • 21