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.

38 lines
1.5 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." "group_validate_invoice_negative_total_amount"
  9. ):
  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(
  18. _(
  19. "The field Vendor is required, please complete it to validate the Vendor Bill."
  20. )
  21. )
  22. if to_open_invoices.filtered(lambda inv: inv.state != "draft"):
  23. raise UserError(
  24. _("Invoice must be in draft state in order to validate it.")
  25. )
  26. if to_open_invoices.filtered(lambda inv: not inv.account_id):
  27. raise UserError(
  28. _(
  29. "No account was found to create the invoice, be sure you have installed a chart of account."
  30. )
  31. )
  32. to_open_invoices.action_date_assign()
  33. to_open_invoices.action_move_create()
  34. return to_open_invoices.invoice_validate()