test_res_config_settings.py 4.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import Command
  4. from odoo.tests import tagged
  5. from .common import TestSaleProjectCommon
  6. @tagged('post_install', '-at_install')
  7. class TestResConfigSettings(TestSaleProjectCommon):
  8. @classmethod
  9. def setUpClass(cls, chart_template_ref=None):
  10. super().setUpClass(chart_template_ref=chart_template_ref)
  11. cls.sale_order = cls.env['sale.order'].with_context(mail_notrack=True, mail_create_nolog=True).create({
  12. 'partner_id': cls.partner_b.id,
  13. 'partner_invoice_id': cls.partner_b.id,
  14. 'partner_shipping_id': cls.partner_b.id,
  15. 'order_line': [
  16. Command.create({
  17. 'product_id': cls.product_milestone.id,
  18. 'product_uom_qty': 3,
  19. }),
  20. Command.create({
  21. 'product_id': cls.product_delivery_manual1.id,
  22. 'product_uom_qty': 2,
  23. })
  24. ]
  25. })
  26. cls.product_milestone_sale_line = cls.sale_order.order_line.filtered(lambda sol: sol.product_id == cls.product_milestone)
  27. cls.product_delivery_manual1_sale_line = cls.sale_order.order_line.filtered(lambda sol: sol.product_id == cls.product_delivery_manual1)
  28. cls.sale_order.action_confirm()
  29. cls.milestone = cls.env['project.milestone'].create({
  30. 'name': 'Test Milestone',
  31. 'sale_line_id': cls.product_milestone_sale_line.id,
  32. 'project_id': cls.project_global.id,
  33. })
  34. def test_disable_and_enable_project_milestone_feature(self):
  35. self.assertTrue(self.env.user.has_group('project.group_project_milestone'), 'The Project Milestones feature should be enabled.')
  36. self.set_project_milestone_feature(False)
  37. self.assertFalse(self.env.user.has_group('project.group_project_milestone'), 'The Project Milestones feature should be disabled.')
  38. product_milestones = self.product_milestone + self.product_milestone2
  39. self.assertEqual(
  40. product_milestones.mapped('service_policy'),
  41. ['delivered_manual'] * 2,
  42. 'Both milestone products should become a manual product when the project milestones feature is disabled')
  43. self.assertEqual(
  44. product_milestones.mapped('service_type'),
  45. ['manual'] * 2,
  46. 'Both milestone products should become a manual product when the project milestones feature is disabled')
  47. self.assertEqual(
  48. self.product_milestone_sale_line.qty_delivered_method,
  49. 'manual',
  50. 'The quantity delivered method of SOL containing milestone product should be changed to manual when the project milestones feature is disabled')
  51. # Since the quantity delivered manual is manual then the user can manually change the quantity delivered
  52. self.product_milestone_sale_line.qty_delivered = 2
  53. # Enable the project milestones feature
  54. self.set_project_milestone_feature(True)
  55. self.assertEqual(
  56. self.product_milestone.service_policy,
  57. 'delivered_milestones',
  58. 'The product has been updated and considered as milestones product since a SOL containing this product is linked to a milestone.')
  59. self.assertEqual(
  60. self.product_milestone.service_type,
  61. 'milestones',
  62. 'The product has been updated and considered as milestones product since a SOL containing this product is linked to a milestone.')
  63. self.assertEqual(
  64. self.product_milestone2.service_policy,
  65. 'delivered_manual',
  66. 'The product should not be updated since we cannot assume this product was a milestone when the feature'
  67. ' was enabled because no SOL with this product is linked to a milestone.')
  68. self.assertEqual(
  69. self.product_milestone2.service_type,
  70. 'manual',
  71. 'The product should not be updated since we cannot assume this product was a milestone when the feature'
  72. ' was enabled because no SOL with this product is linked to a milestone.')
  73. self.assertEqual(
  74. self.product_milestone_sale_line.qty_delivered_method,
  75. 'manual',
  76. 'The quantity delivered method of SOL containing milestone product should keep the same quantity delivered method even if the project milestones feature is renabled.')
  77. self.assertEqual(self.product_milestone_sale_line.qty_delivered, 2, 'The quantity delivered should be the one set by the user.')