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.

39 lines
1.8 KiB

  1. # Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo import _, api, models
  4. class AccountInvoice(models.Model):
  5. _inherit = 'account.invoice'
  6. @api.multi
  7. def action_invoice_open(self):
  8. if self.env.context.get('bypass_risk', False):
  9. return super(AccountInvoice, self).action_invoice_open()
  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. # If risk_invoice_draft_include this invoice included in risk_total
  21. elif not partner.risk_invoice_draft_include and (
  22. partner.risk_invoice_open_include and
  23. (partner.risk_total + invoice.amount_total) >
  24. partner.credit_limit):
  25. exception_msg = _(
  26. "This invoice exceeds the financial risk.\n")
  27. if exception_msg:
  28. return self.env['partner.risk.exceeded.wiz'].create({
  29. 'exception_msg': exception_msg,
  30. 'partner_id': partner.id,
  31. 'origin_reference':
  32. '%s,%s' % ('account.invoice', invoice.id),
  33. 'continue_method': 'action_invoice_open',
  34. }).action_show()
  35. return super(AccountInvoice, self).action_invoice_open()