Debian Codegraph @

addons/sale_project/tests/test_sale_project_dashboard.py

raw
1 # Part of Odoo. See LICENSE file for full copyright and licensing details.
2
3 from odoo.addons.sale_project.tests.test_project_profitability import TestProjectProfitabilityCommon as Common
4
5
6 class TestProjectDashboardCommon(Common):
7
8 @classmethod
9 def setUpClass(cls):
10 super().setUpClass()
11 cls.dashboard_project = cls.env['project.project'].with_context({'mail_create_nolog': True}).create({
12 'name': 'Project',
13 'partner_id': cls.partner.id,
14 'account_id': cls.analytic_account.id,
15 'allow_billable': True,
16 })
17 cls.dashboard_sale_order = cls.env['sale.order'].with_context(tracking_disable=True).create({
18 'partner_id': cls.partner.id,
19 'partner_invoice_id': cls.partner.id,
20 'partner_shipping_id': cls.partner.id,
21 })
22 cls.dashboard_sale_order.action_confirm()
23 cls.dashboardSaleOrderLine = cls.env['sale.order.line'].with_context(tracking_disable=True, default_order_id=cls.dashboard_sale_order.id)
24 cls.dashboard_product_delivery_service, cls.product_milestone, cls.product_prepaid = cls.env['product.product'].create([{
25 'name': "Service Delivery",
26 'standard_price': 30,
27 'list_price': 90,
28 'type': 'service',
29 'invoice_policy': 'delivery',
30 'service_type': 'manual',
31 'uom_id': cls.uom_hour.id,
32 'default_code': 'SERV-ORDERED2',
33 'service_tracking': 'task_global_project',
34 'project_id': cls.dashboard_project.id,
35 }, {
36 'name': "Service Milestone",
37 'standard_price': 30,
38 'list_price': 90,
39 'type': 'service',
40 'invoice_policy': 'delivery',
41 'service_type': 'milestones',
42 'uom_id': cls.uom_hour.id,
43 'default_code': 'SERV-ORDERED2',
44 'service_tracking': 'task_global_project',
45 'project_id': cls.dashboard_project.id,
46 }, {
47 'name': "Product prepaid",
48 'standard_price': 30,
49 'list_price': 90,
50 'type': 'service',
51 'uom_id': cls.uom_hour.id,
52 'default_code': 'SERV-ORDERED2',
53 'service_tracking': 'task_global_project',
54 'project_id': cls.dashboard_project.id,
55 }])
56
57
58 class TestDashboardProject(TestProjectDashboardCommon):
59 """
60 This test ensures that the method get_sale_item_data compute correctly the data needed for the project_profitability sale sub section.
61 Since the data is different for the same input when the timesheet module is installed, those tests have to be run at_install
62 """
63
64 def test_get_sale_item_data_various_sols(self):
65 """This test ensures that the sols are computed and put into the correct profitability sections"""
66 hour_uom_id = self.env.ref('uom.product_uom_hour').id
67 unit_uom_id = self.env.ref('uom.product_uom_unit').id
68 sol_service_1, sol_service_2, sol_service_3, sol_service_4 = self.dashboardSaleOrderLine.create([{
69 'product_id': self.product_milestone.id,
70 'product_uom_qty': 1,
71 }, {
72 'product_id': self.product_prepaid.id,
73 'product_uom_qty': 1,
74 }, {
75 'product_id': self.material_product.id,
76 'product_uom_qty': 1,
77 }, {
78 'product_id': self.dashboard_product_delivery_service.id,
79 'product_uom_qty': 1,
80 }])
81 expected_dict = sol_service_3._read_format(
82 ['display_name', 'product_uom_qty', 'qty_delivered', 'qty_invoiced', 'product_uom_id', 'product_id']
83 )
84 sale_item_data = self.dashboard_project.get_sale_items_data(limit=5, with_action=False, section_id='materials')
85 self.assertEqual(sale_item_data['sol_items'], expected_dict)
86 expected_dict = (sol_service_1 + sol_service_2 + sol_service_4)._read_format(
87 ['display_name', 'product_uom_qty', 'qty_delivered', 'qty_invoiced', 'product_uom_id', 'product_id']
88 )
89 sale_item_data = self.dashboard_project.get_sale_items_data(limit=5, with_action=False, section_id='service_revenues')
90 self.assertEqual(sale_item_data['sol_items'], expected_dict)