From 21379159c00c3d77e29bd2c55616dfbf9399fa32 Mon Sep 17 00:00:00 2001 From: Adrien Peiffer Date: Wed, 20 Aug 2014 10:06:42 +0200 Subject: [PATCH 01/18] [ADD] Migrate account_constraint and account_default_draft_move to V8 --- .../account_default_draft_move/account.py | 64 ------------------- .../account_bank_statement.py | 52 --------------- .../__init__.py | 0 .../__openerp__.py | 8 +-- .../account_constraints.py | 0 .../i18n/account_constraints.pot | 0 .../i18n/pt_BR.po | 0 .../view/account_journal.xml | 0 .../__init__.py | 0 .../__openerp__.py | 8 +-- account_default_draft_move/account.py | 62 ++++++++++++++++++ .../account_bank_statement.py | 32 ++++++++++ .../account_view.xml | 0 .../i18n/account_default_draft_move.pot | 0 .../i18n/en.po | 0 .../i18n/fr.po | 0 .../i18n/pt_BR.po | 0 .../invoice_view.xml | 0 18 files changed, 102 insertions(+), 124 deletions(-) delete mode 100644 __unported__/account_default_draft_move/account.py delete mode 100644 __unported__/account_default_draft_move/account_bank_statement.py rename {__unported__/account_constraints => account_constraints}/__init__.py (100%) rename {__unported__/account_constraints => account_constraints}/__openerp__.py (95%) rename {__unported__/account_constraints => account_constraints}/account_constraints.py (100%) rename {__unported__/account_constraints => account_constraints}/i18n/account_constraints.pot (100%) rename {__unported__/account_constraints => account_constraints}/i18n/pt_BR.po (100%) rename {__unported__/account_constraints => account_constraints}/view/account_journal.xml (100%) rename {__unported__/account_default_draft_move => account_default_draft_move}/__init__.py (100%) rename {__unported__/account_default_draft_move => account_default_draft_move}/__openerp__.py (93%) create mode 100644 account_default_draft_move/account.py create mode 100644 account_default_draft_move/account_bank_statement.py rename {__unported__/account_default_draft_move => account_default_draft_move}/account_view.xml (100%) rename {__unported__/account_default_draft_move => account_default_draft_move}/i18n/account_default_draft_move.pot (100%) rename {__unported__/account_default_draft_move => account_default_draft_move}/i18n/en.po (100%) rename {__unported__/account_default_draft_move => account_default_draft_move}/i18n/fr.po (100%) rename {__unported__/account_default_draft_move => account_default_draft_move}/i18n/pt_BR.po (100%) rename {__unported__/account_default_draft_move => account_default_draft_move}/invoice_view.xml (100%) diff --git a/__unported__/account_default_draft_move/account.py b/__unported__/account_default_draft_move/account.py deleted file mode 100644 index b73275ca0..000000000 --- a/__unported__/account_default_draft_move/account.py +++ /dev/null @@ -1,64 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# Author Vincent Renaville/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 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 Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -############################################################################## - -from openerp.osv import orm, osv -from tools.translate import _ - - -class AccountInvoice(orm.Model): - _inherit = 'account.invoice' - - def action_move_create(self, cr, uid, ids, context=None): - """Set move line in draft state after creating them.""" - res = super(AccountInvoice, self).action_move_create(cr, uid, ids, - context=context) - move_obj = self.pool.get('account.move') - for inv in self.browse(cr, uid, ids, context=context): - if inv.move_id: - move_obj.write(cr, uid, [inv.move_id.id], {'state': 'draft'}, - context=context) - return res - - -class AccountMove(orm.Model): - _inherit = 'account.move' - - def button_cancel(self, cr, uid, ids, context=None): - """ We rewrite function button_cancel, to allow invoice or bank - statement with linked draft moved - to be canceled - - """ - for line in self.browse(cr, uid, ids, context=context): - if line.state == 'draft': - continue - else: - if not line.journal_id.update_posted: - raise osv.except_osv( - _('Error!'), - _('You cannot modify a posted entry of this journal.' - 'First you should set the journal ' - 'to allow cancelling entries.') - ) - if ids: - cr.execute('UPDATE account_move ' - 'SET state=%s ' - 'WHERE id IN %s', ('draft', tuple(ids),)) - return True diff --git a/__unported__/account_default_draft_move/account_bank_statement.py b/__unported__/account_default_draft_move/account_bank_statement.py deleted file mode 100644 index 5a966ed81..000000000 --- a/__unported__/account_default_draft_move/account_bank_statement.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# Author Vincent Renaville. Copyright 2012 Camptocamp SA -# -# This program is free software: you can redistribute it and/or modify -# 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 Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -############################################################################## - -from openerp.osv import orm - - -class AccountBankStatement(orm.Model): - _inherit = "account.bank.statement" - - def create_move_from_st_line(self, cr, uid, - st_line_id, company_currency_id, - st_line_number, context=None): - move_ids = super(AccountBankStatement, self).create_move_from_st_line( - cr, uid, st_line_id, company_currency_id, - st_line_number, context - ) - # If a bank statement line is already linked to a voucher - # we received boolean instead of voucher move ids in move_ids - bank_st_line_obj = self.pool.get('account.bank.statement.line') - voucher_obj = self.pool.get('account.voucher') - st_line = bank_st_line_obj.browse(cr, uid, st_line_id, context=context) - if st_line.voucher_id: - v = voucher_obj.browse(cr, uid, st_line.voucher_id.id, - context=context) - move_ids = v.move_id.id - - if not isinstance(move_ids, (tuple, list)): - move_ids = [move_ids] - # We receive the move created for the bank statement, we set it - # to draft - if move_ids: - move_obj = self.pool.get('account.move') - move_obj.write(cr, uid, move_ids, - {'state': 'draft'}, context=context) - return move_ids -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/__unported__/account_constraints/__init__.py b/account_constraints/__init__.py similarity index 100% rename from __unported__/account_constraints/__init__.py rename to account_constraints/__init__.py diff --git a/__unported__/account_constraints/__openerp__.py b/account_constraints/__openerp__.py similarity index 95% rename from __unported__/account_constraints/__openerp__.py rename to account_constraints/__openerp__.py index c5ab4d7f8..06bda34e3 100644 --- a/__unported__/account_constraints/__openerp__.py +++ b/account_constraints/__openerp__.py @@ -18,7 +18,7 @@ # ############################################################################## { - 'name': 'Account Constraints', + 'name': 'Account Constraints 8.0', 'version': '1.1', 'depends': ['account'], 'author': 'Camptocamp', @@ -51,8 +51,8 @@ Summary of constraints are: invoice or a bank statement, no matter what the status of the move (draft, validated or posted). This is useful in a standard context but even more if you're using `account_default_draft_move`. This way you ensure - that the user cannot make mistakes even in draft state, he must pass - through the parent object to make his modification. + that the user cannot make mistakes even in draft state, he must pass through + the parent object to make his modification. Contributors * Stéphane Bidoul @@ -62,5 +62,5 @@ Summary of constraints are: 'data': [ 'view/account_journal.xml', ], - 'installable': False, + 'installable': True, } diff --git a/__unported__/account_constraints/account_constraints.py b/account_constraints/account_constraints.py similarity index 100% rename from __unported__/account_constraints/account_constraints.py rename to account_constraints/account_constraints.py diff --git a/__unported__/account_constraints/i18n/account_constraints.pot b/account_constraints/i18n/account_constraints.pot similarity index 100% rename from __unported__/account_constraints/i18n/account_constraints.pot rename to account_constraints/i18n/account_constraints.pot diff --git a/__unported__/account_constraints/i18n/pt_BR.po b/account_constraints/i18n/pt_BR.po similarity index 100% rename from __unported__/account_constraints/i18n/pt_BR.po rename to account_constraints/i18n/pt_BR.po diff --git a/__unported__/account_constraints/view/account_journal.xml b/account_constraints/view/account_journal.xml similarity index 100% rename from __unported__/account_constraints/view/account_journal.xml rename to account_constraints/view/account_journal.xml diff --git a/__unported__/account_default_draft_move/__init__.py b/account_default_draft_move/__init__.py similarity index 100% rename from __unported__/account_default_draft_move/__init__.py rename to account_default_draft_move/__init__.py diff --git a/__unported__/account_default_draft_move/__openerp__.py b/account_default_draft_move/__openerp__.py similarity index 93% rename from __unported__/account_default_draft_move/__openerp__.py rename to account_default_draft_move/__openerp__.py index 748b33e3e..7e0502478 100644 --- a/__unported__/account_default_draft_move/__openerp__.py +++ b/account_default_draft_move/__openerp__.py @@ -18,9 +18,9 @@ # along with this program. If not, see . ############################################################################## { - "name": "Move in draft state by default", + "name": "Move in draft state by default 8.0", "version": "1.0", - "depends": ["base", "account", "account_constraints"], + "depends": ["base", "account", "account_constraints_80"], "author": "Camptocamp", 'license': 'AGPL-3', "description": """ @@ -51,7 +51,7 @@ need to make a refund). 'website': 'http://www.camptocamp.com', 'data': ['account_view.xml', 'invoice_view.xml'], - 'installable': False, - 'active': False, + 'installable': True, + 'active': True, } # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/account_default_draft_move/account.py b/account_default_draft_move/account.py new file mode 100644 index 000000000..2b488ecde --- /dev/null +++ b/account_default_draft_move/account.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author Vincent Renaville/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 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +############################################################################## + +from openerp import models, api +from openerp.tools.translate import _ + + +class AccountInvoice(models.Model): + _inherit = 'account.invoice' + + @api.multi + def action_move_create(self): + """Set move line in draft state after creating them.""" + res = super(AccountInvoice, self).action_move_create() + for inv in self: + if inv.move_id: + inv.move_id.write({'state': 'draft'}) + return res + + +class AccountMove(models.Model): + _inherit = 'account.move' + + @api.multi + def button_cancel(self): + """ We rewrite function button_cancel, to allow invoice or bank + statement with linked draft moved + to be canceled """ + for line in self: + if line.state == 'draft': + continue + else: + if not line.journal_id.update_posted: + raise models.except_orm( + _('Error!'), + _('You cannot modify a posted entry of this journal.' + 'First you should set the journal to allow' + ' cancelling entries.') + ) + if self: + self._cr.execute('UPDATE account_move ' + 'SET state=%s ' + 'WHERE id IN %s', ('draft', self._ids,)) + return True + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/account_default_draft_move/account_bank_statement.py b/account_default_draft_move/account_bank_statement.py new file mode 100644 index 000000000..c69e11ad7 --- /dev/null +++ b/account_default_draft_move/account_bank_statement.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Author Vincent Renaville. Copyright 2012 Camptocamp SA +# +# This program is free software: you can redistribute it and/or modify +# 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +############################################################################## + +from openerp import models, api + + +class AccountBankStatement(models.Model): + _inherit = "account.bank.statement" + + @api.multi + def button_confirm_bank(self): + res = super(AccountBankStatement, self).button_confirm_bank() + for st in self: + for st_line in st.line_ids: + st_line.journal_entry_id.write({'state': 'draft'}) + return res diff --git a/__unported__/account_default_draft_move/account_view.xml b/account_default_draft_move/account_view.xml similarity index 100% rename from __unported__/account_default_draft_move/account_view.xml rename to account_default_draft_move/account_view.xml diff --git a/__unported__/account_default_draft_move/i18n/account_default_draft_move.pot b/account_default_draft_move/i18n/account_default_draft_move.pot similarity index 100% rename from __unported__/account_default_draft_move/i18n/account_default_draft_move.pot rename to account_default_draft_move/i18n/account_default_draft_move.pot diff --git a/__unported__/account_default_draft_move/i18n/en.po b/account_default_draft_move/i18n/en.po similarity index 100% rename from __unported__/account_default_draft_move/i18n/en.po rename to account_default_draft_move/i18n/en.po diff --git a/__unported__/account_default_draft_move/i18n/fr.po b/account_default_draft_move/i18n/fr.po similarity index 100% rename from __unported__/account_default_draft_move/i18n/fr.po rename to account_default_draft_move/i18n/fr.po diff --git a/__unported__/account_default_draft_move/i18n/pt_BR.po b/account_default_draft_move/i18n/pt_BR.po similarity index 100% rename from __unported__/account_default_draft_move/i18n/pt_BR.po rename to account_default_draft_move/i18n/pt_BR.po diff --git a/__unported__/account_default_draft_move/invoice_view.xml b/account_default_draft_move/invoice_view.xml similarity index 100% rename from __unported__/account_default_draft_move/invoice_view.xml rename to account_default_draft_move/invoice_view.xml From 406c9280469c875dd7b3d1b996c2e51694973771 Mon Sep 17 00:00:00 2001 From: Adrien Peiffer Date: Wed, 20 Aug 2014 10:14:19 +0200 Subject: [PATCH 02/18] [FIX] Fix depends --- account_constraints/__openerp__.py | 2 +- account_default_draft_move/__openerp__.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/account_constraints/__openerp__.py b/account_constraints/__openerp__.py index 06bda34e3..5b74c2437 100644 --- a/account_constraints/__openerp__.py +++ b/account_constraints/__openerp__.py @@ -18,7 +18,7 @@ # ############################################################################## { - 'name': 'Account Constraints 8.0', + 'name': 'Account Constraints', 'version': '1.1', 'depends': ['account'], 'author': 'Camptocamp', diff --git a/account_default_draft_move/__openerp__.py b/account_default_draft_move/__openerp__.py index 7e0502478..2df5719a2 100644 --- a/account_default_draft_move/__openerp__.py +++ b/account_default_draft_move/__openerp__.py @@ -18,9 +18,9 @@ # along with this program. If not, see . ############################################################################## { - "name": "Move in draft state by default 8.0", + "name": "Move in draft state by default", "version": "1.0", - "depends": ["base", "account", "account_constraints_80"], + "depends": ["base", "account", "account_constraints"], "author": "Camptocamp", 'license': 'AGPL-3', "description": """ From 06df67e44eb744c3c23d1e2a9f5389985348397b Mon Sep 17 00:00:00 2001 From: Adrien Peiffer Date: Thu, 21 Aug 2014 13:50:14 +0200 Subject: [PATCH 03/18] [IMP] Better modularity and naming convention --- account_constraints/__init__.py | 2 +- account_constraints/model/__init__.py | 33 +++++++++++ .../model/account_bank_statement.py | 55 +++++++++++++++++++ account_constraints/model/account_invoice.py | 41 ++++++++++++++ account_constraints/model/account_journal.py | 30 ++++++++++ account_constraints/model/account_move.py | 42 ++++++++++++++ .../account_move_line.py} | 0 7 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 account_constraints/model/__init__.py create mode 100644 account_constraints/model/account_bank_statement.py create mode 100644 account_constraints/model/account_invoice.py create mode 100644 account_constraints/model/account_journal.py create mode 100644 account_constraints/model/account_move.py rename account_constraints/{account_constraints.py => model/account_move_line.py} (100%) diff --git a/account_constraints/__init__.py b/account_constraints/__init__.py index 403b23fcb..9fd8f5806 100644 --- a/account_constraints/__init__.py +++ b/account_constraints/__init__.py @@ -17,4 +17,4 @@ # along with this program. If not, see . # ############################################################################## -from . import account_constraints +from . import model diff --git a/account_constraints/model/__init__.py b/account_constraints/model/__init__.py new file mode 100644 index 000000000..28d810046 --- /dev/null +++ b/account_constraints/model/__init__.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# +# +# Authors: Adrien Peiffer +# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) +# All Rights Reserved +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsibility of assessing all potential +# consequences resulting from its eventual inadequacies and bugs. +# End users who are looking for a ready-to-use solution with commercial +# guarantees and support are strongly advised to contact a Free Software +# Service Company. +# +# This program is free software: you can redistribute it and/or modify +# 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# +from . import account_bank_statement +from . import account_invoice +from . import account_journal +from . import account_move_line +from . import account_move diff --git a/account_constraints/model/account_bank_statement.py b/account_constraints/model/account_bank_statement.py new file mode 100644 index 000000000..22010bc81 --- /dev/null +++ b/account_constraints/model/account_bank_statement.py @@ -0,0 +1,55 @@ +# -*- 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 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp import models, api + + +class AccountBankStatement(models.Model): + _inherit = "account.bank.statement" + + @api.multi + def button_cancel(self): + """Override the method to add the key 'from_parent_object' in + the context. This is to allow to delete move line related to + bank statement through the cancel button. + """ + self = self.with_context(from_parent_object=True) + return super(AccountBankStatement, self).button_cancel() + + @api.multi + def button_confirm_bank(self): + """Add the from_parent_object key in context in order to be able + to post the move. + """ + self = self.with_context(from_parent_object=True) + return super(AccountBankStatement, self).button_confirm_bank() + + +class AccountBankStatementLine(models.Model): + _inherit = "account.bank.statement.line" + + @api.multi + def process_reconciliation(self, mv_line_dicts): + """Add the from_parent_object key in context in order to be able + to balanced the move. + """ + self = self.with_context(from_parent_object=True) + return super(AccountBankStatementLine, self)\ + .process_reconciliation(mv_line_dicts) diff --git a/account_constraints/model/account_invoice.py b/account_constraints/model/account_invoice.py new file mode 100644 index 000000000..5e59ae9d0 --- /dev/null +++ b/account_constraints/model/account_invoice.py @@ -0,0 +1,41 @@ +# -*- 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 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp import models, api + + +class AccountInvoice(models.Model): + _inherit = "account.invoice" + + @api.multi + def action_cancel(self): + """Override the method to add the key 'from_parent_object' in + the context. This is to allow to delete move line related to + invoice through the cancel button. + """ + self = self.with_context(from_parent_object=True) + return super(AccountInvoice, self).action_cancel() + + @api.multi + def action_move_create(self): + """Override the method to add the key 'from_parent_object' in + the context.""" + self = self.with_context(from_parent_object=True) + return super(AccountInvoice, self).action_move_create() diff --git a/account_constraints/model/account_journal.py b/account_constraints/model/account_journal.py new file mode 100644 index 000000000..dd02dd62a --- /dev/null +++ b/account_constraints/model/account_journal.py @@ -0,0 +1,30 @@ +# -*- 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 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +## +from openerp import models, fields + + +class AccountJournal(models.Model): + _inherit = 'account.journal' + allow_date_fy = fields.Boolean(string='Check Date in Fiscal Year', + help='If set to True then do not ' + 'accept the entry if ' + 'the entry date is not into ' + 'the fiscal year dates', + default=True) diff --git a/account_constraints/model/account_move.py b/account_constraints/model/account_move.py new file mode 100644 index 000000000..3123cbf87 --- /dev/null +++ b/account_constraints/model/account_move.py @@ -0,0 +1,42 @@ +# -*- 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 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp import models, api + + +class AccountMove(models.Model): + _inherit = "account.move" + + @api.multi + def _check_fiscal_year(self): + for move in self: + if move.journal_id.allow_date_fy: + date_start = move.period_id.fiscalyear_id.date_start + date_stop = move.period_id.fiscalyear_id.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']), + ] diff --git a/account_constraints/account_constraints.py b/account_constraints/model/account_move_line.py similarity index 100% rename from account_constraints/account_constraints.py rename to account_constraints/model/account_move_line.py From 2bfa8bc1cf89bdc2dbfbc75712316767df3092df Mon Sep 17 00:00:00 2001 From: Adrien Peiffer Date: Wed, 3 Sep 2014 17:06:11 +0200 Subject: [PATCH 04/18] [IMP] Replace active by auto_install key and set to False --- account_default_draft_move/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_default_draft_move/__openerp__.py b/account_default_draft_move/__openerp__.py index 2df5719a2..e7c4cc5d4 100644 --- a/account_default_draft_move/__openerp__.py +++ b/account_default_draft_move/__openerp__.py @@ -52,6 +52,6 @@ need to make a refund). 'data': ['account_view.xml', 'invoice_view.xml'], 'installable': True, - 'active': True, + 'auto_install': False, } # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From 1dca59147767e8d634b9278a473d85f8cfe2cae9 Mon Sep 17 00:00:00 2001 From: Adrien Peiffer Date: Thu, 4 Sep 2014 01:55:59 +0200 Subject: [PATCH 05/18] [IMP] Improve modularity and migrate account_move_line --- .../model/account_move_line.py | 186 ++++-------------- 1 file changed, 43 insertions(+), 143 deletions(-) diff --git a/account_constraints/model/account_move_line.py b/account_constraints/model/account_move_line.py index 09203a432..4a981aebb 100644 --- a/account_constraints/model/account_move_line.py +++ b/account_constraints/model/account_move_line.py @@ -18,56 +18,19 @@ # ############################################################################## -from openerp.osv import fields, orm, osv +from openerp import models, api from openerp.tools.translate import _ -class AccountJournal(orm.Model): - _inherit = 'account.journal' - - _columns = { - 'allow_date_fy': fields.boolean('Check Date in Fiscal Year', - help='If set to True then do not ' - 'accept the entry if ' - 'the entry date is not into ' - 'the fiscal year dates'), - } - - _defaults = { - 'allow_date_fy': True, - } - - -class AccountMove(orm.Model): - _inherit = "account.move" - - def _check_fiscal_year(self, cr, uid, ids): - for move in self.browse(cr, uid, ids): - if move.journal_id.allow_date_fy: - date_start = move.period_id.fiscalyear_id.date_start - date_stop = move.period_id.fiscalyear_id.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']), - ] - - -class AccountMoveLine(orm.Model): +class AccountMoveLine(models.Model): _inherit = 'account.move.line' + @api.multi def _authorized_reconcile(self, vals): """ Check if only reconcile_id and/or reconcile_partial_id are altered. We cannot change other vals, but we should be able to write or unlink - those field. - e.g. when you want to manually unreconcile an entry - generated by an invoice - + those field (e.g. when you want to manually unreconcile an entry + generated by an invoice). """ if not vals: return False @@ -75,88 +38,84 @@ class AccountMoveLine(orm.Model): write_keys = set(vals) return rec_keys.issuperset(write_keys) - def _check_invoice_related_move(self, cr, uid, ids, vals=None, - context=None): - for line in self.browse(cr, uid, ids, context=context): + @api.multi + def _check_invoice_related_move(self, vals=None): + for line in self: if line.invoice: if self._authorized_reconcile(vals): return True err_msg = (_('Invoice name (id): %s (%s)') % (line.invoice.name, line.invoice.id)) - raise osv.except_osv( + raise models.except_orm( _('Error'), - _('You cannot do this on an entry generated ' - 'by an invoice. You must change the related ' - 'invoice directly.\n%s.') % err_msg - ) + _('You cannot do this on an entry generated by an invoice.' + 'You must ' + 'change the related invoice directly.\n%s.') % err_msg) return True - def _check_statement_related_move(self, cr, uid, ids, vals=None, - context=None): - for line in self.browse(cr, uid, ids, context=context): + @api.multi + def _check_statement_related_move(self, vals=None): + for line in self: if line.statement_id: if self._authorized_reconcile(vals): return True err_msg = (_('Bank statement name (id): %s (%s)') % (line.statement_id.name, line.statement_id.id)) - raise osv.except_osv( + raise models.except_orm( _('Error'), - _('You cannot do this on an entry generated ' - 'by a bank statement. You must change the related' - 'bank statement directly.\n%s.') % err_msg - ) + _('You cannot do this on an entry generated by a bank' + ' statement. ' + 'You must change the related bank statement' + ' directly.\n%s.') % err_msg) return True + @api.cr_uid_ids_context def unlink(self, cr, uid, ids, context=None, check=True): """ Add the following checks: - Is the move related to an invoice - Is the move related to a bank statement - - Is other values than reconcile_partial_id and/or - reconcile_id modified + - Is other values than reconcile_partial_id and/or reconcile_id + modified In that case, we forbid the move to be deleted even if draft. We should never delete directly a move line related or generated by another object. This is mandatory if you use the module setting all moves in draft (module: account_default_draft_move) """ - if context is None: - context = {} if not context.get('from_parent_object', False): - self._check_invoice_related_move(cr, uid, ids, context=context) - self._check_statement_related_move(cr, uid, ids, context=context) + self._check_invoice_related_move(cr, uid, ids) + self._check_statement_related_move(cr, uid, ids) return super(AccountMoveLine, self).unlink(cr, uid, ids, context=context, check=check) + @api.cr_uid_ids_context def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True): """ Add the following checks: - Is the move related to an invoice - Is the move related to a bank statement - - Is other values than reconcile_partial_id and/or - reconcile_id modified + - Is other values than reconcile_partial_id and/or reconcile_id + modified In that case, we forbid the move to be modified even if draft. We should never update directly a move line related or generated by another object. This is mandatory if you use the module setting all moves in draft (module: account_default_draft_move) """ - if context is None: - context = {} if not context.get('from_parent_object', False): - self._check_invoice_related_move(cr, uid, ids, vals, - context=context) - self._check_statement_related_move(cr, uid, ids, vals, - context=context) - return super(AccountMoveLine, self).write( - cr, uid, ids, vals, - context=context, check=check, update_check=update_check - ) + self._check_invoice_related_move(cr, uid, ids, vals) + self._check_statement_related_move(cr, uid, ids, vals) + return super(AccountMoveLine, self).write(cr, uid, ids, vals, + context=context, + check=check, + update_check=update_check) - def _check_currency_and_amount(self, cr, uid, ids, context=None): - for l in self.browse(cr, uid, ids, context=context): + @api.multi + def _check_currency_and_amount(self): + for l in self: # we check zero amount line if not (l.debit and l.credit): continue @@ -164,16 +123,18 @@ class AccountMoveLine(orm.Model): return False return True - def _check_currency_amount(self, cr, uid, ids, context=None): - for l in self.browse(cr, uid, ids, context=context): + @api.multi + def _check_currency_amount(self): + for l in self: 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): + @api.multi + def _check_currency_company(self): + for l in self: if l.currency_id.id == l.company_id.currency_id.id: return False return True @@ -195,64 +156,3 @@ class AccountMoveLine(orm.Model): "the same than the company one.", ['currency_id']), ] - - -class AccountInvoice(orm.Model): - _inherit = "account.invoice" - - def action_cancel(self, cr, uid, ids, context=None): - """Override the method to add the key 'from_parent_object' in - the context. This is to allow to delete move line related to - invoice through the cancel button. - """ - if context is None: - context = {} - else: - context = context.copy() - context['from_parent_object'] = True - return super(AccountInvoice, self).action_cancel(cr, uid, ids, - context=context) - - def action_move_create(self, cr, uid, ids, context=None): - """Override the method to add the key 'from_parent_object' in - the context.""" - if context is None: - context = {} - else: - context = context.copy() - context['from_parent_object'] = True - return super(AccountInvoice, self).action_move_create(cr, uid, ids, - context=context) - - -class AccountBankStatement(orm.Model): - _inherit = "account.bank.statement" - - def button_cancel(self, cr, uid, ids, context=None): - """Override the method to add the key 'from_parent_object' in - the context. This is to allow to delete move line related to - bank statement through the cancel button. - """ - if context is None: - context = {} - else: - context = context.copy() - context['from_parent_object'] = True - return super(AccountBankStatement, self).button_cancel(cr, uid, ids, - context=context) - - def create_move_from_st_line(self, cr, uid, st_line_id, - company_currency_id, - st_line_number, context=None): - """Add the from_parent_object key in context in order to be able - to post the move. - """ - if context is None: - context = {} - else: - context = context.copy() - context['from_parent_object'] = True - return super(AccountBankStatement, self).create_move_from_st_line( - cr, uid, st_line_id, company_currency_id, - st_line_number, context=context - ) From 9452f909776e2bbf867035276fef2caf88634475 Mon Sep 17 00:00:00 2001 From: Adrien Peiffer Date: Mon, 8 Sep 2014 09:38:46 +0200 Subject: [PATCH 06/18] [IMP] Improve use of new api for account_default_draft_move --- account_default_draft_move/account.py | 2 +- account_default_draft_move/account_bank_statement.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/account_default_draft_move/account.py b/account_default_draft_move/account.py index 2b488ecde..3282a8eb5 100644 --- a/account_default_draft_move/account.py +++ b/account_default_draft_move/account.py @@ -30,7 +30,7 @@ class AccountInvoice(models.Model): res = super(AccountInvoice, self).action_move_create() for inv in self: if inv.move_id: - inv.move_id.write({'state': 'draft'}) + inv.move_id.state = 'draft' return res diff --git a/account_default_draft_move/account_bank_statement.py b/account_default_draft_move/account_bank_statement.py index c69e11ad7..0773b811d 100644 --- a/account_default_draft_move/account_bank_statement.py +++ b/account_default_draft_move/account_bank_statement.py @@ -28,5 +28,5 @@ class AccountBankStatement(models.Model): res = super(AccountBankStatement, self).button_confirm_bank() for st in self: for st_line in st.line_ids: - st_line.journal_entry_id.write({'state': 'draft'}) + st_line.journal_entry_id.state = 'draft' return res From e72546fcb25ebd3b3cf70b5fa5fb44bd32103b8f Mon Sep 17 00:00:00 2001 From: Adrien Peiffer Date: Mon, 8 Sep 2014 09:39:52 +0200 Subject: [PATCH 07/18] [IMP] Use exceptions import on account_default_draft_move --- account_default_draft_move/account.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/account_default_draft_move/account.py b/account_default_draft_move/account.py index 3282a8eb5..42c9e068e 100644 --- a/account_default_draft_move/account.py +++ b/account_default_draft_move/account.py @@ -18,6 +18,7 @@ ############################################################################## from openerp import models, api +from openerp import exceptions from openerp.tools.translate import _ @@ -47,7 +48,7 @@ class AccountMove(models.Model): continue else: if not line.journal_id.update_posted: - raise models.except_orm( + raise exceptions.except_orm( _('Error!'), _('You cannot modify a posted entry of this journal.' 'First you should set the journal to allow' From e533ba1f4cf2272df3a428635d5e60a569341984 Mon Sep 17 00:00:00 2001 From: Adrien Peiffer Date: Mon, 8 Sep 2014 09:42:02 +0200 Subject: [PATCH 08/18] [IMP] Use exceptions import on account_constraints --- account_constraints/model/account_move_line.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/account_constraints/model/account_move_line.py b/account_constraints/model/account_move_line.py index 4a981aebb..b6f7feff5 100644 --- a/account_constraints/model/account_move_line.py +++ b/account_constraints/model/account_move_line.py @@ -19,6 +19,7 @@ ############################################################################## from openerp import models, api +from openerp import exceptions from openerp.tools.translate import _ @@ -46,7 +47,7 @@ class AccountMoveLine(models.Model): return True err_msg = (_('Invoice name (id): %s (%s)') % (line.invoice.name, line.invoice.id)) - raise models.except_orm( + raise exceptions.except_orm( _('Error'), _('You cannot do this on an entry generated by an invoice.' 'You must ' @@ -61,7 +62,7 @@ class AccountMoveLine(models.Model): return True err_msg = (_('Bank statement name (id): %s (%s)') % (line.statement_id.name, line.statement_id.id)) - raise models.except_orm( + raise exceptions.except_orm( _('Error'), _('You cannot do this on an entry generated by a bank' ' statement. ' From 52cb0259f6372673ef0e8d180224d8180a6a7c4a Mon Sep 17 00:00:00 2001 From: Adrien Peiffer Date: Tue, 9 Sep 2014 15:13:50 +0200 Subject: [PATCH 09/18] [TEST] Add tests for account default draft move addons --- account_default_draft_move/__init__.py | 1 + account_default_draft_move/tests/__init__.py | 38 ++++++++++ .../tests/test_account_default_draft_move.py | 73 +++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 account_default_draft_move/tests/__init__.py create mode 100644 account_default_draft_move/tests/test_account_default_draft_move.py diff --git a/account_default_draft_move/__init__.py b/account_default_draft_move/__init__.py index 3593dc32f..e7cbe6cd9 100644 --- a/account_default_draft_move/__init__.py +++ b/account_default_draft_move/__init__.py @@ -19,3 +19,4 @@ ############################################################################## from . import account from . import account_bank_statement +from . import tests diff --git a/account_default_draft_move/tests/__init__.py b/account_default_draft_move/tests/__init__.py new file mode 100644 index 000000000..a02043455 --- /dev/null +++ b/account_default_draft_move/tests/__init__.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +# +# +# Authors: Adrien Peiffer +# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) +# All Rights Reserved +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsibility of assessing all potential +# consequences resulting from its eventual inadequacies and bugs. +# End users who are looking for a ready-to-use solution with commercial +# guarantees and support are strongly advised to contact a Free Software +# Service Company. +# +# This program is free software: you can redistribute it and/or modify +# 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# + +from . import test_account_default_draft_move + +fast_suite = [ + test_account_default_draft_move, +] + +checks = [ + test_account_default_draft_move, +] diff --git a/account_default_draft_move/tests/test_account_default_draft_move.py b/account_default_draft_move/tests/test_account_default_draft_move.py new file mode 100644 index 000000000..0812e3123 --- /dev/null +++ b/account_default_draft_move/tests/test_account_default_draft_move.py @@ -0,0 +1,73 @@ +# -*- coding: utf-8 -*- +# +# +# Authors: Adrien Peiffer +# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) +# All Rights Reserved +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsibility of assessing all potential +# consequences resulting from its eventual inadequacies and bugs. +# End users who are looking for a ready-to-use solution with commercial +# guarantees and support are strongly advised to contact a Free Software +# Service Company. +# +# This program is free software: you can redistribute it and/or modify +# 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# + +import openerp.tests.common as common +from datetime import datetime +from openerp.tools import DEFAULT_SERVER_DATE_FORMAT +from openerp import workflow + +DB = common.DB +ADMIN_USER_ID = common.ADMIN_USER_ID + + +def create_simple_invoice(self): + partner_id = self.ref('base.res_partner_2') + product_id = self.ref('product.product_product_4') + today = datetime.now() + journal_id = self.ref('account.sales_journal') + date = today.strftime(DEFAULT_SERVER_DATE_FORMAT) + return self.env['account.invoice']\ + .create({'partner_id': partner_id, + 'account_id': + self.ref('account.a_recv'), + 'journal_id': + journal_id, + 'date_invoice': date, + 'invoice_line': [(0, 0, {'name': 'test', + 'account_id': + self.ref('account.a_sale'), + 'price_unit': 2000.00, + 'quantity': 1, + 'product_id': product_id, + } + ) + ], + }) + + +class TestAccountDefaultDraftMove(common.TransactionCase): + + def setUp(self): + super(TestAccountDefaultDraftMove, self).setUp() + + def test_draft_move_invoice(self): + invoice = create_simple_invoice(self) + workflow.trg_validate(self.uid, 'account.invoice', invoice.id, + 'invoice_open', self.cr) + self.assertEqual(invoice.move_id.state, 'draft', 'State error!') From b3544b026b7625cb42e3eb895b2f4386d418ae5c Mon Sep 17 00:00:00 2001 From: Adrien Peiffer Date: Tue, 9 Sep 2014 15:14:07 +0200 Subject: [PATCH 10/18] [TEST] Add tests for account constraints addons --- account_constraints/__init__.py | 1 + account_constraints/tests/__init__.py | 40 ++++++++ .../tests/test_account_constraints.py | 96 +++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 account_constraints/tests/__init__.py create mode 100644 account_constraints/tests/test_account_constraints.py diff --git a/account_constraints/__init__.py b/account_constraints/__init__.py index 9fd8f5806..ec1575354 100644 --- a/account_constraints/__init__.py +++ b/account_constraints/__init__.py @@ -18,3 +18,4 @@ # ############################################################################## from . import model +from . import tests diff --git a/account_constraints/tests/__init__.py b/account_constraints/tests/__init__.py new file mode 100644 index 000000000..d2b3476e4 --- /dev/null +++ b/account_constraints/tests/__init__.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +# +# +# Authors: Adrien Peiffer +# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) +# All Rights Reserved +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsibility of assessing all potential +# consequences resulting from its eventual inadequacies and bugs. +# End users who are looking for a ready-to-use solution with commercial +# guarantees and support are strongly advised to contact a Free Software +# Service Company. +# +# This program is free software: you can redistribute it and/or modify +# 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# + +from . import test_account_constraints + +fast_suite = [ + test_account_constraints, +] + +checks = [ + test_account_constraints, +] + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/account_constraints/tests/test_account_constraints.py b/account_constraints/tests/test_account_constraints.py new file mode 100644 index 000000000..cfae38313 --- /dev/null +++ b/account_constraints/tests/test_account_constraints.py @@ -0,0 +1,96 @@ +# -*- coding: utf-8 -*- +# +# +# Authors: Adrien Peiffer +# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) +# All Rights Reserved +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsibility of assessing all potential +# consequences resulting from its eventual inadequacies and bugs. +# End users who are looking for a ready-to-use solution with commercial +# guarantees and support are strongly advised to contact a Free Software +# Service Company. +# +# This program is free software: you can redistribute it and/or modify +# 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# + +import openerp.tests.common as common +from openerp.osv import orm +from datetime import datetime +from openerp.tools import DEFAULT_SERVER_DATE_FORMAT +from openerp import workflow + +DB = common.DB +ADMIN_USER_ID = common.ADMIN_USER_ID + + +def create_simple_invoice(self): + partner_id = self.ref('base.res_partner_2') + product_id = self.ref('product.product_product_4') + today = datetime.now() + journal_id = self.ref('account.sales_journal') + date = today.strftime(DEFAULT_SERVER_DATE_FORMAT) + return self.env['account.invoice']\ + .create({'partner_id': partner_id, + 'account_id': + self.ref('account.a_recv'), + 'journal_id': + journal_id, + 'date_invoice': date, + 'invoice_line': [(0, 0, {'name': 'test', + 'account_id': + self.ref('account.a_sale'), + 'price_unit': 2000.00, + 'quantity': 1, + 'product_id': product_id, + } + ) + ], + }) + + +class TestAccountConstraints(common.TransactionCase): + + def setUp(self): + super(TestAccountConstraints, self).setUp() + + def test_draft_move_invoice(self): + invoice = create_simple_invoice(self) + workflow.trg_validate(self.uid, 'account.invoice', invoice.id, + 'invoice_open', self.cr) + move = invoice.move_id + move_lines = move.line_id + move.with_context({'from_parent_object': True})\ + .write({'state': 'draft'}) + self.assertRaises(orm.except_orm, move_lines.write, {'credit': 0.0}) + + def test_post_move_invoice_ref(self): + invoice = create_simple_invoice(self) + workflow.trg_validate(self.uid, 'account.invoice', invoice.id, + 'invoice_open', self.cr) + move_lines = invoice.move_id.line_id + # here, normally no exception is raised in standard code. + # It's just to verify if it's + # possible to modify ref field in a post account_move_line + move_lines.with_context({'from_parent_object': True})\ + .write({'ref': 'test'}) + + def test_post_move_invoice(self): + invoice = create_simple_invoice(self) + workflow.trg_validate(self.uid, 'account.invoice', invoice.id, + 'invoice_open', self.cr) + move_lines = invoice.move_id.line_id + self.assertRaises(orm.except_orm, move_lines.write, {'ref': 'test'}) From fcb6150d53c9dab9dccfb0fb1b3138fc528819f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Fri, 24 Oct 2014 19:26:24 +0200 Subject: [PATCH 11/18] [IMP] allow unreconciling bank statement lines by adding the cancel button Since account_constraint forbids the deletion of account moves that are linked to a bank statement, we add the possibility to delete them from the bank statement itself, to provide a way to fix erroneous matches. --- account_constraints/__openerp__.py | 1 + .../model/account_bank_statement.py | 10 ++++++++- .../view/account_bank_statement.xml | 21 +++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 account_constraints/view/account_bank_statement.xml diff --git a/account_constraints/__openerp__.py b/account_constraints/__openerp__.py index 5b74c2437..016c0c81c 100644 --- a/account_constraints/__openerp__.py +++ b/account_constraints/__openerp__.py @@ -61,6 +61,7 @@ Summary of constraints are: 'website': 'http://www.camptocamp.com', 'data': [ 'view/account_journal.xml', + 'view/account_bank_statement.xml', ], 'installable': True, } diff --git a/account_constraints/model/account_bank_statement.py b/account_constraints/model/account_bank_statement.py index 22010bc81..903f29723 100644 --- a/account_constraints/model/account_bank_statement.py +++ b/account_constraints/model/account_bank_statement.py @@ -18,7 +18,7 @@ # ############################################################################## -from openerp import models, api +from openerp import models, api, fields class AccountBankStatement(models.Model): @@ -45,6 +45,14 @@ class AccountBankStatement(models.Model): class AccountBankStatementLine(models.Model): _inherit = "account.bank.statement.line" + state = fields.Selection(string='Statement state', + related='statement_id.state') + + @api.multi + def cancel(self): + self = self.with_context(from_parent_object=True) + return super(AccountBankStatementLine, self).cancel() + @api.multi def process_reconciliation(self, mv_line_dicts): """Add the from_parent_object key in context in order to be able diff --git a/account_constraints/view/account_bank_statement.xml b/account_constraints/view/account_bank_statement.xml new file mode 100644 index 000000000..b1c7f3e48 --- /dev/null +++ b/account_constraints/view/account_bank_statement.xml @@ -0,0 +1,21 @@ + + + + + + bank.statement.cancel.form.inherit + account.bank.statement + + + + +