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.

68 lines
2.5 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, exceptions, models
  5. class StockMove(models.Model):
  6. _inherit = 'stock.move'
  7. @api.multi
  8. def action_done(self):
  9. if not self.env.context.get('bypass_risk'):
  10. moves = self.filtered(lambda x: (
  11. x.location_dest_id.usage == 'customer' and
  12. x.partner_id.risk_exception
  13. ))
  14. if moves:
  15. raise exceptions.UserError(
  16. _("Financial risk exceeded in partner:\n%s") %
  17. moves.mapped('partner_id.name'))
  18. return super(StockMove, self).action_done()
  19. class StockPicking(models.Model):
  20. _inherit = 'stock.picking'
  21. @api.multi
  22. def show_risk_wizard(self, continue_method):
  23. return self.env['partner.risk.exceeded.wiz'].create({
  24. 'exception_msg': _("Financial risk exceeded \n"),
  25. 'partner_id': self.partner_id.id,
  26. 'origin_reference': '%s,%s' % (self._model, self.id),
  27. 'continue_method': continue_method,
  28. }).action_show()
  29. @api.multi
  30. def action_confirm(self):
  31. if not self.env.context.get('bypass_risk'):
  32. if (self.location_dest_id.usage == 'customer' and
  33. self.partner_id.risk_exception):
  34. return self.show_risk_wizard('action_confirm')
  35. return super(StockPicking, self).action_confirm()
  36. @api.multi
  37. def action_assign(self):
  38. if not self.env.context.get('bypass_risk') and \
  39. self.filtered('partner_id.risk_exception'):
  40. params = self.env.context.get('params', {})
  41. if 'purchase.order' not in params and 'sale.order' not in params:
  42. return self.show_risk_wizard('action_assign')
  43. return super(StockPicking, self).action_assign()
  44. @api.multi
  45. def force_assign(self):
  46. if not self.env.context.get('bypass_risk'):
  47. if (self.location_dest_id.usage == 'customer' and
  48. self.partner_id.risk_exception):
  49. return self.show_risk_wizard('force_assign')
  50. return super(StockPicking, self).force_assign()
  51. @api.multi
  52. def do_new_transfer(self):
  53. if not self.env.context.get('bypass_risk'):
  54. if (self.location_dest_id.usage == 'customer' and
  55. self.partner_id.risk_exception):
  56. return self.show_risk_wizard('do_new_transfer')
  57. return super(StockPicking, self).do_new_transfer()