Skip to content

Commit

Permalink
[REF] Open Invoice or Fiscal Document
Browse files Browse the repository at this point in the history
  • Loading branch information
renatonlima committed Feb 25, 2021
1 parent 5617e92 commit dffa676
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions l10n_br_sale/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,28 @@ def action_invoice_create(self, grouped=False, final=False):
inv_line.invoice_id = invoice.id

return inv_ids

@api.multi
def action_view_invoice(self):
action = super().action_view_invoice()
invoices = self.mapped('invoice_ids')
if any(invoices.filtered(lambda i: i.document_type_id)):
action = self.env.ref(
'l10n_br_account.fiscal_invoice_action').read()[0]
if len(invoices) > 1:
action['domain'] = [('id', 'in', invoices.ids)]
elif len(invoices) == 1:
form_view = [
(self.env.ref('l10n_br_account.fiscal_invoice_form').id,
'form')
]
if 'views' in action:
action['views'] = form_view + [
(state,view) for state,view in action['views']
if view != 'form']
else:
action['views'] = form_view
action['res_id'] = invoices.ids[0]
else:
action = {'type': 'ir.actions.act_window_close'}
return action

0 comments on commit dffa676

Please sign in to comment.