From 172241022a4b22feb1c834273b174e0ff59b21e6 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Wed, 27 Feb 2019 21:41:56 +0100 Subject: [PATCH] Avoid inconsistent dates --- .../wizards/account_update_lock_date.py | 10 ++++-- .../wizards/account_update_lock_date.xml | 14 ++++---- .../wizard/permanent_lock_date_wizard.py | 36 ++++++++++++------- .../wizard/permanent_lock_date_wizard.xml | 1 + .../wizards/account_update_lock_date.py | 12 +++---- 5 files changed, 44 insertions(+), 29 deletions(-) diff --git a/account_lock_date_update/wizards/account_update_lock_date.py b/account_lock_date_update/wizards/account_update_lock_date.py index f033bce64..22886a6ea 100644 --- a/account_lock_date_update/wizards/account_update_lock_date.py +++ b/account_lock_date_update/wizards/account_update_lock_date.py @@ -7,7 +7,6 @@ from odoo.exceptions import UserError class AccountUpdateLockDate(models.TransientModel): - _name = 'account.update.lock_date' _description = 'Account Update Lock_date' @@ -45,7 +44,12 @@ class AccountUpdateLockDate(models.TransientModel): def execute(self): self.ensure_one() self._check_execute_allowed() - self.company_id.sudo().write({ + vals = { 'period_lock_date': self.period_lock_date, 'fiscalyear_lock_date': self.fiscalyear_lock_date, - }) + } + if ( + self.period_lock_date and self.fiscalyear_lock_date and + self.period_lock_date < self.fiscalyear_lock_date): + vals['period_lock_date'] = self.fiscalyear_lock_date + self.company_id.sudo().write(vals) diff --git a/account_lock_date_update/wizards/account_update_lock_date.xml b/account_lock_date_update/wizards/account_update_lock_date.xml index 0816faece..2697f8ef9 100644 --- a/account_lock_date_update/wizards/account_update_lock_date.xml +++ b/account_lock_date_update/wizards/account_update_lock_date.xml @@ -10,7 +10,7 @@
- + @@ -30,10 +30,12 @@ new - + + Update Accounting Lock Dates + + + + + diff --git a/account_permanent_lock_move/wizard/permanent_lock_date_wizard.py b/account_permanent_lock_move/wizard/permanent_lock_date_wizard.py index cc2ac62ae..89a9a6bda 100644 --- a/account_permanent_lock_move/wizard/permanent_lock_date_wizard.py +++ b/account_permanent_lock_move/wizard/permanent_lock_date_wizard.py @@ -1,39 +1,49 @@ # -*- coding: utf-8 -*- # © 2016 Camptocamp SA (Matthieu Dietrich) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import _, api, fields, models +from odoo import _, fields, models from odoo.exceptions import UserError class PermanentLockDateWizard(models.TransientModel): _name = 'permanent.lock.date.wizard' + _description = 'Wizard to update the permanent lock date' - lock_date = fields.Date(string="New Lock Date") - company_id = fields.Many2one(comodel_name='res.company', - string='Company') + lock_date = fields.Date(string="New Permanent Lock Date", required=True) + company_id = fields.Many2one( + comodel_name='res.company', + string='Company', required=True, readonly=True) current_lock_date = fields.Date( related='company_id.permanent_lock_date', readonly=True, string='Current Lock Date') - @api.multi def confirm_date(self): self.ensure_one() company = self.company_id if (company.permanent_lock_date and self.lock_date < company.permanent_lock_date): - raise UserError( - _("You cannot set the permanent lock date in the past.") - ) + raise UserError(_( + "You cannot set the new permanent lock date before the " + "current permanent lock date.")) # Then check if unposted moves are present before the date moves = self.env['account.move'].search( [('company_id', '=', company.id), ('date', '<=', self.lock_date), ('state', '=', 'draft')]) if moves: - raise UserError( - _("You cannot set the permanent lock date since entries are " - "still unposted before this date.") - ) + raise UserError(_( + "You cannot set the new permanent lock date to %s " + "since some journal entries before that date are still " + "unposted.") % self.lock_date) - company.permanent_lock_date = self.lock_date + vals = {'permanent_lock_date': self.lock_date} + if ( + company.period_lock_date and + company.period_lock_date < self.lock_date): + vals['period_lock_date'] = self.lock_date + if ( + company.fiscalyear_lock_date and + company.fiscalyear_lock_date < self.lock_date): + vals['fiscalyear_lock_date'] = self.lock_date + company.write(vals) return {'type': 'ir.actions.act_window_close'} diff --git a/account_permanent_lock_move/wizard/permanent_lock_date_wizard.xml b/account_permanent_lock_move/wizard/permanent_lock_date_wizard.xml index b03402569..4066a364b 100644 --- a/account_permanent_lock_move/wizard/permanent_lock_date_wizard.xml +++ b/account_permanent_lock_move/wizard/permanent_lock_date_wizard.xml @@ -7,6 +7,7 @@