diff --git a/account_lock_to_date/__manifest__.py b/account_lock_to_date/__manifest__.py index 5da8d5a59..72e378901 100644 --- a/account_lock_to_date/__manifest__.py +++ b/account_lock_to_date/__manifest__.py @@ -5,7 +5,7 @@ 'name': 'Account Lock To Date', 'summary': """ Allows to set an account lock date in the future.""", - 'version': '11.0.1.0.0', + 'version': '12.0.1.0.0', 'license': 'AGPL-3', 'author': 'Eficent, Odoo Community Association (OCA)', 'website': 'https://github.com/OCA/account-financial-tools', diff --git a/account_lock_to_date/models/res_company.py b/account_lock_to_date/models/res_company.py index 88c0b94d1..3332789e6 100644 --- a/account_lock_to_date/models/res_company.py +++ b/account_lock_to_date/models/res_company.py @@ -4,6 +4,7 @@ from datetime import datetime from dateutil.relativedelta import relativedelta import calendar import time +from time import mktime from odoo import api, fields, models, SUPERUSER_ID, _ from odoo.tools.misc import DEFAULT_SERVER_DATE_FORMAT from odoo.exceptions import ValidationError @@ -36,24 +37,17 @@ class ResCompany(models.Model): :param vals: The values passed to the write method. ''' - period_lock_to_date = vals.get('period_lock_to_date') and\ - time.strptime(vals['period_lock_to_date'], - DEFAULT_SERVER_DATE_FORMAT) - fiscalyear_lock_to_date = vals.get('fiscalyear_lock_to_date') and\ - time.strptime(vals['fiscalyear_lock_to_date'], - DEFAULT_SERVER_DATE_FORMAT) + period_lock_to_date = vals.get('period_lock_to_date') + fiscalyear_lock_to_date = vals.get('fiscalyear_lock_to_date') - next_month = datetime.strptime( - fields.Date.today(), - DEFAULT_SERVER_DATE_FORMAT) + relativedelta(months=+1) + next_month = datetime.now() + relativedelta(months=+1) days_next_month = calendar.monthrange(next_month.year, next_month.month) next_month = next_month.replace( day=days_next_month[1]).timetuple() + next_month = datetime.fromtimestamp(mktime(next_month)).date() for company in self: - old_fiscalyear_lock_to_date = company.fiscalyear_lock_to_date and\ - time.strptime(company.fiscalyear_lock_to_date, - DEFAULT_SERVER_DATE_FORMAT) + old_fiscalyear_lock_to_date = company.fiscalyear_lock_to_date # The user attempts to remove the lock date for advisors if old_fiscalyear_lock_to_date and \ diff --git a/account_lock_to_date/tests/test_account_lock_to_date_update.py b/account_lock_to_date/tests/test_account_lock_to_date_update.py index e0d7e456f..318ac1794 100644 --- a/account_lock_to_date/tests/test_account_lock_to_date_update.py +++ b/account_lock_to_date/tests/test_account_lock_to_date_update.py @@ -3,6 +3,8 @@ from odoo.tests.common import TransactionCase from odoo.exceptions import UserError, ValidationError +from odoo.tools.misc import DEFAULT_SERVER_DATE_FORMAT +from datetime import datetime class TestAccountLockToDateUpdate(TransactionCase): @@ -88,8 +90,16 @@ class TestAccountLockToDateUpdate(TransactionCase): 'groups_id': [(4, self.adviser_group.id)], }) wizard.sudo(self.demo_user.id).execute() - self.assertEqual(self.company.period_lock_to_date, '2900-01-01') - self.assertEqual(self.company.fiscalyear_lock_to_date, '2900-02-01') + self.assertEqual( + self.company.period_lock_to_date, + datetime.strptime( + '2900-01-01', + DEFAULT_SERVER_DATE_FORMAT).date()) + self.assertEqual( + self.company.fiscalyear_lock_to_date, + datetime.strptime( + '2900-02-01', + DEFAULT_SERVER_DATE_FORMAT).date()) def test_03_create_move_outside_period(self): """We test that we cannot create journal entries after the