New module account_permanent_lock_move

This commit is contained in:
Matthieu Dietrich
2016-05-24 11:42:40 +02:00
committed by houssine
parent 9039c392c1
commit ff23dc7688
12 changed files with 231 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
===================
Permanent Lock Move
===================
This module extends the functionality of the basic "lock date"
functionality in invoicing, in order to add a more definitive
lock date (which does not allow to be set at a previous date,
or emptied, and only accepts unposted moves)
Configuration
=============
To configure this module, you need to:
* Go to Invoicing -> Settings, and set the Permanent Lock Date.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/92/9.0
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/account-financial-tools/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
* Matthieu Dietrich <matthieu.dietrich@camptocamp.com>
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit https://odoo-community.org.

View File

@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
from . import models
from . import wizard

View File

@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# © 2016 Camptocamp SA (Matthieu Dietrich)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Permanent Lock Move",
"version": "9.0.1.0.0",
"depends": ["account"],
"author": "Camptocamp,Odoo Community Association (OCA)",
"website": "http://www.camptocamp.com/",
"category": "Finance",
"data": [
"views/res_config_view.xml",
"wizard/permanent_lock_date_wizard.xml",
"security/ir.model.access.csv",
],
'license': 'AGPL-3',
"auto_install": False,
'installable': True,
}

View File

@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
from . import account_move
from . import company
from . import res_config

View File

@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# © 2016 Camptocamp SA (Matthieu Dietrich)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import _, api, models
from openerp.exceptions import UserError
class AccountMove(models.Model):
_inherit = "account.move"
@api.multi
def _check_lock_date(self):
for move in self:
if move.date <= move.company_id.permanent_lock_date:
raise UserError(_(
"You cannot add/modify entries prior to and inclusive "
"of the permanent lock date."))
return super(AccountMove, self)._check_lock_date()
@api.multi
def button_cancel(self):
# Add check for button_cancel, as it does not use ORM
self._check_lock_date()
return super(AccountMove, self).button_cancel()

View File

@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
# © 2016 Camptocamp SA (Matthieu Dietrich)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import _, api, fields, models
from openerp.exceptions import UserError
class ResCompany(models.Model):
_inherit = "res.company"
permanent_lock_date = fields.Date(
string="Permanent Lock Date",
help="Non-revertible closing of accounts prior to and inclusive of "
"this date. Use it for fiscal year locking instead of ""Lock Date"".")

View File

@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# © 2016 Camptocamp SA (Matthieu Dietrich)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import api, fields, models
class AccountConfigSettings(models.TransientModel):
_inherit = 'account.config.settings'
permanent_lock_date = fields.Date(
string="Permanent Lock Date",
related='company_id.permanent_lock_date',
help="Non-revertible closing of accounts prior to and inclusive of "
"this date. Use it for fiscal year locking instead of ""Lock Date"".")
@api.multi
def change_permanent_lock_date(self):
wizard = self.env['permanent.lock.date.wizard'].create({
'company_id': self.company_id.id
})
return {
'type': 'ir.actions.act_window',
'res_model': 'permanent.lock.date.wizard',
'view_mode': 'form',
'view_type': 'form',
'res_id': wizard.id,
'target': 'new',
}

View File

@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_account_permanent_lock_date_wizard,account.permanent.lock.move,model_permanent_lock_date_wizard,account.group_account_manager,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_account_permanent_lock_date_wizard account.permanent.lock.move model_permanent_lock_date_wizard account.group_account_manager 1 1 1 1

View File

@@ -0,0 +1,18 @@
<odoo>
<record id="view_account_config_settings_permanent_lock" model="ir.ui.view">
<field name="name">account settings permanent lock</field>
<field name="model">account.config.settings</field>
<field name="inherit_id" ref="account.view_account_config_settings"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='fiscalyear_lock_date']/parent::div" position="after">
<div>
<label for="permanent_lock_date"/>
<field name="permanent_lock_date" class="oe_inline" readonly="1"/>
</div>
<div>
<button type="object" name="change_permanent_lock_date" string="Permanently Lock Entries" class="oe_inline oe_stat_button"/>
</div>
</xpath>
</field>
</record>
</odoo>

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import permanent_lock_date_wizard

View File

@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
# © 2016 Camptocamp SA (Matthieu Dietrich)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import _, api, fields, models
from openerp.exceptions import UserError
class PermanentLockDateWizard(models.TransientModel):
_name = 'permanent.lock.date.wizard'
lock_date = fields.Date(string="Lock Date")
company_id = fields.Many2one(comodel_name='res.company',
string='Company')
@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!")
)
# Then check if unposted moves are present before the date
moves = self.env['account.move'].search(
[('company_id', '=', self.id),
('date', '<=', self.lock_date),
('state', '=', 'draft')])
if moves:
raise UserError(
_("You cannot permanently lock since entries "
"are still unposted before this date!")
)
company.permanent_lock_date = self.lock_date
return {'type': 'ir.actions.act_window_close'}

View File

@@ -0,0 +1,19 @@
<odoo>
<record id="permanent_lock_date_wizard_form" model="ir.ui.view">
<field name="name">permanent.lock.date.wizard.form</field>
<field name="model">permanent.lock.date.wizard</field>
<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!"/>
<group>
<field name="lock_date" required="1"/>
</group>
<footer>
<button string="Lock Journal Entries" name="confirm_date" type="object" default_focus="1" class="btn-primary"/>
<button string="Cancel" class="btn-default" special="cancel"/>
</footer>
</form>
</field>
</record>
</odoo>