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.

62 lines
2.4 KiB

9 years ago
  1. from openerp.exceptions import ValidationError
  2. from openerp.addons.sale.tests.test_sale_order import TestSaleOrder
  3. class TestSaleException(TestSaleOrder):
  4. def test_sale_order_exception(self):
  5. exception = self.env.ref('sale_exception.excep_no_zip')
  6. exception.active = True
  7. partner = self.env.ref('base.res_partner_1')
  8. partner.zip = False
  9. p = self.env.ref('product.product_product_6')
  10. so = self.env['sale.order'].create({
  11. 'partner_id': partner.id,
  12. 'partner_invoice_id': partner.id,
  13. 'partner_shipping_id': partner.id,
  14. 'order_line': [(0, 0, {'name': p.name,
  15. 'product_id': p.id,
  16. 'product_uom_qty': 2,
  17. 'product_uom': p.uom_id.id,
  18. 'price_unit': p.list_price})],
  19. 'pricelist_id': self.env.ref('product.list0').id,
  20. })
  21. # confirm quotation
  22. so.action_confirm()
  23. self.assertTrue(so.state == 'draft')
  24. # Set ignore_exception flag (Done after ignore is selected at wizard)
  25. so.ignore_exception = True
  26. so.action_confirm()
  27. self.assertTrue(so.state == 'sale')
  28. # Add a order line to test after SO is confirmed
  29. p = self.env.ref('product.product_product_7')
  30. # set ignore_exception = False (Done by onchange of order_line)
  31. self.assertRaises(
  32. ValidationError,
  33. so.write,
  34. {
  35. 'ignore_exception': False,
  36. 'order_line': [(0, 0, {'name': p.name,
  37. 'product_id': p.id,
  38. 'product_uom_qty': 2,
  39. 'product_uom': p.uom_id.id,
  40. 'price_unit': p.list_price})]
  41. },
  42. )
  43. p = self.env.ref('product.product_product_7')
  44. # Set ignore exception True (Done manually by user)
  45. so.write({
  46. 'ignore_exception': True,
  47. 'order_line': [(0, 0, {'name': p.name,
  48. 'product_id': p.id,
  49. 'product_uom_qty': 2,
  50. 'product_uom': p.uom_id.id,
  51. 'price_unit': p.list_price})]
  52. })
  53. exception.active = False