You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
1.4 KiB

  1. from odoo import api, fields, models, _
  2. from odoo.exceptions import UserError
  3. class AccountInvoice(models.Model):
  4. _inherit = "account.invoice"
  5. @api.multi
  6. def action_invoice_open(self):
  7. if self.user_has_groups(
  8. 'beesdoo_account.'
  9. 'group_validate_invoice_negative_total_amount'):
  10. return self.action_invoice_negative_amount_open()
  11. return super(AccountInvoice, self).action_invoice_open()
  12. @api.multi
  13. def action_invoice_negative_amount_open(self):
  14. """Identical to action_invoice_open without UserError on an invoice with a negative total amount"""
  15. to_open_invoices = self.filtered(lambda inv: inv.state != 'open')
  16. if to_open_invoices.filtered(lambda inv: not inv.partner_id):
  17. raise UserError(_("The field Vendor is required, please complete it to validate the Vendor Bill."))
  18. if to_open_invoices.filtered(lambda inv: inv.state != 'draft'):
  19. raise UserError(_("Invoice must be in draft state in order to validate it."))
  20. if to_open_invoices.filtered(lambda inv: not inv.account_id):
  21. raise UserError(
  22. _('No account was found to create the invoice, be sure you have installed a chart of account.'))
  23. to_open_invoices.action_date_assign()
  24. to_open_invoices.action_move_create()
  25. return to_open_invoices.invoice_validate()