77 lines
3.3 KiB
Python
77 lines
3.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
from odoo.tests.common import TransactionCase
|
|
|
|
|
|
class TestEstimateWizard(TransactionCase):
|
|
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
super().setUpClass()
|
|
cls.project = cls.env['project.project'].create({'name': 'Проект для сметы'})
|
|
cls.code = cls.env['hg.index.code'].create({'name': 'Код сметы'})
|
|
cls.index = cls.env['hg.index'].create({
|
|
'name': 'Показатель сметы',
|
|
'internal_code_id': cls.code.id,
|
|
})
|
|
cls.template = cls.env['hg.templates'].create({'name': 'Шаблон сметы'})
|
|
cls.env['hg.templates.line'].create({
|
|
'template_id': cls.template.id,
|
|
'index_id': cls.index.id,
|
|
'date_due': '2025-06-30',
|
|
'value_float_plan': 300000.0,
|
|
})
|
|
|
|
def _create_task(self, name='Задача сметы'):
|
|
return self.env['project.task'].create({
|
|
'name': name,
|
|
'project_id': self.project.id,
|
|
})
|
|
|
|
def test_confirm_action_creates_index_and_value(self):
|
|
task = self._create_task()
|
|
wizard = self.env['estimate.wizard'].with_context(active_id=task.id).create({
|
|
'template_id': self.template.id,
|
|
'code_id': self.code.id,
|
|
})
|
|
wizard.confirm_action()
|
|
|
|
# Должен создаться показатель, привязанный к узлу задачи
|
|
indexes = self.env['hg.index'].search([('node_id', '=', task.node_id.id)])
|
|
self.assertTrue(indexes, 'Показатель должен быть создан для узла задачи')
|
|
|
|
# Должно создаться значение для каждого показателя
|
|
for index in indexes:
|
|
values = self.env['hg.value'].search([('index_id', '=', index.id)])
|
|
self.assertTrue(values, 'Значение должно быть создано для показателя')
|
|
|
|
def test_confirm_action_value_plan_matches_template(self):
|
|
task = self._create_task('Задача проверки плана')
|
|
wizard = self.env['estimate.wizard'].with_context(active_id=task.id).create({
|
|
'template_id': self.template.id,
|
|
'code_id': self.code.id,
|
|
})
|
|
wizard.confirm_action()
|
|
|
|
indexes = self.env['hg.index'].search([('node_id', '=', task.node_id.id)])
|
|
value = self.env['hg.value'].search([('index_id', 'in', indexes.ids)], limit=1)
|
|
self.assertEqual(value.value_float_plan, 300000.0)
|
|
self.assertEqual(str(value.date_due), '2025-06-30')
|
|
|
|
def test_confirm_action_returns_close(self):
|
|
task = self._create_task('Задача закрытия')
|
|
wizard = self.env['estimate.wizard'].with_context(active_id=task.id).create({
|
|
'template_id': self.template.id,
|
|
'code_id': self.code.id,
|
|
})
|
|
result = wizard.confirm_action()
|
|
self.assertEqual(result['type'], 'ir.actions.act_window_close')
|
|
|
|
def test_confirm_action_without_active_id(self):
|
|
wizard = self.env['estimate.wizard'].create({
|
|
'template_id': self.template.id,
|
|
'code_id': self.code.id,
|
|
})
|
|
# Без active_id в контексте — должен вернуть None без ошибок
|
|
result = wizard.confirm_action()
|
|
self.assertIsNone(result)
|