Hello Joao,
The function action_invoice_sent return an action in dictionary format. You have to return the result of this function to perform the action.
def my_action(self):
action = invoice_object.action_invoice_sent()
return action
Otherwise, if you want to perform sending the Invoice directly (without opening the wizard), so you will have to create account.invoice.send object with the following context values:
def action_send_invoice_directly(self):
# Search for your invoice_object
invoice_object = ...
template = self.env.ref('account.email_template_edi_invoice', raise_if_not_found=False)
lang = False
if template:
lang = template._render_lang(invoice_object.ids)[invoice_object.id]
if not lang:
lang = get_lang(self.env).code
ctx = dict(
mark_invoice_as_sent=True,
active_ids=invoice_object.ids, # Use ids and not id (it has to be a list)
custom_layout="mail.mail_notification_paynow",
model_description=invoice_object.with_context(lang=lang).type_name,
force_email=True,
default_res_model='account.move',
default_use_template=bool(template),
)
values = {
'model': 'account.move',
'res_id': invoice_object.id,
'template_id': template and template.id or False,
'composition_mode': 'comment',
}
wizard = self.env['account.invoice.send'].with_context(ctx).create(values)
wizard._compute_composition_mode()
wizard.onchange_template_id()
wizard.onchange_is_email()
# If you want to send without printing the invoice use this function
wizard._send_email()
# If you want to send and print use this function
# wizard.send_and_print_action()
Hope my answer helps you.