[MIG]account_lock_to_date to v12

This commit is contained in:
ahenriquez
2020-02-21 12:59:37 +01:00
committed by Miquel Raïch
parent dfbe917f67
commit 6ec55928a4
3 changed files with 19 additions and 15 deletions

View File

@@ -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',

View File

@@ -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 \

View File

@@ -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