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.7 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from odoo import _, api, models
  5. class AccountInvoice(models.Model):
  6. _inherit = 'account.invoice'
  7. @api.multi
  8. def action_invoice_open(self):
  9. if not self.env.context.get('bypass_risk', False):
  10. for invoice in self:
  11. partner = invoice.partner_id.commercial_partner_id
  12. exception_msg = ""
  13. if partner.risk_exception:
  14. exception_msg = _("Financial risk exceeded.\n")
  15. elif partner.risk_invoice_open_limit and (
  16. (partner.risk_invoice_open + invoice.amount_total) >
  17. partner.risk_invoice_open_limit):
  18. exception_msg = _(
  19. "This invoice exceeds the open invoices risk.\n")
  20. elif not partner.risk_invoice_draft_include and (
  21. partner.risk_invoice_open_include and
  22. (partner.risk_total + invoice.amount_total) >
  23. partner.credit_limit):
  24. exception_msg = _(
  25. "This invoice exceeds the financial risk.\n")
  26. if exception_msg:
  27. return self.env['partner.risk.exceeded.wiz'].create({
  28. 'exception_msg': exception_msg,
  29. 'partner_id': partner.id,
  30. 'origin_reference':
  31. '%s,%s' % ('account.invoice', invoice.id),
  32. 'continue_method': 'action_invoice_open',
  33. }).action_show()
  34. return super(AccountInvoice, self).action_invoice_open()