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.6 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 openerp import api, models, _
  5. class AccountInvoice(models.Model):
  6. _inherit = 'account.invoice'
  7. @api.multi
  8. def invoice_open(self):
  9. if self.env.context.get('bypass_risk', False):
  10. return self.signal_workflow('invoice_open')
  11. for invoice in self:
  12. partner = invoice.partner_id
  13. exception_msg = ""
  14. if partner.risk_exception:
  15. exception_msg = _("Financial risk exceeded.\n")
  16. elif partner.risk_invoice_open_limit and (
  17. (partner.risk_invoice_open + invoice.amount_total) >
  18. partner.risk_invoice_open_limit):
  19. exception_msg = _(
  20. "This invoice exceeds the open invoices risk.\n")
  21. elif 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' % (self._model, invoice.id),
  32. 'continue_method': 'invoice_open',
  33. }).action_show()
  34. return self.signal_workflow('invoice_open')