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.

46 lines
1.8 KiB

  1. from odoo import api, fields, models, _
  2. from odoo.tools import float_compare
  3. from odoo.exceptions import UserError
  4. class AccountInvoice(models.Model):
  5. _inherit = "account.invoice"
  6. @api.multi
  7. def action_invoice_open(self):
  8. to_open_invoices = self.filtered(lambda inv: inv.state != "open")
  9. if self.user_has_groups(
  10. "beesdoo_account." "group_validate_invoice_negative_total_amount"
  11. ) and to_open_invoices.filtered(
  12. lambda inv: float_compare(
  13. inv.amount_total,
  14. 0.0,
  15. precision_rounding=inv.currency_id.rounding,
  16. )
  17. == -1
  18. ):
  19. return self.action_invoice_negative_amount_open(to_open_invoices)
  20. return super(AccountInvoice, self).action_invoice_open()
  21. @api.multi
  22. def action_invoice_negative_amount_open(self, to_open_invoices):
  23. """Similar to action_invoice_open without UserError on an invoice with a negative total amount"""
  24. if to_open_invoices.filtered(lambda inv: not inv.partner_id):
  25. raise UserError(
  26. _(
  27. "The field Vendor is required, please complete it to validate the Vendor Bill."
  28. )
  29. )
  30. if to_open_invoices.filtered(lambda inv: inv.state != "draft"):
  31. raise UserError(
  32. _("Invoice must be in draft state in order to validate it.")
  33. )
  34. if to_open_invoices.filtered(lambda inv: not inv.account_id):
  35. raise UserError(
  36. _(
  37. "No account was found to create the invoice, be sure you have installed a chart of account."
  38. )
  39. )
  40. to_open_invoices.action_date_assign()
  41. to_open_invoices.action_move_create()
  42. return to_open_invoices.invoice_validate()