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.

76 lines
2.8 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 exceptions
  5. from openerp.tests.common import SavepointCase
  6. class TestPartnerStocklRisk(SavepointCase):
  7. @classmethod
  8. def setUpClass(cls):
  9. super(TestPartnerStocklRisk, cls).setUpClass()
  10. cls.partner = cls.env['res.partner'].create({
  11. 'name': 'Partner test',
  12. 'customer': True,
  13. })
  14. cls.product = cls.env.ref('product.product_product_36')
  15. cls.quant = cls.env['stock.quant'].create({
  16. 'qty': 100,
  17. 'location_id': cls.env.ref('stock.stock_location_stock').id,
  18. 'product_id': cls.product.id,
  19. })
  20. cls.picking = cls.env['stock.picking'].create({
  21. 'picking_type_id': cls.env.ref('stock.picking_type_out').id,
  22. 'location_id': cls.env.ref('stock.stock_location_stock').id,
  23. 'location_dest_id':
  24. cls.env.ref('stock.stock_location_customers').id,
  25. 'partner_id': cls.partner.id,
  26. })
  27. cls.move = cls.env['stock.move'].create({
  28. 'name': '/',
  29. 'picking_id': cls.picking.id,
  30. 'product_uom_qty': 10,
  31. 'product_uom': cls.product.uom_id.id,
  32. 'location_id': cls.env.ref('stock.stock_location_stock').id,
  33. 'location_dest_id':
  34. cls.env.ref('stock.stock_location_customers').id,
  35. 'product_id': cls.product.id,
  36. })
  37. cls.env.user.lang = 'en_US'
  38. def test_stock_move_ok(self):
  39. self.move.action_done()
  40. def test_stock_move_error(self):
  41. self.partner.risk_exception = True
  42. self.move.partner_id = self.partner
  43. with self.assertRaises(exceptions.UserError):
  44. self.move.action_done()
  45. def test_stock_picking_ok(self):
  46. self.picking.action_assign()
  47. self.picking.force_assign()
  48. self.picking.action_confirm()
  49. def test_stock_picking_error(self):
  50. self.partner.risk_exception = True
  51. res = self.picking.action_assign()
  52. self.assertEqual(res['name'], 'Partner risk exceeded')
  53. res = self.picking.force_assign()
  54. self.assertEqual(res['name'], 'Partner risk exceeded')
  55. res = self.picking.action_confirm()
  56. self.assertEqual(res['name'], 'Partner risk exceeded')
  57. def test_do_new_transfer_ok(self):
  58. self.picking.action_assign()
  59. self.picking.pack_operation_product_ids[:1].qty_done = 5
  60. self.picking.do_new_transfer()
  61. def test_do_new_transfer_error(self):
  62. self.picking.action_assign()
  63. self.picking.pack_operation_product_ids[:1].qty_done = 5
  64. self.partner.risk_exception = True
  65. res = self.picking.do_new_transfer()
  66. self.assertEqual(res['name'], 'Partner risk exceeded')