Debian Codegraph @

addons/sale_purchase_project/tests/test_sale_purchase_project.py

raw symbols SCIP
1 # Part of Odoo. See LICENSE file for full copyright and licensing details.
2
3 from odoo.tests import tagged
4 from odoo.addons.sale_purchase.tests.test_sale_purchase import TestSalePurchase
5
6
7 @tagged('-at_install', 'post_install')
8 class TestSalePurchaseProject(TestSalePurchase):
9
10 def test_pol_analytic_distribution(self):
11 """Confirming SO, analytic accounts from the project's SO should be set as Analytic Distribution in POL."""
12 self.env.user.group_ids += self.quick_ref('project.group_project_manager')
13 project = self.env['project.project'].create({
14 'name': 'SO Project',
15 self.analytic_plan._column_name(): self.test_analytic_account_1.id,
16 })
17 # Remove the analytic account auto-generated when creating a timesheetable project if it exists
18 project.account_id = False
19
20 (self.sale_order_1 + self.sale_order_2).project_id = project
21 self.sale_order_2.order_line.analytic_distribution = {str(self.test_analytic_account_2.id): 100}
22
23 (self.sale_order_1 + self.sale_order_2).action_confirm()
24
25 purchase_order = self.env['purchase.order'].search([('partner_id', '=', self.service_purchase_1.seller_ids.partner_id.id), ('state', '=', 'draft')])
26 self.assertEqual(len(purchase_order), 2, "Two PO should have been created, from the 2 Sales orders")
27 self.assertEqual(len(purchase_order.order_line), 2, "The purchase order should have 2 lines")
28 self.assertEqual(set(purchase_order.mapped('state')), {'draft'}, "The created PO should be in draft state.")
29
30 purchase_lines_so1 = self.env['purchase.order.line'].search([('sale_line_id', 'in', self.sale_order_1.order_line.ids)])
31 self.assertEqual(len(purchase_lines_so1), 1, "Only one SO line from SO 1 should have create a PO line")
32 purchase_line1 = purchase_lines_so1[0]
33
34 purchase_lines_so2 = self.env['purchase.order.line'].search([('sale_line_id', 'in', self.sale_order_2.order_line.ids)])
35 self.assertEqual(len(purchase_lines_so2), 1, "Only one SO line from SO 2 should have create a PO line")
36 purchase_line2 = purchase_lines_so2[0]
37
38 self.assertNotEqual(purchase_line1.product_id, purchase_line2.product_id, "The 2 PO line should have different products")
39 self.assertEqual(purchase_line1.product_id, self.sol1_service_purchase_1.product_id, "The create PO line must have the same product as its mother SO line")
40 self.assertEqual(purchase_line2.product_id, self.sol2_service_purchase_2.product_id, "The create PO line must have the same product as its mother SO line")
41
42 self.assertEqual(purchase_line1.analytic_distribution, {str(self.sale_order_1.project_id[self.analytic_plan._column_name()].id): 100}, "Analytic Distribution in PO should be same as Analytic Account set in SO")
43 self.assertEqual(purchase_line2.analytic_distribution, {str(self.test_analytic_account_2.id): 100}, "Analytic Distribution in PO should be same as Analytic Distribution set in SOL")