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.

40 lines
1.7 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 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.commercial_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. # If risk_invoice_draft_include this invoice included in risk_total
  22. elif not partner.risk_invoice_draft_include and (
  23. partner.risk_invoice_open_include and
  24. (partner.risk_total + invoice.amount_total) >
  25. partner.credit_limit):
  26. exception_msg = _(
  27. "This invoice exceeds the financial risk.\n")
  28. if exception_msg:
  29. return self.env['partner.risk.exceeded.wiz'].create({
  30. 'exception_msg': exception_msg,
  31. 'partner_id': partner.id,
  32. 'origin_reference':
  33. '%s,%s' % (self._model, invoice.id),
  34. 'continue_method': 'invoice_open',
  35. }).action_show()
  36. return self.signal_workflow('invoice_open')