Merge pull request #605 from akretion/10-lock_date_update-usability

[10.0] account_lock_date_update + account_permanent_lock_move_update : several usability improvements
This commit is contained in:
Alexis de Lattre
2019-12-05 17:10:44 +01:00
committed by GitHub
11 changed files with 71 additions and 71 deletions

View File

@@ -6,7 +6,7 @@
Account Lock Date Update
========================
Allow an Account adviser to update locking date without having
Allow an Account adviser to update lock dates without having
access to all technical settings.
Installation
@@ -24,8 +24,8 @@ Usage
To use this module, you need to be an account adviser and go to:
* Accounting -> Configuration -> Accounting -> Update accounting lock dates
* Change values and click on update button
* Accounting -> Configuration -> Accounting -> Lock Dates
* Change values and click on *Update* button
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot

View File

@@ -5,9 +5,9 @@
{
'name': 'Account Lock Date Update',
'summary': """
Allow an Account adviser to update locking date without having
Allow an Account adviser to update lock dates without having
access to all technical settings""",
'version': '10.0.1.0.0',
'version': '10.0.1.0.1',
'license': 'AGPL-3',
'author': 'ACSONE SA/NV, Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/account-financial-tools',

View File

@@ -7,7 +7,6 @@ from odoo.exceptions import UserError
class AccountUpdateLockDate(models.TransientModel):
_name = 'account.update.lock_date'
_description = 'Account Update Lock_date'
@@ -35,7 +34,6 @@ class AccountUpdateLockDate(models.TransientModel):
})
return res
@api.multi
def _check_execute_allowed(self):
self.ensure_one()
has_adviser_group = self.env.user.has_group(
@@ -43,11 +41,15 @@ class AccountUpdateLockDate(models.TransientModel):
if not (has_adviser_group or self.env.uid == SUPERUSER_ID):
raise UserError(_("You are not allowed to execute this action."))
@api.multi
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)

View File

@@ -9,14 +9,11 @@
<field name="model">account.update.lock_date</field>
<field name="arch" type="xml">
<form>
<header/>
<sheet>
<group>
<field name="company_id" invisible="1"/>
<field name="period_lock_date"/>
<field name="fiscalyear_lock_date"/>
</group>
</sheet>
<group name="main">
<field name="company_id" groups="base.group_multi_company"/>
<field name="period_lock_date"/>
<field name="fiscalyear_lock_date"/>
</group>
<footer>
<button string="Update" name="execute" type="object" class="btn-primary"/>
<button string="Cancel" class="btn-default" special="cancel"/>
@@ -27,14 +24,14 @@
<record model="ir.actions.act_window" id="account_update_lock_date_act_window">
<field name="name">Update accounting lock dates</field>
<field name="name">Lock Dates</field>
<field name="res_model">account.update.lock_date</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<record model="ir.ui.menu" id="account_update_lock_date_menu">
<field name="name">Update accounting lock dates</field>
<field name="name">Update Accounting Lock Dates</field>
<field name="parent_id" ref="account.account_account_menu"/>
<field name="action" ref="account_update_lock_date_act_window"/>
<field name="groups_id" eval="[(6, 0, [ref('account.group_account_manager')])]"/>

View File

@@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Permanent Lock Move",
"version": "10.0.1.0.0",
"version": "10.0.1.0.1",
"depends": ["account"],
"author": "Camptocamp,Odoo Community Association (OCA)",
"website": "http://www.camptocamp.com/",

View File

@@ -56,7 +56,7 @@ class PermanentLock(common.TransactionCase):
})
self.wizard.confirm_date()
except UserError as ue:
if 'entries are still unposted' in ue.name:
if 'are still unposted' in ue.name:
raised_lock_error = True
self.assertTrue(raised_lock_error,
@@ -90,7 +90,7 @@ class PermanentLock(common.TransactionCase):
})
self.wizard.confirm_date()
except UserError as ue:
if 'permanent lock date in the past' in ue.name:
if 'permanent lock date before the current permanent' in ue.name:
raised_lock_error = True
self.assertTrue(raised_lock_error,

View File

@@ -1,36 +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="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'}

View File

@@ -5,8 +5,10 @@
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Lock permanently entries">
<label string="All journal entries prior to and included at this date will be permanently locked."/>
<label string="All journal entries prior to and included at the new lock date will be permanently locked."/>
<group>
<field name="company_id" groups="base.group_multi_company"/>
<field name="current_lock_date"/>
<field name="lock_date" required="1"/>
</group>
<footer>

View File

@@ -7,7 +7,7 @@
'summary': """
Allow an Account adviser to update permanent lock date without
having access to all technical settings""",
'version': '10.0.1.0.0',
'version': '10.0.1.0.1',
'license': 'AGPL-3',
'author': 'ACSONE SA/NV, Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/account-financial-tools',

View File

@@ -6,32 +6,28 @@ from odoo import api, fields, models
class AccountUpdateLockDate(models.TransientModel):
_inherit = 'account.update.lock_date'
permanent_lock_date = fields.Date(
string="Permanent Lock Date", readonly=True)
tmp_permanent_lock_date = fields.Date(string="Permanent Lock Date")
@api.model
def default_get(self, field_list):
res = super(AccountUpdateLockDate, self).default_get(field_list)
company = self.env.user.company_id
res['permanent_lock_date'] = company.permanent_lock_date
res['tmp_permanent_lock_date'] = company.permanent_lock_date
return res
@api.multi
def change_permanent_lock_date(self):
self.ensure_one()
company = self.company_id
wizard = self.env['permanent.lock.date.wizard'].create({
'company_id': company.id,
'lock_date': company.permanent_lock_date,
})
return {
'type': 'ir.actions.act_window',
'res_model': 'permanent.lock.date.wizard',
'view_mode': 'form',
'view_type': 'form',
'res_id': wizard.id,
'target': 'new',
}
def execute(self):
res = super(AccountUpdateLockDate, self).execute()
if self.tmp_permanent_lock_date != self.company_id.permanent_lock_date:
return {
'type': 'ir.actions.act_window',
'res_model': 'permanent.lock.date.wizard',
'view_mode': 'form',
'target': 'new',
'context': {
'default_company_id': self.company_id.id,
'default_lock_date': self.tmp_permanent_lock_date,
}
}
return res

View File

@@ -9,19 +9,9 @@
<field name="model">account.update.lock_date</field>
<field name="inherit_id" ref="account_lock_date_update.account_update_lock_date_form_view"/>
<field name="arch" type="xml">
<sheet position="inside">
<group>
<group>
<field name="permanent_lock_date"/>
</group>
<group>
<button string="Permanently Lock Entries" name="change_permanent_lock_date"
type="object" class="btn-primary"/>
</group>
</group>
</sheet>
<field name="fiscalyear_lock_date" position="after">
<field name="tmp_permanent_lock_date"/>
</field>
</field>
</record>