|
| 1 | +# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 2 | + |
| 3 | +from odoo.tests import tagged, Form |
| 4 | +from odoo.tests.common import TransactionCase |
| 5 | +from odoo import fields, Command |
| 6 | + |
| 7 | + |
| 8 | +@tagged('post_install', '-at_install') |
| 9 | +class ActionServerTestCase(TransactionCase): |
| 10 | + |
| 11 | + @classmethod |
| 12 | + def setUpClass(cls): |
| 13 | + super().setUpClass() |
| 14 | + cls.partner_a = cls.env['res.partner'].create({'name': 'partner_a'}) |
| 15 | + cls.demo_account_move = cls.env['account.move'].create({ |
| 16 | + 'move_type': 'out_refund', |
| 17 | + 'partner_id': cls.partner_a.id, |
| 18 | + 'invoice_date': fields.Date.today().strftime("%Y-%m-02"), |
| 19 | + 'delivery_date': fields.Date.today().strftime("%Y-%m-02"), |
| 20 | + 'invoice_line_ids': [Command.create({'quantity': 5, 'display_type': 'product'})], |
| 21 | + 'x_task_id': cls.env['project.task'].create({ |
| 22 | + 'name': 'project_task', |
| 23 | + 'project_id': cls.env['project.project'].create({'name': 'project'}).id, |
| 24 | + }).id, |
| 25 | + }) |
| 26 | + cls.sale_order_1 = cls.env['sale.order'].create({'partner_id': cls.partner_a.id}) |
| 27 | + with Form(cls.sale_order_1) as so: |
| 28 | + with so.order_line.new() as order_line: |
| 29 | + order_line.display_type = 'line_section' |
| 30 | + order_line.name = 'section_1' |
| 31 | + with so.order_line.new() as order_line: |
| 32 | + order_line.product_id = cls.env.ref("handyman.product_product_5") |
| 33 | + order_line.sequence = 11 |
| 34 | + so.save() |
| 35 | + cls.sale_order_1.action_confirm() |
| 36 | + |
| 37 | + def test_base_automation_create_move_line_add_automatic_account(self): |
| 38 | + move_line = self.demo_account_move.invoice_line_ids |
| 39 | + self.assertEqual(move_line.analytic_distribution, {f'{move_line.move_id.x_task_id.project_id.account_id.id}': 100.0}) |
| 40 | + |
| 41 | + def test_add_default_analytic_account_server_action(self): |
| 42 | + move_line = self.demo_account_move.invoice_line_ids |
| 43 | + move_line.analytic_distribution = False |
| 44 | + # Check that the automation is not triggered when move_line changes |
| 45 | + self.assertEqual(move_line.analytic_distribution, False) |
| 46 | + server_action = self.env['ir.actions.server'].browse(self.env.ref('handyman.action_add_default_analytic_account').id) |
| 47 | + server_action.with_context(active_id=move_line.id, active_model="account.move.line").run() |
| 48 | + self.assertEqual(move_line.analytic_distribution, {f'{move_line.move_id.x_task_id.project_id.account_id.id}': 100.0}) |
| 49 | + |
| 50 | + def test_add_section_task_name_base_automation(self): |
| 51 | + for project_task in self.sale_order_1.tasks_ids: |
| 52 | + self.assertEqual(project_task.name[-12:], " - section_1") |
| 53 | + |
| 54 | + def test_add_section_task_name_server_action(self): |
| 55 | + for project_task in self.sale_order_1.tasks_ids: |
| 56 | + project_task.name = "project_task_1" |
| 57 | + # Check that the automation is not triggered when project task is changed |
| 58 | + self.assertEqual(project_task.name, "project_task_1") |
| 59 | + server_action = self.env['ir.actions.server'].browse(self.env.ref('handyman.action_add_section_task_name').id) |
| 60 | + server_action.with_context(active_ids=[project_task.id], active_model="project.task").run() |
| 61 | + self.assertEqual(project_task.name, "project_task_1 - section_1") |
0 commit comments