GoodERP
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.

166 lines
6.0KB

  1. # Copyright 2016 上海开阖软件有限公司 (http://www.osbzr.com)
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. from odoo.tests.common import TransactionCase
  4. from odoo.exceptions import UserError, ValidationError
  5. from datetime import datetime, timedelta
  6. class TestStaff(TransactionCase):
  7. def test_get_image(self):
  8. '''拿到用户头像,职位的onchange'''
  9. user_lucy = self.env['res.users'].create({
  10. 'name': 'Lucy',
  11. 'login': 'lucy@osbzr.com',
  12. })
  13. staff_pro = self.env['staff'].create({
  14. 'identification_id': 111111,
  15. 'work_phone': 12345678901,
  16. 'work_email': 'lucy@osbzr.com',
  17. 'name': 'Lucy',
  18. 'code': 'lucy',
  19. 'type': 'member',
  20. 'user_id': user_lucy.id,
  21. 'job_id': self.env.ref('staff.staff_job_1').id})
  22. staff_pro.onchange_job_id()
  23. def test_staff_contract_over_date(self):
  24. '''测试:员工合同到期,发送邮件给员工 和 部门经理(如果存在)'''
  25. job = self.browse_ref('staff.ir_cron_module_remind_contract_over_date')
  26. job.interval_type = 'minutes'
  27. job.nextcall = (datetime.now() + timedelta(hours=8)
  28. ).strftime('%Y-%m-%d %H:%M:%S')
  29. # not staff.contract_ids
  30. self.env['staff'].staff_contract_over_date()
  31. # has staff.contract_ids but no apartment manager
  32. staff_lily = self.env.ref('staff.lili')
  33. staff_lily.work_email = 'lili@sina.com.cn'
  34. staff_lily.contract_ids.create({'staff_id': staff_lily.id,
  35. 'basic_wage': 123456,
  36. 'over_date': datetime.now().strftime("%Y-%m-%d"),
  37. 'job_id': self.env.ref('staff.staff_job_1').id})
  38. # has staff.contract_ids and apartment manager
  39. self.env.ref('staff.staff_1').work_email = 'admin@sina.com.cn'
  40. staff_lily.parent_id = self.env.ref('staff.staff_1').id
  41. self.env['staff'].staff_contract_over_date()
  42. def test_onchange_basic_wage(self):
  43. ''' 测试:选择基本工资时带出五险一金比例,计算出应交金额并填充 '''
  44. company = self.env.company
  45. company.endowment_ratio = 8
  46. # company.health_ratio = 2
  47. # company.unemployment_ratio = 0.5
  48. # company.housing_fund_ratio = 7
  49. # company.endowment_co_ratio = 20
  50. # company.health_co_ratio = 10
  51. # company.unemployment_co_ratio = 1
  52. # company.injury_ratio = 1
  53. # company.maternity_ratio = 0.5
  54. # company.housing_fund_co_ratio = 7
  55. lili_contract = self.env.ref('staff.contract_staff_lili')
  56. lili_contract.basic_wage = 13000
  57. lili_contract.onchange_basic_wage()
  58. def test_check_work_email(self):
  59. ''' Test: check work email '''
  60. staff_lili = self.env.ref('staff.lili')
  61. # 测试邮箱格式正确
  62. staff_lili.work_email = 'gooderp@osbzr.com'
  63. # 测试邮箱格式不正确,报错
  64. with self.assertRaises(UserError):
  65. staff_lili.work_email = 'gooderp'
  66. class TestStaffDepartment(TransactionCase):
  67. ''' 测试 部门 '''
  68. def test_check_parent_id(self):
  69. ''' 测试 上级部门不能选择自己和下级的部门 '''
  70. department_1 = self.env.ref('staff.department_1')
  71. department_2 = self.env['staff.department'].create({
  72. 'name': '财务部',
  73. 'code': 'dep_finance',
  74. 'type': 'department',
  75. 'parent_id': department_1.id,
  76. })
  77. with self.assertRaises(UserError):
  78. department_1.parent_id = department_2.id
  79. def test_view_detail(self):
  80. ''' 测试部门list 打开部门 '''
  81. department_1 = self.env.ref('staff.department_1')
  82. department_1.view_detail()
  83. class TestMailMessage(TransactionCase):
  84. def setUp(self):
  85. '''准备基本数据'''
  86. super(TestMailMessage, self).setUp()
  87. self.staff = self.browse_ref('staff.staff_1')
  88. def test_staff_birthday_message(self):
  89. '''测试:员工生日当天,whole company 会收到祝福信息'''
  90. # 设置了员工生日
  91. self.staff.birthday = datetime.now()
  92. job = self.browse_ref(
  93. 'staff.ir_cron_module_update_notification_birthday')
  94. job.interval_type = 'minutes'
  95. job.nextcall = (datetime.now() + timedelta(hours=8)
  96. ).strftime('%Y-%m-%d %H:%M:%S')
  97. self.env['mail.message'].staff_birthday_message()
  98. class TestResUsers(TransactionCase):
  99. def test_check_user_id(self):
  100. ''' 测试 一个用户只能对应一个员工 '''
  101. # core 模块里
  102. user = self.env.ref('base.user_demo')
  103. self.env.ref('staff.lili').user_id = user.id
  104. with self.assertRaises(UserError):
  105. self.env.ref('staff.staff_1').user_id = user.id
  106. class TestLeave(TransactionCase):
  107. ''' 测试 请假 '''
  108. def setUp(self):
  109. '''准备基本数据'''
  110. super(TestLeave, self).setUp()
  111. self.leave = self.browse_ref('staff.leave_1')
  112. def test_set_staff_id(self):
  113. ''' 测试 请假人 默认值 '''
  114. self.env['staff.leave'].create({
  115. 'name': 'go back home',
  116. 'leave_type': 'no_pay',
  117. })
  118. def test_leave_done(self):
  119. '''审核请假单'''
  120. self.leave.leave_done()
  121. self.assertTrue(self.leave.state == 'done')
  122. # 重复审核报错
  123. with self.assertRaises(UserError):
  124. self.leave.leave_done()
  125. def test_leave_draft(self):
  126. '''反审核请假单'''
  127. self.leave.leave_done()
  128. self.leave.leave_draft()
  129. self.assertTrue(self.leave.state == 'draft')
  130. # 重复反审核审核报错
  131. with self.assertRaises(UserError):
  132. self.leave.leave_draft()
  133. def test_check_leave_dates(self):
  134. '''请假天数不能小于或等于零'''
  135. with self.assertRaises(UserError):
  136. self.leave.leave_dates = 0
上海开阖软件有限公司 沪ICP备12045867号-1