common.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo.addons.mail.tests.common import mail_new_test_user
  4. from odoo.addons.sale_project.tests.common import TestSaleProjectCommon
  5. class TestCommonSaleTimesheet(TestSaleProjectCommon):
  6. @classmethod
  7. def setUpClass(cls, chart_template_ref=None):
  8. super().setUpClass(chart_template_ref=chart_template_ref)
  9. cls.user_employee_company_B = mail_new_test_user(
  10. cls.env,
  11. name='Gregor Clegane Employee',
  12. login='gregor',
  13. email='gregor@example.com',
  14. notification_type='email',
  15. groups='base.group_user',
  16. company_id=cls.company_data_2['company'].id,
  17. company_ids=[cls.company_data_2['company'].id],
  18. )
  19. cls.user_manager_company_B = mail_new_test_user(
  20. cls.env,
  21. name='Cersei Lannister Manager',
  22. login='cersei',
  23. email='cersei@example.com',
  24. notification_type='email',
  25. groups='base.group_user',
  26. company_id=cls.company_data_2['company'].id,
  27. company_ids=[cls.company_data_2['company'].id, cls.env.company.id],
  28. )
  29. cls.employee_user = cls.env['hr.employee'].create({
  30. 'name': 'Employee User',
  31. 'hourly_cost': 15,
  32. })
  33. cls.employee_manager = cls.env['hr.employee'].create({
  34. 'name': 'Employee Manager',
  35. 'hourly_cost': 45,
  36. })
  37. cls.employee_company_B = cls.env['hr.employee'].create({
  38. 'name': 'Gregor Clegane',
  39. 'user_id': cls.user_employee_company_B.id,
  40. 'hourly_cost': 15,
  41. })
  42. cls.manager_company_B = cls.env['hr.employee'].create({
  43. 'name': 'Cersei Lannister',
  44. 'user_id': cls.user_manager_company_B.id,
  45. 'hourly_cost': 45,
  46. })
  47. # Account and project
  48. cls.analytic_account_sale.name = 'Project for selling timesheet - AA'
  49. cls.analytic_plan = cls.env['account.analytic.plan'].create({
  50. 'name': 'Plan Test',
  51. 'company_id': cls.company_data_2['company'].id,
  52. })
  53. cls.analytic_account_sale_company_B = cls.env['account.analytic.account'].create({
  54. 'name': 'Project for selling timesheet Company B - AA',
  55. 'code': 'AA-2030',
  56. 'plan_id': cls.analytic_plan.id,
  57. 'company_id': cls.company_data_2['company'].id,
  58. })
  59. # Create projects
  60. Project = cls.env['project.project'].with_context(tracking_disable=True)
  61. cls.project_global.write({
  62. 'name': 'Project for selling timesheets',
  63. 'allow_timesheets': True,
  64. })
  65. cls.project_template.write({
  66. 'name': 'Project TEMPLATE for services',
  67. })
  68. # Projects: at least one per billable type
  69. cls.project_task_rate = Project.create({
  70. 'name': 'Project with pricing_type="task_rate"',
  71. 'allow_timesheets': True,
  72. 'allow_billable': True,
  73. 'partner_id': cls.partner_b.id,
  74. 'analytic_account_id': cls.analytic_account_sale.id,
  75. })
  76. cls.project_subtask = Project.create({
  77. 'name': "Sub Task Project (non billable)",
  78. 'allow_timesheets': True,
  79. 'allow_billable': False,
  80. 'partner_id': False,
  81. })
  82. cls.project_non_billable = Project.create({
  83. 'name': "Non Billable Project",
  84. 'allow_timesheets': True,
  85. 'allow_billable': False,
  86. 'partner_id': False,
  87. })
  88. # Create service products
  89. # -- ordered quantities (ordered, timesheet)
  90. cls.product_order_timesheet1 = cls.env['product.product'].create({
  91. 'name': "Service Ordered, create no task",
  92. 'standard_price': 11,
  93. 'list_price': 13,
  94. 'type': 'service',
  95. 'invoice_policy': 'order',
  96. 'uom_id': cls.uom_hour.id,
  97. 'uom_po_id': cls.uom_hour.id,
  98. 'default_code': 'SERV-ORDERED1',
  99. 'service_type': 'timesheet',
  100. 'service_tracking': 'no',
  101. 'project_id': False,
  102. 'taxes_id': False,
  103. 'property_account_income_id': cls.account_sale.id,
  104. })
  105. cls.product_order_timesheet2 = cls.env['product.product'].create({
  106. 'name': "Service Ordered, create task in global project",
  107. 'standard_price': 30,
  108. 'list_price': 90,
  109. 'type': 'service',
  110. 'invoice_policy': 'order',
  111. 'uom_id': cls.uom_hour.id,
  112. 'uom_po_id': cls.uom_hour.id,
  113. 'default_code': 'SERV-ORDERED2',
  114. 'service_type': 'timesheet',
  115. 'service_tracking': 'task_global_project',
  116. 'project_id': cls.project_global.id,
  117. 'taxes_id': False,
  118. 'property_account_income_id': cls.account_sale.id,
  119. })
  120. cls.product_order_timesheet3 = cls.env['product.product'].create({
  121. 'name': "Service Ordered, create task in new project",
  122. 'standard_price': 10,
  123. 'list_price': 20,
  124. 'type': 'service',
  125. 'invoice_policy': 'order',
  126. 'uom_id': cls.uom_hour.id,
  127. 'uom_po_id': cls.uom_hour.id,
  128. 'default_code': 'SERV-ORDERED3',
  129. 'service_type': 'timesheet',
  130. 'service_tracking': 'task_in_project',
  131. 'project_id': False, # will create a project
  132. 'taxes_id': False,
  133. 'property_account_income_id': cls.account_sale.id,
  134. })
  135. cls.product_order_timesheet4 = cls.env['product.product'].create({
  136. 'name': "Service Ordered, create project only",
  137. 'standard_price': 15,
  138. 'list_price': 30,
  139. 'type': 'service',
  140. 'invoice_policy': 'order',
  141. 'uom_id': cls.uom_hour.id,
  142. 'uom_po_id': cls.uom_hour.id,
  143. 'default_code': 'SERV-ORDERED4',
  144. 'service_type': 'timesheet',
  145. 'service_tracking': 'project_only',
  146. 'project_id': False,
  147. 'taxes_id': False,
  148. 'property_account_income_id': cls.account_sale.id,
  149. })
  150. cls.product_order_timesheet5 = cls.env['product.product'].create({
  151. 'name': "Service Ordered, create project only based on template",
  152. 'standard_price': 17,
  153. 'list_price': 34,
  154. 'type': 'service',
  155. 'invoice_policy': 'order',
  156. 'uom_id': cls.uom_hour.id,
  157. 'uom_po_id': cls.uom_hour.id,
  158. 'default_code': 'SERV-ORDERED4',
  159. 'service_type': 'timesheet',
  160. 'service_tracking': 'project_only',
  161. 'project_id': False,
  162. 'project_template_id': cls.project_template.id,
  163. 'taxes_id': False,
  164. 'property_account_income_id': cls.account_sale.id,
  165. })
  166. # -- timesheet on tasks (delivered, timesheet)
  167. cls.product_delivery_timesheet1 = cls.env['product.product'].create({
  168. 'name': "Service delivered, create no task",
  169. 'standard_price': 11,
  170. 'list_price': 13,
  171. 'type': 'service',
  172. 'invoice_policy': 'delivery',
  173. 'uom_id': cls.uom_hour.id,
  174. 'uom_po_id': cls.uom_hour.id,
  175. 'default_code': 'SERV-DELI1',
  176. 'service_type': 'timesheet',
  177. 'service_tracking': 'no',
  178. 'project_id': False,
  179. 'taxes_id': False,
  180. 'property_account_income_id': cls.account_sale.id,
  181. })
  182. cls.product_delivery_timesheet2 = cls.env['product.product'].create({
  183. 'name': "Service delivered, create task in global project",
  184. 'standard_price': 30,
  185. 'list_price': 90,
  186. 'type': 'service',
  187. 'invoice_policy': 'delivery',
  188. 'uom_id': cls.uom_hour.id,
  189. 'uom_po_id': cls.uom_hour.id,
  190. 'default_code': 'SERV-DELI2',
  191. 'service_type': 'timesheet',
  192. 'service_tracking': 'task_global_project',
  193. 'project_id': cls.project_global.id,
  194. 'taxes_id': False,
  195. 'property_account_income_id': cls.account_sale.id,
  196. })
  197. cls.product_delivery_timesheet3 = cls.env['product.product'].create({
  198. 'name': "Service delivered, create task in new project",
  199. 'standard_price': 10,
  200. 'list_price': 20,
  201. 'type': 'service',
  202. 'invoice_policy': 'delivery',
  203. 'uom_id': cls.uom_hour.id,
  204. 'uom_po_id': cls.uom_hour.id,
  205. 'default_code': 'SERV-DELI3',
  206. 'service_type': 'timesheet',
  207. 'service_tracking': 'task_in_project',
  208. 'project_id': False, # will create a project
  209. 'taxes_id': False,
  210. 'property_account_income_id': cls.account_sale.id,
  211. })
  212. cls.product_delivery_timesheet4 = cls.env['product.product'].create({
  213. 'name': "Service delivered, create project only",
  214. 'standard_price': 15,
  215. 'list_price': 30,
  216. 'type': 'service',
  217. 'invoice_policy': 'delivery',
  218. 'uom_id': cls.uom_hour.id,
  219. 'uom_po_id': cls.uom_hour.id,
  220. 'default_code': 'SERV-DELI4',
  221. 'service_type': 'timesheet',
  222. 'service_tracking': 'project_only',
  223. 'project_id': False,
  224. 'taxes_id': False,
  225. 'property_account_income_id': cls.account_sale.id,
  226. })
  227. cls.product_delivery_timesheet5 = cls.env['product.product'].create({
  228. 'name': "Service delivered, create project only based on template",
  229. 'standard_price': 17,
  230. 'list_price': 34,
  231. 'type': 'service',
  232. 'invoice_policy': 'delivery',
  233. 'uom_id': cls.uom_hour.id,
  234. 'uom_po_id': cls.uom_hour.id,
  235. 'default_code': 'SERV-DELI5',
  236. 'service_type': 'timesheet',
  237. 'service_tracking': 'project_only',
  238. 'project_template_id': cls.project_template.id,
  239. 'project_id': False,
  240. 'taxes_id': False,
  241. 'property_account_income_id': cls.account_sale.id,
  242. })
  243. def setUp(self):
  244. super().setUp()
  245. self.so = self.env['sale.order'].with_context(mail_notrack=True, mail_create_nolog=True).create({
  246. 'partner_id': self.partner_b.id,
  247. 'partner_invoice_id': self.partner_b.id,
  248. 'partner_shipping_id': self.partner_b.id,
  249. })
  250. self.env['sale.order.line'].create([{
  251. 'order_id': self.so.id,
  252. 'product_id': self.product_delivery_timesheet1.id,
  253. 'product_uom_qty': 10,
  254. }, {
  255. 'order_id': self.so.id,
  256. 'product_id': self.product_delivery_timesheet2.id,
  257. 'product_uom_qty': 5,
  258. }, {
  259. 'order_id': self.so.id,
  260. 'product_id': self.product_delivery_timesheet3.id,
  261. 'product_uom_qty': 5,
  262. }, {
  263. 'order_id': self.so.id,
  264. 'product_id': self.product_order_timesheet1.id,
  265. 'product_uom_qty': 2,
  266. }])
  267. self.so.action_confirm()