From 180bcc609b6020379644120c190c9e585b0c6c65 Mon Sep 17 00:00:00 2001 From: Matthieu Dietrich Date: Tue, 24 May 2016 11:42:40 +0200 Subject: [PATCH 1/7] New module account_permanent_lock_move --- account_permanent_lock_move/README.rst | 59 +++++++++++++++++++ account_permanent_lock_move/__init__.py | 4 ++ account_permanent_lock_move/__openerp__.py | 19 ++++++ .../models/__init__.py | 5 ++ .../models/account_move.py | 24 ++++++++ account_permanent_lock_move/models/company.py | 14 +++++ .../models/res_config.py | 28 +++++++++ .../security/ir.model.access.csv | 2 + .../views/res_config_view.xml | 18 ++++++ .../wizard/__init__.py | 3 + .../wizard/permanent_lock_date_wizard.py | 36 +++++++++++ .../wizard/permanent_lock_date_wizard.xml | 19 ++++++ 12 files changed, 231 insertions(+) create mode 100644 account_permanent_lock_move/README.rst create mode 100755 account_permanent_lock_move/__init__.py create mode 100644 account_permanent_lock_move/__openerp__.py create mode 100644 account_permanent_lock_move/models/__init__.py create mode 100644 account_permanent_lock_move/models/account_move.py create mode 100644 account_permanent_lock_move/models/company.py create mode 100644 account_permanent_lock_move/models/res_config.py create mode 100644 account_permanent_lock_move/security/ir.model.access.csv create mode 100644 account_permanent_lock_move/views/res_config_view.xml create mode 100644 account_permanent_lock_move/wizard/__init__.py create mode 100644 account_permanent_lock_move/wizard/permanent_lock_date_wizard.py create mode 100644 account_permanent_lock_move/wizard/permanent_lock_date_wizard.xml diff --git a/account_permanent_lock_move/README.rst b/account_permanent_lock_move/README.rst new file mode 100644 index 000000000..581e722c0 --- /dev/null +++ b/account_permanent_lock_move/README.rst @@ -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 +`_. 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 `_. + +Contributors +------------ + +* Matthieu Dietrich + +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. diff --git a/account_permanent_lock_move/__init__.py b/account_permanent_lock_move/__init__.py new file mode 100755 index 000000000..35e7c9600 --- /dev/null +++ b/account_permanent_lock_move/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +from . import models +from . import wizard diff --git a/account_permanent_lock_move/__openerp__.py b/account_permanent_lock_move/__openerp__.py new file mode 100644 index 000000000..b30ac3438 --- /dev/null +++ b/account_permanent_lock_move/__openerp__.py @@ -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, +} diff --git a/account_permanent_lock_move/models/__init__.py b/account_permanent_lock_move/models/__init__.py new file mode 100644 index 000000000..8993bef01 --- /dev/null +++ b/account_permanent_lock_move/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- + +from . import account_move +from . import company +from . import res_config diff --git a/account_permanent_lock_move/models/account_move.py b/account_permanent_lock_move/models/account_move.py new file mode 100644 index 000000000..7dc1be14f --- /dev/null +++ b/account_permanent_lock_move/models/account_move.py @@ -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() diff --git a/account_permanent_lock_move/models/company.py b/account_permanent_lock_move/models/company.py new file mode 100644 index 000000000..e9b5dedc0 --- /dev/null +++ b/account_permanent_lock_move/models/company.py @@ -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"".") diff --git a/account_permanent_lock_move/models/res_config.py b/account_permanent_lock_move/models/res_config.py new file mode 100644 index 000000000..5f6d1c54d --- /dev/null +++ b/account_permanent_lock_move/models/res_config.py @@ -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', + } diff --git a/account_permanent_lock_move/security/ir.model.access.csv b/account_permanent_lock_move/security/ir.model.access.csv new file mode 100644 index 000000000..01a499cc9 --- /dev/null +++ b/account_permanent_lock_move/security/ir.model.access.csv @@ -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 diff --git a/account_permanent_lock_move/views/res_config_view.xml b/account_permanent_lock_move/views/res_config_view.xml new file mode 100644 index 000000000..990efc5c5 --- /dev/null +++ b/account_permanent_lock_move/views/res_config_view.xml @@ -0,0 +1,18 @@ + + + account settings permanent lock + account.config.settings + + + +
+
+
+
+
+
+
+
diff --git a/account_permanent_lock_move/wizard/__init__.py b/account_permanent_lock_move/wizard/__init__.py new file mode 100644 index 000000000..def3c56f1 --- /dev/null +++ b/account_permanent_lock_move/wizard/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import permanent_lock_date_wizard diff --git a/account_permanent_lock_move/wizard/permanent_lock_date_wizard.py b/account_permanent_lock_move/wizard/permanent_lock_date_wizard.py new file mode 100644 index 000000000..6d849e9ce --- /dev/null +++ b/account_permanent_lock_move/wizard/permanent_lock_date_wizard.py @@ -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'} diff --git a/account_permanent_lock_move/wizard/permanent_lock_date_wizard.xml b/account_permanent_lock_move/wizard/permanent_lock_date_wizard.xml new file mode 100644 index 000000000..f789e3171 --- /dev/null +++ b/account_permanent_lock_move/wizard/permanent_lock_date_wizard.xml @@ -0,0 +1,19 @@ + + + permanent.lock.date.wizard.form + permanent.lock.date.wizard + form + +
+
+
+
From 6ab069ba493d406b9d534afc6871cbedc1381297 Mon Sep 17 00:00:00 2001 From: Matthieu Dietrich Date: Tue, 24 May 2016 11:56:36 +0200 Subject: [PATCH 2/7] Remove unnecessary imports --- account_permanent_lock_move/models/company.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/account_permanent_lock_move/models/company.py b/account_permanent_lock_move/models/company.py index e9b5dedc0..5e4bfbb63 100644 --- a/account_permanent_lock_move/models/company.py +++ b/account_permanent_lock_move/models/company.py @@ -1,8 +1,7 @@ # -*- 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 +from openerp import fields, models class ResCompany(models.Model): From c1062478a037d6212fb71e8b839b6113de2b9e3b Mon Sep 17 00:00:00 2001 From: Matthieu Dietrich Date: Tue, 24 May 2016 13:06:48 +0200 Subject: [PATCH 3/7] Change button style --- account_permanent_lock_move/views/res_config_view.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_permanent_lock_move/views/res_config_view.xml b/account_permanent_lock_move/views/res_config_view.xml index 990efc5c5..ff81a801a 100644 --- a/account_permanent_lock_move/views/res_config_view.xml +++ b/account_permanent_lock_move/views/res_config_view.xml @@ -10,7 +10,7 @@
-
From da73f15cd0ee959898018ec59cc2305dba59dbde Mon Sep 17 00:00:00 2001 From: Matthieu Dietrich Date: Tue, 24 May 2016 15:20:22 +0200 Subject: [PATCH 4/7] Change button style again --- account_permanent_lock_move/__openerp__.py | 1 - account_permanent_lock_move/models/res_config.py | 4 ++-- account_permanent_lock_move/security/ir.model.access.csv | 2 -- account_permanent_lock_move/views/res_config_view.xml | 4 ++-- .../wizard/permanent_lock_date_wizard.py | 4 ++-- .../wizard/permanent_lock_date_wizard.xml | 2 +- 6 files changed, 7 insertions(+), 10 deletions(-) delete mode 100644 account_permanent_lock_move/security/ir.model.access.csv diff --git a/account_permanent_lock_move/__openerp__.py b/account_permanent_lock_move/__openerp__.py index b30ac3438..c18f0fc46 100644 --- a/account_permanent_lock_move/__openerp__.py +++ b/account_permanent_lock_move/__openerp__.py @@ -11,7 +11,6 @@ "data": [ "views/res_config_view.xml", "wizard/permanent_lock_date_wizard.xml", - "security/ir.model.access.csv", ], 'license': 'AGPL-3', "auto_install": False, diff --git a/account_permanent_lock_move/models/res_config.py b/account_permanent_lock_move/models/res_config.py index 5f6d1c54d..1e312fff8 100644 --- a/account_permanent_lock_move/models/res_config.py +++ b/account_permanent_lock_move/models/res_config.py @@ -10,8 +10,8 @@ class AccountConfigSettings(models.TransientModel): 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"".") + 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): diff --git a/account_permanent_lock_move/security/ir.model.access.csv b/account_permanent_lock_move/security/ir.model.access.csv deleted file mode 100644 index 01a499cc9..000000000 --- a/account_permanent_lock_move/security/ir.model.access.csv +++ /dev/null @@ -1,2 +0,0 @@ -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 diff --git a/account_permanent_lock_move/views/res_config_view.xml b/account_permanent_lock_move/views/res_config_view.xml index ff81a801a..acc77dd5f 100644 --- a/account_permanent_lock_move/views/res_config_view.xml +++ b/account_permanent_lock_move/views/res_config_view.xml @@ -7,10 +7,10 @@
-
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 6d849e9ce..7382d4414 100644 --- a/account_permanent_lock_move/wizard/permanent_lock_date_wizard.py +++ b/account_permanent_lock_move/wizard/permanent_lock_date_wizard.py @@ -19,7 +19,7 @@ class PermanentLockDateWizard(models.TransientModel): 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!") + _("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( @@ -29,7 +29,7 @@ class PermanentLockDateWizard(models.TransientModel): if moves: raise UserError( _("You cannot permanently lock since entries " - "are still unposted before this date!") + "are still unposted before this date.") ) company.permanent_lock_date = self.lock_date 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 f789e3171..0ffbe0046 100644 --- a/account_permanent_lock_move/wizard/permanent_lock_date_wizard.xml +++ b/account_permanent_lock_move/wizard/permanent_lock_date_wizard.xml @@ -5,7 +5,7 @@ form
-