# -*- coding: utf-8 -*-
from odoo.tests.common import TransactionCase


class TestHgValue(TransactionCase):

    def setUp(self):
        super().setUp()
        self.index = self.env['hg.index'].create({'name': 'Показатель для значений'})
        self.value = self.env['hg.value'].create({
            'name': 'Тестовое значение',
            'index_id': self.index.id,
            'value_float_actual': 100.0,
            'value_float_plan': 120.0,
            'date_due': '2025-01-31',
            'type': 'alone',
        })

    def test_create(self):
        self.assertEqual(self.value.value_float_actual, 100.0)
        self.assertEqual(self.value.value_float_plan, 120.0)
        self.assertEqual(self.value.type, 'alone')

    def test_calc_alone_does_not_change_value(self):
        self.value.calc()
        self.assertEqual(self.value.value_float_actual, 100.0)

    def test_calc_formula(self):
        value = self.env['hg.value'].create({
            'name': 'Формульное значение',
            'index_id': self.index.id,
            'value_float_actual': 0.0,
            'value_float_plan': 0.0,
            'date_due': '2025-02-28',
            'type': 'formula',
            'formula': '2 + 2',
        })
        value.calc()
        self.assertEqual(value.value_float_actual, 4.0)

    def test_type_selection_values(self):
        selection = dict(self.env['hg.value'].fields_get(['type'])['type']['selection'])
        self.assertIn('alone', selection)
        self.assertIn('formula', selection)
