odoo 16 printing invoice by method

73 Views Asked by At

i coded a method to post invoices like this:

`def print_invoice(self):

        _logger.info('-#-#-#-#--#-#-#-in print_invoice')

        line_array = []

        for ar in self.ks_paketareale:

            val = (0, None, {

                'product_id': ar.ks_areal.id,

                'name': ar.name,

                'quantity': ar.ks_anzahl_behandlung,

                'price_unit': ar.ks_areal.list_price,

                'price_subtotal': ar.ks_areal.list_price * ar.ks_anzahl_behandlung,

            })

            line_array.append(val)

        iid = self.env['account.move'].create({

                'move_type': 'out_invoice',

                'invoice_date': fields.Date.context_today(self),

                'partner_id': self.partner_id.id,

                #'currency_id': self.currency_id.id,

                'amount_total': self.ks_rabattpreis,

                'invoice_line_ids': line_array,

            },

        )

        iid.action_post()

        action = iid.action_invoice_print()

        action.update({'close_on_report_download': True})`

creating the invoice works and the created invoice is posted.

but the call of iid.action_invoice_print() doesnt work. nothing happens. i was excpecting that the download of the invoice starts because in the method  _print_document in accout_move the method action_invoice_print is called. whats going wrong? thx for any help

overriding action_post and action_print_invoice

1

There are 1 best solutions below

0
klausjulius On

Levizar’s comment was the crucial clue for solving my problem:

You forgot to return the action. If you don't return the action, the function returns None and the framework has no clue you're trying to call an action.