test_child_tasks.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details
  3. from odoo.tests.common import TransactionCase, new_test_user
  4. class TestNestedTaskUpdate(TransactionCase):
  5. @classmethod
  6. def setUpClass(cls):
  7. super().setUpClass()
  8. cls.partner = cls.env['res.partner'].create({'name': "Mur en béton"})
  9. sale_order = cls.env['sale.order'].with_context(tracking_disable=True).create({
  10. 'partner_id': cls.partner.id,
  11. 'partner_invoice_id': cls.partner.id,
  12. 'partner_shipping_id': cls.partner.id,
  13. })
  14. product = cls.env['product.product'].create({
  15. 'name': "Prepaid Consulting",
  16. 'type': 'service',
  17. })
  18. cls.order_line = cls.env['sale.order.line'].create({
  19. 'name': "Order line",
  20. 'product_id': product.id,
  21. 'order_id': sale_order.id,
  22. })
  23. cls.user = new_test_user(cls.env, login='mla')
  24. #----------------------------------
  25. #
  26. # When creating tasks that have a parent_id, they pick some values from their parent
  27. #
  28. #----------------------------------
  29. def test_creating_subtask_user_id_on_parent_dont_go_on_child(self):
  30. parent = self.env['project.task'].create({'name': 'parent', 'user_ids': [(4, self.user.id)]})
  31. child = self.env['project.task'].create({'name': 'child', 'parent_id': parent.id, 'user_ids': False})
  32. self.assertFalse(child.user_ids)
  33. def test_creating_subtask_partner_id_on_parent_goes_on_child(self):
  34. parent = self.env['project.task'].create({'name': 'parent', 'partner_id': self.user.partner_id.id})
  35. child = self.env['project.task'].create({'name': 'child', 'parent_id': parent.id})
  36. child._compute_partner_id() # the compute will be triggered since the user set the parent_id.
  37. self.assertEqual(child.partner_id, self.user.partner_id)
  38. # Another case, it is the parent as a default value
  39. child = self.env['project.task'].with_context(default_parent_id=parent.id).create({'name': 'child'})
  40. self.assertEqual(child.partner_id, self.user.partner_id)
  41. def test_creating_subtask_email_from_on_parent_goes_on_child(self):
  42. parent = self.env['project.task'].create({'name': 'parent', 'email_from': 'a@c.be'})
  43. child = self.env['project.task'].create({'name': 'child', 'parent_id': parent.id})
  44. self.assertEqual(child.email_from, 'a@c.be')
  45. def test_creating_subtask_sale_line_id_on_parent_goes_on_child_if_same_partner_in_values(self):
  46. parent = self.env['project.task'].create({'name': 'parent', 'partner_id': self.partner.id, 'sale_line_id': self.order_line.id})
  47. child = self.env['project.task'].create({'name': 'child', 'partner_id': self.partner.id, 'parent_id': parent.id})
  48. self.assertEqual(child.sale_line_id, parent.sale_line_id)
  49. parent.write({'sale_line_id': False})
  50. self.assertEqual(child.sale_line_id, self.order_line)
  51. def test_creating_subtask_sale_line_id_on_parent_goes_on_child_with_partner_if_not_in_values(self):
  52. parent = self.env['project.task'].create({'name': 'parent', 'partner_id': self.partner.id, 'sale_line_id': self.order_line.id})
  53. child = self.env['project.task'].create({'name': 'child', 'parent_id': parent.id})
  54. self.assertEqual(child.partner_id, parent.partner_id)
  55. self.assertEqual(child.sale_line_id, parent.sale_line_id)
  56. def test_creating_subtask_sale_line_id_on_parent_dont_go_on_child_if_other_partner(self):
  57. parent = self.env['project.task'].create({'name': 'parent', 'partner_id': self.partner.id, 'sale_line_id': self.order_line.id})
  58. child = self.env['project.task'].create({'name': 'child', 'partner_id': self.user.partner_id.id, 'parent_id': parent.id})
  59. self.assertFalse(child.sale_line_id)
  60. self.assertNotEqual(child.partner_id, parent.partner_id)
  61. def test_creating_subtask_sale_line_id_on_parent_go_on_child_if_same_commercial_partner(self):
  62. commercial_partner = self.env['res.partner'].create({'name': "Jémémy"})
  63. self.partner.parent_id = commercial_partner
  64. self.user.partner_id.parent_id = commercial_partner
  65. parent = self.env['project.task'].create({'name': 'parent', 'partner_id': self.partner.id, 'sale_line_id': self.order_line.id})
  66. child = self.env['project.task'].create({'name': 'child', 'partner_id': self.user.partner_id.id, 'parent_id': parent.id})
  67. self.assertEqual(child.sale_line_id, self.order_line, "Sale order line on parent should be transfered to child")
  68. self.assertNotEqual(child.partner_id, parent.partner_id)
  69. #----------------------------------------
  70. #
  71. # When writing on a parent task, some values adapt on their children
  72. #
  73. #----------------------------------------
  74. def test_write_user_id_on_parent_dont_write_on_child(self):
  75. parent = self.env['project.task'].create({'name': 'parent', 'user_ids': False})
  76. child = self.env['project.task'].create({'name': 'child', 'user_ids': False, 'parent_id': parent.id})
  77. self.assertFalse(child.user_ids)
  78. parent.write({'user_ids': [(4, self.user.id)]})
  79. self.assertFalse(child.user_ids)
  80. parent.write({'user_ids': False})
  81. self.assertFalse(child.user_ids)
  82. def test_write_partner_id_on_parent_write_on_child(self):
  83. parent = self.env['project.task'].create({'name': 'parent', 'partner_id': False})
  84. child = self.env['project.task'].create({'name': 'child', 'partner_id': False, 'parent_id': parent.id})
  85. self.assertFalse(child.partner_id)
  86. parent.write({'partner_id': self.user.partner_id.id})
  87. self.assertNotEqual(child.partner_id, parent.partner_id)
  88. parent.write({'partner_id': False})
  89. self.assertNotEqual(child.partner_id, self.user.partner_id)
  90. def test_write_email_from_on_parent_write_on_child(self):
  91. parent = self.env['project.task'].create({'name': 'parent'})
  92. child = self.env['project.task'].create({'name': 'child', 'parent_id': parent.id})
  93. self.assertFalse(child.email_from)
  94. parent.write({'email_from': 'a@c.be'})
  95. self.assertEqual(child.email_from, parent.email_from)
  96. parent.write({'email_from': ''})
  97. self.assertEqual(child.email_from, 'a@c.be')
  98. def test_write_sale_line_id_on_parent_write_on_child_if_same_partner(self):
  99. parent = self.env['project.task'].create({'name': 'parent', 'partner_id': self.partner.id})
  100. child = self.env['project.task'].create({'name': 'child', 'parent_id': parent.id, 'partner_id': self.partner.id})
  101. self.assertFalse(child.sale_line_id)
  102. parent.write({'sale_line_id': self.order_line.id})
  103. self.assertEqual(child.sale_line_id, parent.sale_line_id)
  104. parent.write({'sale_line_id': False})
  105. self.assertEqual(child.sale_line_id, self.order_line)
  106. def test_write_sale_line_id_on_parent_write_on_child_with_partner_if_not_set(self):
  107. parent = self.env['project.task'].create({'name': 'parent', 'partner_id': self.partner.id})
  108. child = self.env['project.task'].create({'name': 'child', 'parent_id': parent.id})
  109. child._compute_partner_id()
  110. self.assertFalse(child.sale_line_id)
  111. parent.write({'sale_line_id': self.order_line.id})
  112. self.assertEqual(child.sale_line_id, parent.sale_line_id)
  113. self.assertEqual(child.partner_id, self.partner)
  114. parent.write({'sale_line_id': False})
  115. self.assertEqual(child.sale_line_id, self.order_line)
  116. def test_write_sale_line_id_on_parent_dont_write_on_child_if_other_partner(self):
  117. parent = self.env['project.task'].create({'name': 'parent', 'partner_id': self.partner.id})
  118. child = self.env['project.task'].create({'name': 'child', 'parent_id': parent.id, 'partner_id': self.user.partner_id.id})
  119. self.assertFalse(child.sale_line_id)
  120. parent.write({'sale_line_id': self.order_line.id})
  121. self.assertFalse(child.sale_line_id)
  122. #----------------------------------
  123. #
  124. # When linking two existent task, some values go on the child
  125. #
  126. #----------------------------------
  127. def test_linking_user_id_on_parent_dont_write_on_child(self):
  128. parent = self.env['project.task'].create({'name': 'parent', 'user_ids': [(4, self.user.id)]})
  129. child = self.env['project.task'].create({'name': 'child', 'user_ids': False})
  130. self.assertFalse(child.user_ids)
  131. child.write({'parent_id': parent.id})
  132. self.assertFalse(child.user_ids)
  133. def test_linking_partner_id_on_parent_write_on_child(self):
  134. parent = self.env['project.task'].create({'name': 'parent', 'partner_id': self.user.partner_id.id})
  135. child = self.env['project.task'].create({'name': 'child', 'partner_id': False})
  136. self.assertFalse(child.partner_id)
  137. child.write({'parent_id': parent.id})
  138. self.assertEqual(child.partner_id, self.user.partner_id)
  139. def test_linking_email_from_on_parent_write_on_child(self):
  140. parent = self.env['project.task'].create({'name': 'parent', 'email_from': 'a@c.be'})
  141. child = self.env['project.task'].create({'name': 'child', 'email_from': False})
  142. self.assertFalse(child.email_from)
  143. child.write({'parent_id': parent.id})
  144. self.assertEqual(child.email_from, 'a@c.be')
  145. def test_linking_sale_line_id_on_parent_write_on_child_if_same_partner(self):
  146. parent = self.env['project.task'].create({'name': 'parent', 'partner_id': self.partner.id, 'sale_line_id': self.order_line.id})
  147. child = self.env['project.task'].create({'name': 'child', 'partner_id': self.partner.id})
  148. self.assertFalse(child.sale_line_id)
  149. child.write({'parent_id': parent.id})
  150. self.assertEqual(child.sale_line_id, parent.sale_line_id)
  151. parent.write({'sale_line_id': False})
  152. self.assertEqual(child.sale_line_id, self.order_line)
  153. def test_linking_sale_line_id_on_parent_write_on_child_with_partner_if_not_set(self):
  154. parent = self.env['project.task'].create({'name': 'parent', 'partner_id': self.partner.id, 'sale_line_id': self.order_line.id})
  155. child = self.env['project.task'].create({'name': 'child', 'partner_id': False})
  156. self.assertFalse(child.sale_line_id)
  157. self.assertFalse(child.partner_id)
  158. child.write({'parent_id': parent.id})
  159. self.assertEqual(child.partner_id, parent.partner_id)
  160. self.assertEqual(child.sale_line_id, parent.sale_line_id)
  161. def test_linking_sale_line_id_on_parent_write_dont_child_if_other_partner(self):
  162. parent = self.env['project.task'].create({'name': 'parent', 'partner_id': self.partner.id, 'sale_line_id': self.order_line.id})
  163. child = self.env['project.task'].create({'name': 'child', 'partner_id': self.user.partner_id.id})
  164. self.assertFalse(child.sale_line_id)
  165. self.assertNotEqual(child.partner_id, parent.partner_id)
  166. child.write({'parent_id': parent.id})
  167. self.assertFalse(child.sale_line_id)
  168. def test_writing_on_parent_with_multiple_tasks(self):
  169. parent = self.env['project.task'].create({'name': 'parent', 'user_ids': False, 'partner_id': self.partner.id})
  170. children_values = [{'name': 'child%s' % i, 'user_ids': False, 'parent_id': parent.id} for i in range(5)]
  171. children = self.env['project.task'].create(children_values)
  172. children._compute_partner_id()
  173. # test writing sale_line_id
  174. for child in children:
  175. self.assertFalse(child.sale_line_id)
  176. parent.write({'sale_line_id': self.order_line.id})
  177. for child in children:
  178. self.assertEqual(child.sale_line_id, self.order_line)
  179. def test_linking_on_parent_with_multiple_tasks(self):
  180. parent = self.env['project.task'].create({'name': 'parent', 'partner_id': self.partner.id, 'sale_line_id': self.order_line.id, 'user_ids': [(4, self.user.id)]})
  181. children_values = [{'name': 'child%s' % i, 'user_ids': False} for i in range(5)]
  182. children = self.env['project.task'].create(children_values)
  183. # test writing user_ids and sale_line_id
  184. for child in children:
  185. self.assertFalse(child.user_ids)
  186. self.assertFalse(child.sale_line_id)
  187. children.write({'parent_id': parent.id})
  188. for child in children:
  189. self.assertEqual(child.sale_line_id, self.order_line)
  190. self.assertFalse(child.user_ids)