2
0

[FIX] Tests

This commit is contained in:
Laurent Mignon 2016-04-28 11:50:23 +02:00 committed by Benoit Aimont
parent 8c7d7661d9
commit 17230a8c5f

View File

@ -2,53 +2,45 @@
# Author: Damien Crier # Author: Damien Crier
# Copyright 2016 Camptocamp SA # Copyright 2016 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import datetime
from dateutil.relativedelta import relativedelta
import openerp.tests.common as common
from openerp import fields from openerp import fields
from openerp.tools import (DEFAULT_SERVER_DATE_FORMAT, import openerp.tests.common as common
DEFAULT_SERVER_DATETIME_FORMAT)
def to_odoo_datetime(date):
return date.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
def to_odoo_date(date):
return date.strftime(DEFAULT_SERVER_DATE_FORMAT)
class TestAccountFiscalYear(common.TransactionCase): class TestAccountFiscalYear(common.TransactionCase):
def setUp(self): def setUp(self):
super(TestAccountFiscalYear, self).setUp() super(TestAccountFiscalYear, self).setUp()
self.today_date = fields.Date.from_string(fields.Date.today()) self.today_date = datetime.date.today() + relativedelta(years=100)
self.company = self.env.ref('base.main_company') self.company = self.env.ref('base.main_company')
def test_example(self): def test_compute_fiscalyear(self):
"""Check that a call to that Odoo's method returns the dates from
a fiscal year date range if one exists for the given date
"""
# check that the result by default from 1/1 31/12
result = self.company.compute_fiscalyear_dates(self.today_date)
self.assertEquals(
result['date_from'],
datetime.date(self.today_date.year, 1, 1))
self.assertEquals(
result['date_to'],
datetime.date(self.today_date.year, 12, 31))
# create a fiscal year with different limits
demo_date_range = self.env['date.range'].create( demo_date_range = self.env['date.range'].create(
{'name': 'FY%s' % (self.today_date.year), {'name': 'FY%s' % (self.today_date.year),
'date_start': '%s-01-01' % self.today_date.year, 'date_start': '%s-04-01' % self.today_date.year,
'date_end': '%s-12-31' % self.today_date.year, 'date_end': '%s-11-30' % self.today_date.year,
'type_id': self.env.ref('account_fiscal_year.fiscalyear').id, 'type_id': self.env.ref('account_fiscal_year.fiscalyear').id,
'company_id': self.company.id, 'company_id': self.company.id,
'active': True}) 'active': True})
result = self.company.compute_fiscalyear_dates(self.today_date) result = self.company.compute_fiscalyear_dates(
self.assertEqual(to_odoo_datetime(result['date_from']), datetime.date(self.today_date.year, 5, 4))
demo_date_range.date_start) self.assertEqual(
self.assertEqual(to_odoo_datetime(result['date_to']), result['date_from'],
demo_date_range.date_end) fields.Date.from_string(demo_date_range.date_start))
self.assertEqual(
def test_example2(self): result['date_to'],
demo_date_range = self.env['date.range'].create( fields.Date.from_string(demo_date_range.date_end))
{'name': 'FY%s' % (self.today_date.year),
'date_start': '%s-03-01' % self.today_date.year,
'date_end': '%s-12-31' % self.today_date.year,
'type_id': self.env.ref('account_fiscal_year.fiscalyear').id,
'company_id': self.company.id,
'active': True})
result = self.company.compute_fiscalyear_dates(self.today_date)
if to_odoo_date(self.today_date) >= demo_date_range.date_start:
self.assertEqual(to_odoo_datetime(result['date_from']),
demo_date_range.date_start)
self.assertEqual(to_odoo_datetime(result['date_to']),
demo_date_range.date_end)