From e13b4a37cbc515440da6a837688fb8aea015e89c Mon Sep 17 00:00:00 2001 From: Joel Grand-Guillaume Date: Wed, 9 Jan 2013 12:09:27 +0100 Subject: [PATCH 1/9] [ADD] Account_constraints module to implement accounting constraints that OpenERP doesn't wanted in the core. --- account_constraints/__init__.py | 21 ++++++ account_constraints/__openerp__.py | 50 +++++++++++++ account_constraints/account_constraints.py | 85 ++++++++++++++++++++++ 3 files changed, 156 insertions(+) create mode 100644 account_constraints/__init__.py create mode 100644 account_constraints/__openerp__.py create mode 100644 account_constraints/account_constraints.py diff --git a/account_constraints/__init__.py b/account_constraints/__init__.py new file mode 100644 index 000000000..7e8f7ca8c --- /dev/null +++ b/account_constraints/__init__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author Joel Grand-Guillaume. Copyright 2012 Camptocamp SA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +############################################################################## + +import account_constraints \ No newline at end of file diff --git a/account_constraints/__openerp__.py b/account_constraints/__openerp__.py new file mode 100644 index 000000000..39f912acf --- /dev/null +++ b/account_constraints/__openerp__.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author Joel Grand-Guillaume. Copyright 2012 Camptocamp SA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +############################################################################## +{ + 'name' : 'Account Contraints', + 'version' : '1', + 'depends' : [ + 'account', + ], + 'author' : 'Camptocamp', + 'category': 'Generic Modules/Accounting', + 'description': """ + Add contraints in the accounting module of OpenERP to avoid bad usage by users that lead + to corrupted datas. This is based on our experiences and legal state of the art in other + software. + + Summary of constraints are: + + * Add a constraint on account move: you cannot pickup a date that is not in the fiscal year of the concerned period + + * For manual entries when multicurrency: + a - Validation on the use of the 'Currency' and 'Currency Amount' fields as it is possible to enter one without the other + b - Validation to prevent a Credit amount with a positive 'Currency Amount', or a Debit with a negative 'Currency Amount' + + * Add a check on entries that user cannot provide a secondary currency if the same than the company one. + + """, + 'website': 'http://www.camptocamp.com', + 'init_xml': [], + 'update_xml': [], + 'demo_xml': [], + 'installable': True, + 'active': False, +} diff --git a/account_constraints/account_constraints.py b/account_constraints/account_constraints.py new file mode 100644 index 000000000..6ba995a31 --- /dev/null +++ b/account_constraints/account_constraints.py @@ -0,0 +1,85 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author Joel Grand-Guillaume. Copyright 2012 Camptocamp SA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +############################################################################## + +import time +from openerp.osv import fields, osv +from openerp.tools.translate import _ + +class AccountMove(osv.osv): + _inherit = "account.move" + + def _check_fiscal_year(self, cursor, user, ids): + for move in self.browse(cursor, user, ids): + date_start = move.period_id.fiscalyear_id.date_start + date_stop = move.period_id.fiscalyear_id.date_stop + if move.date < date_start or move.date > date_stop: + return False + return True + + _constraints = [ + (_check_fiscal_year, + 'You cannot create entries with date not in the fiscal year of the chosen period', + ['line_id','']), + ] + + +class AccountMoveLine(osv.osv): + _inherit='account.move.line' + + def _check_currency_and_amount(self, cr, uid, ids, context=None): + for l in self.browse(cr, uid, ids, context=context): + if (l.currency_id and not l.amount_currency) or (not l.currency_id and l.amount_currency): + return False + return True + + def _check_currency_amount(self, cr, uid, ids, context=None): + for l in self.browse(cr, uid, ids, context=context): + if l.amount_currency: + if (l.amount_currency > 0.0 and l.credit > 0.0) or (l.amount_currency < 0.0 and l.debit > 0.0): + return False + return True + + def _check_currency_company(self, cr, uid, ids, context=None): + for l in self.browse(cr, uid, ids, context=context): + if l.currency_id.id == l.company_id.currency_id.id: + return False + return True + + _constraints = [ + ( + _check_currency_and_amount, + "You cannot create journal items with a secondary currency without recording \ + both 'currency' and 'amount currency' field.", + ['currency_id','amount_currency'] + ), + ( + _check_currency_amount, + 'The amount expressed in the secondary currency must be positif when journal item\ + are debit and negatif when journal item are credit.', + ['amount_currency'] + ), + ( + _check_currency_company, + "You can't provide a secondary currency if the same than the company one." , + ['currency_id'] + ), + ] + + From 27910b6ac7049852804af40d979b045ea97ea7da Mon Sep 17 00:00:00 2001 From: Joel Grand-Guillaume Date: Fri, 11 Jan 2013 09:43:29 +0100 Subject: [PATCH 2/9] [IMP] Replace osv.osv by Model --- account_constraints/account_constraints.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/account_constraints/account_constraints.py b/account_constraints/account_constraints.py index 6ba995a31..6d4fa5e74 100644 --- a/account_constraints/account_constraints.py +++ b/account_constraints/account_constraints.py @@ -20,9 +20,10 @@ import time from openerp.osv import fields, osv +from openerp.osv.orm import Model from openerp.tools.translate import _ -class AccountMove(osv.osv): +class AccountMove(Model): _inherit = "account.move" def _check_fiscal_year(self, cursor, user, ids): @@ -40,7 +41,7 @@ class AccountMove(osv.osv): ] -class AccountMoveLine(osv.osv): +class AccountMoveLine(Model): _inherit='account.move.line' def _check_currency_and_amount(self, cr, uid, ids, context=None): From 30dcbd2fb06a42a930a42fcc0c34d44878cfb451 Mon Sep 17 00:00:00 2001 From: Joel Grand-Guillaume Date: Fri, 11 Jan 2013 14:41:57 +0100 Subject: [PATCH 3/9] [FIX] All remarks made in review: style issue, wrong usage of '\', better if check,... --- account_constraints/__init__.py | 11 ++++---- account_constraints/__openerp__.py | 15 ++++++----- account_constraints/account_constraints.py | 30 +++++++++++----------- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/account_constraints/__init__.py b/account_constraints/__init__.py index 7e8f7ca8c..ef69cef93 100644 --- a/account_constraints/__init__.py +++ b/account_constraints/__init__.py @@ -4,18 +4,17 @@ # Author Joel Grand-Guillaume. Copyright 2012 Camptocamp SA # # This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# GNU Affero General Public License for more details. # -# You should have received a copy of the GNU General Public License +# You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # ############################################################################## - import account_constraints \ No newline at end of file diff --git a/account_constraints/__openerp__.py b/account_constraints/__openerp__.py index 39f912acf..c9f2e5038 100644 --- a/account_constraints/__openerp__.py +++ b/account_constraints/__openerp__.py @@ -4,29 +4,30 @@ # Author Joel Grand-Guillaume. Copyright 2012 Camptocamp SA # # This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# GNU Affero General Public License for more details. # -# You should have received a copy of the GNU General Public License +# You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # ############################################################################## { - 'name' : 'Account Contraints', + 'name' : 'Account Constraints', 'version' : '1', 'depends' : [ 'account', ], 'author' : 'Camptocamp', + 'license': 'AGPL-3', 'category': 'Generic Modules/Accounting', 'description': """ - Add contraints in the accounting module of OpenERP to avoid bad usage by users that lead + Add constraints in the accounting module of OpenERP to avoid bad usage by users that lead to corrupted datas. This is based on our experiences and legal state of the art in other software. diff --git a/account_constraints/account_constraints.py b/account_constraints/account_constraints.py index 6d4fa5e74..2a3e906c3 100644 --- a/account_constraints/account_constraints.py +++ b/account_constraints/account_constraints.py @@ -4,16 +4,16 @@ # Author Joel Grand-Guillaume. Copyright 2012 Camptocamp SA # # This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# GNU Affero General Public License for more details. # -# You should have received a copy of the GNU General Public License +# You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # ############################################################################## @@ -26,18 +26,18 @@ from openerp.tools.translate import _ class AccountMove(Model): _inherit = "account.move" - def _check_fiscal_year(self, cursor, user, ids): - for move in self.browse(cursor, user, ids): + def _check_fiscal_year(self, cr, uid, ids): + for move in self.browse(cr, uid, ids): date_start = move.period_id.fiscalyear_id.date_start date_stop = move.period_id.fiscalyear_id.date_stop - if move.date < date_start or move.date > date_stop: + if not date_start <= move.date <= date_stop: return False return True _constraints = [ (_check_fiscal_year, 'You cannot create entries with date not in the fiscal year of the chosen period', - ['line_id','']), + ['line_id']), ] @@ -65,15 +65,15 @@ class AccountMoveLine(Model): _constraints = [ ( - _check_currency_and_amount, - "You cannot create journal items with a secondary currency without recording \ - both 'currency' and 'amount currency' field.", - ['currency_id','amount_currency'] + _check_currency_and_amount, + "You cannot create journal items with a secondary currency without " + "recording both 'currency' and 'amount currency' field.", + ['currency_id','amountount_currency'] ), ( _check_currency_amount, - 'The amount expressed in the secondary currency must be positif when journal item\ - are debit and negatif when journal item are credit.', + "The amount expressed in the secondary currency must be positif when journal item " + "are debit and negatif when journal item are credit.", ['amount_currency'] ), ( From 82b6bc26ce6978ffcc5a300019e81621b519d76b Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 14 Jan 2013 09:30:11 +0100 Subject: [PATCH 4/9] [FIX] remove unused imports --- account_constraints/account_constraints.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/account_constraints/account_constraints.py b/account_constraints/account_constraints.py index 2a3e906c3..0d43e2c36 100644 --- a/account_constraints/account_constraints.py +++ b/account_constraints/account_constraints.py @@ -18,10 +18,9 @@ # ############################################################################## -import time -from openerp.osv import fields, osv +from openerp.osv import fields from openerp.osv.orm import Model -from openerp.tools.translate import _ + class AccountMove(Model): _inherit = "account.move" From 69fe336fe601245aa37607e7748bb49daf657f5a Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 14 Jan 2013 09:31:49 +0100 Subject: [PATCH 5/9] [FIX] remove trailing whitespace --- account_constraints/account_constraints.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/account_constraints/account_constraints.py b/account_constraints/account_constraints.py index 0d43e2c36..d2093eeef 100644 --- a/account_constraints/account_constraints.py +++ b/account_constraints/account_constraints.py @@ -42,7 +42,7 @@ class AccountMove(Model): class AccountMoveLine(Model): _inherit='account.move.line' - + def _check_currency_and_amount(self, cr, uid, ids, context=None): for l in self.browse(cr, uid, ids, context=context): if (l.currency_id and not l.amount_currency) or (not l.currency_id and l.amount_currency): @@ -70,16 +70,14 @@ class AccountMoveLine(Model): ['currency_id','amountount_currency'] ), ( - _check_currency_amount, + _check_currency_amount, "The amount expressed in the secondary currency must be positif when journal item " - "are debit and negatif when journal item are credit.", + "are debit and negatif when journal item are credit.", ['amount_currency'] ), ( - _check_currency_company, - "You can't provide a secondary currency if the same than the company one." , + _check_currency_company, + "You can't provide a secondary currency if the same than the company one." , ['currency_id'] ), ] - - From e8cf906a9bf1d81d899ceb148bb32385b4a5c6a1 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 14 Jan 2013 09:35:01 +0100 Subject: [PATCH 6/9] [IMP] formatting --- account_constraints/account_constraints.py | 38 ++++++++++++---------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/account_constraints/account_constraints.py b/account_constraints/account_constraints.py index d2093eeef..96a3e6d65 100644 --- a/account_constraints/account_constraints.py +++ b/account_constraints/account_constraints.py @@ -35,24 +35,27 @@ class AccountMove(Model): _constraints = [ (_check_fiscal_year, - 'You cannot create entries with date not in the fiscal year of the chosen period', + 'You cannot create entries with date not in the ' + 'fiscal year of the chosen period', ['line_id']), ] class AccountMoveLine(Model): - _inherit='account.move.line' + _inherit = 'account.move.line' def _check_currency_and_amount(self, cr, uid, ids, context=None): for l in self.browse(cr, uid, ids, context=context): - if (l.currency_id and not l.amount_currency) or (not l.currency_id and l.amount_currency): + if ((l.currency_id and not l.amount_currency) or + (not l.currency_id and l.amount_currency)): return False return True def _check_currency_amount(self, cr, uid, ids, context=None): for l in self.browse(cr, uid, ids, context=context): if l.amount_currency: - if (l.amount_currency > 0.0 and l.credit > 0.0) or (l.amount_currency < 0.0 and l.debit > 0.0): + if ((l.amount_currency > 0.0 and l.credit > 0.0) or + (l.amount_currency < 0.0 and l.debit > 0.0)): return False return True @@ -63,21 +66,20 @@ class AccountMoveLine(Model): return True _constraints = [ - ( - _check_currency_and_amount, - "You cannot create journal items with a secondary currency without " - "recording both 'currency' and 'amount currency' field.", - ['currency_id','amountount_currency'] + (_check_currency_and_amount, + "You cannot create journal items with a secondary currency " + "without recording both 'currency' and 'amount currency' field.", + ['currency_id','amountount_currency'] ), - ( - _check_currency_amount, - "The amount expressed in the secondary currency must be positif when journal item " - "are debit and negatif when journal item are credit.", - ['amount_currency'] + (_check_currency_amount, + "The amount expressed in the secondary currency must be positive " + "when journal item are debit and negatif when journal item are " + "credit.", + ['amount_currency'] ), - ( - _check_currency_company, - "You can't provide a secondary currency if the same than the company one." , - ['currency_id'] + (_check_currency_company, + "You can't provide a secondary currency if " + "the same than the company one.", + ['currency_id'] ), ] From 70811a9d2d022a86ec36e7f36b43b8606caf3fa9 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 14 Jan 2013 09:35:42 +0100 Subject: [PATCH 7/9] [IMP] use more common form of imports orm.Model --- account_constraints/account_constraints.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/account_constraints/account_constraints.py b/account_constraints/account_constraints.py index 96a3e6d65..b9153e4b4 100644 --- a/account_constraints/account_constraints.py +++ b/account_constraints/account_constraints.py @@ -18,11 +18,10 @@ # ############################################################################## -from openerp.osv import fields -from openerp.osv.orm import Model +from openerp.osv import fields, orm -class AccountMove(Model): +class AccountMove(orm.Model): _inherit = "account.move" def _check_fiscal_year(self, cr, uid, ids): @@ -41,7 +40,7 @@ class AccountMove(Model): ] -class AccountMoveLine(Model): +class AccountMoveLine(orm.Model): _inherit = 'account.move.line' def _check_currency_and_amount(self, cr, uid, ids, context=None): From 01ebea67a6667844f86dbf7374edd8716418f28b Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 14 Jan 2013 09:36:40 +0100 Subject: [PATCH 8/9] [FIX] wrong field name --- account_constraints/account_constraints.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_constraints/account_constraints.py b/account_constraints/account_constraints.py index b9153e4b4..861005daa 100644 --- a/account_constraints/account_constraints.py +++ b/account_constraints/account_constraints.py @@ -68,7 +68,7 @@ class AccountMoveLine(orm.Model): (_check_currency_and_amount, "You cannot create journal items with a secondary currency " "without recording both 'currency' and 'amount currency' field.", - ['currency_id','amountount_currency'] + ['currency_id','amount_currency'] ), (_check_currency_amount, "The amount expressed in the secondary currency must be positive " From fc317a27b6ed19b8e0e59b6f0d3dee3a7b426250 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 14 Jan 2013 09:42:08 +0100 Subject: [PATCH 9/9] [FIX] manifest: remove deprecated keys, ReSTructure the description --- account_constraints/__openerp__.py | 43 +++++++++++++++++------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/account_constraints/__openerp__.py b/account_constraints/__openerp__.py index c9f2e5038..222b3e365 100644 --- a/account_constraints/__openerp__.py +++ b/account_constraints/__openerp__.py @@ -19,7 +19,7 @@ ############################################################################## { 'name' : 'Account Constraints', - 'version' : '1', + 'version' : '1.0', 'depends' : [ 'account', ], @@ -27,25 +27,30 @@ 'license': 'AGPL-3', 'category': 'Generic Modules/Accounting', 'description': """ - Add constraints in the accounting module of OpenERP to avoid bad usage by users that lead - to corrupted datas. This is based on our experiences and legal state of the art in other - software. - - Summary of constraints are: - - * Add a constraint on account move: you cannot pickup a date that is not in the fiscal year of the concerned period - - * For manual entries when multicurrency: - a - Validation on the use of the 'Currency' and 'Currency Amount' fields as it is possible to enter one without the other - b - Validation to prevent a Credit amount with a positive 'Currency Amount', or a Debit with a negative 'Currency Amount' - - * Add a check on entries that user cannot provide a secondary currency if the same than the company one. - +Account Constraints +=================== + +Add constraints in the accounting module of OpenERP to avoid bad usage +by users that lead to corrupted datas. This is based on our experiences +and legal state of the art in other software. + +Summary of constraints are: + +* Add a constraint on account move: you cannot pickup a date that is not + in the fiscal year of the concerned period + +* For manual entries when multicurrency: + + a. Validation on the use of the 'Currency' and 'Currency Amount' + fields as it is possible to enter one without the other + b. Validation to prevent a Credit amount with a positive + 'Currency Amount', or a Debit with a negative 'Currency Amount' + +* Add a check on entries that user cannot provide a secondary currency + if the same than the company one. + """, 'website': 'http://www.camptocamp.com', - 'init_xml': [], - 'update_xml': [], - 'demo_xml': [], + 'data': [], 'installable': True, - 'active': False, }