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.

37 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 partner.risk_invoice_open_include and (
  21. (partner.risk_total + invoice.amount_total) >
  22. partner.credit_limit):
  23. exception_msg = _(
  24. "This invoice exceeds the financial risk.\n")
  25. if exception_msg:
  26. return self.env['partner.risk.exceeded.wiz'].create({
  27. 'exception_msg': exception_msg,
  28. 'partner_id': partner.id,
  29. 'origin_reference':
  30. '%s,%s' % ('account.invoice', invoice.id),
  31. 'continue_method': 'action_invoice_open',
  32. }).action_show()
  33. return super(AccountInvoice, self).action_invoice_open()