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.

97 lines
3.4 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
  3. # Copyright 2017 David Vidal <david.vidal@tecnativa.com>
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  5. from odoo import exceptions
  6. from odoo.tests import common
  7. class TestPartnerStocklRisk(common.SavepointCase):
  8. @classmethod
  9. def setUpClass(cls):
  10. super(TestPartnerStocklRisk, cls).setUpClass()
  11. cls.partner = cls.env['res.partner'].create({
  12. 'name': 'Partner test',
  13. 'customer': True,
  14. })
  15. cls.product = cls.env['product.product'].create({
  16. 'name': 'Test product',
  17. })
  18. cls.location = cls.env['stock.location'].create({
  19. 'name': 'Test location',
  20. 'usage': 'internal',
  21. })
  22. cls.location_customers = cls.env['stock.location'].create({
  23. 'name': 'Test location customers',
  24. 'usage': 'customer',
  25. })
  26. cls.sequence = cls.env['ir.sequence'].create({
  27. 'name': 'test seq',
  28. 'implementation': 'standard',
  29. 'padding': 1,
  30. 'number_increment': 1,
  31. })
  32. cls.stock_picking_type = cls.env['stock.picking.type'].create({
  33. 'name': 'Test picking type',
  34. 'code': 'outgoing',
  35. 'sequence_id': cls.sequence.id,
  36. })
  37. cls.quant = cls.env['stock.quant'].create({
  38. 'qty': 100,
  39. 'location_id': cls.location.id,
  40. 'product_id': cls.product.id,
  41. })
  42. cls.picking = cls.env['stock.picking'].create({
  43. 'picking_type_id': cls.stock_picking_type.id,
  44. 'location_id': cls.location.id,
  45. 'location_dest_id': cls.location_customers.id,
  46. 'partner_id': cls.partner.id,
  47. })
  48. cls.move = cls.env['stock.move'].create({
  49. 'name': '/',
  50. 'picking_id': cls.picking.id,
  51. 'product_uom_qty': 10,
  52. 'product_uom': cls.product.uom_id.id,
  53. 'location_id': cls.location.id,
  54. 'location_dest_id':
  55. cls.location_customers.id,
  56. 'product_id': cls.product.id,
  57. })
  58. cls.env.user.lang = 'en_US'
  59. def test_stock_move_ok(self):
  60. self.move.action_done()
  61. def test_stock_move_error(self):
  62. self.partner.risk_exception = True
  63. self.move.partner_id = self.partner
  64. with self.assertRaises(exceptions.UserError):
  65. self.move.action_done()
  66. def test_stock_picking_ok(self):
  67. self.picking.action_assign()
  68. self.picking.force_assign()
  69. self.picking.action_confirm()
  70. def test_stock_picking_error(self):
  71. self.partner.risk_exception = True
  72. res = self.picking.action_assign()
  73. self.assertEqual(res['name'], 'Partner risk exceeded')
  74. res = self.picking.force_assign()
  75. self.assertEqual(res['name'], 'Partner risk exceeded')
  76. res = self.picking.action_confirm()
  77. self.assertEqual(res['name'], 'Partner risk exceeded')
  78. def test_do_new_transfer_ok(self):
  79. self.picking.action_assign()
  80. self.picking.pack_operation_product_ids[:1].qty_done = 5
  81. self.picking.do_new_transfer()
  82. def test_do_new_transfer_error(self):
  83. self.picking.action_assign()
  84. self.picking.pack_operation_product_ids[:1].qty_done = 5
  85. self.partner.risk_exception = True
  86. res = self.picking.do_new_transfer()
  87. self.assertEqual(res['name'], 'Partner risk exceeded')