I'm trying to redirect to view account.view_move_form after invoicing several POS orders and merging those invoices into one, but after the action is done it stays at POS order tree view. Here is my code:
def invoice_and_merge(self):
partner_id = self[0].partner_id
account_moves = []
account_moves_ids = []
wizard = {}
for pedido in self:
if pedido.partner_id != partner_id:
raise UserError('Todas las facturas debes ser del mismo cliente
account_moves.append(pedido.action_pos_order_invoice())
for move in account_moves:
account_moves_ids.append(move['res_id'])
factura = self.env['account.move'].search([('id', '=', move['res_id'])])
factura.button_draft()
wizard['merge_type'] = 'cancel'
wizard['partner_id'] = partner_id.id
merge_invoice = self.env['sh.minv.merge.invoice.wizard'].with_context({'active_ids': account_moves_ids}).create(wizard)
# This is a third party app that merges serveral invoices into a new one and returns a tree view with all new invoices
ret = merge_invoice.action_merge_invoice()
facturas = self.env['account.move'].search([('id','in', ret['domain'][0][2])])
id = 0
for factura in facturas:
if factura.name == '/':
self.account_move = factura
id = factura.id
factura.action_post()
else:
factura.write({'agrupado': True})
# Return form view with the new invoice
return {
'name': _('Customer Invoice'),
'view_mode': 'form',
'view_id': self.env.ref('account.view_move_form').id,
'res_model': 'account.move',
'context': "{'move_type':'out_invoice'}",
'type': 'ir.actions.act_window',
'nodestroy': True,
'res_id': id,
'target': 'current'
}