diff --git a/account_payment_blocking/__init__.py b/account_payment_blocking/__init__.py new file mode 100644 index 000000000..aa439117c --- /dev/null +++ b/account_payment_blocking/__init__.py @@ -0,0 +1,24 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Account Payment Blocking module for OpenERP +# Copyright (C) 2014 ACSONE SA/NV (http://acsone.eu) +# @author Stéphane Bidoul +# +# 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 model +from . import tests diff --git a/account_payment_blocking/__openerp__.py b/account_payment_blocking/__openerp__.py new file mode 100644 index 000000000..1e591a504 --- /dev/null +++ b/account_payment_blocking/__openerp__.py @@ -0,0 +1,59 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Account Payment Blocking module for OpenERP +# Copyright (C) 2014 ACSONE SA/NV (http://acsone.eu) +# @author Stéphane Bidoul +# @author Adrien Peiffer +# +# 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 . +# +############################################################################## +{ + 'name': 'account banking payment blocking', + 'version': '0.1', + 'category': 'Banking addons', + 'description': """ + Prevent invoices under litigation to be proposed in payment orders. + + This module uses the 'blocked' flag that is present on move lines, + to filter out lines proposed in payment orders. + + In addition it exposes this flag on the supplier invoice form + so it is easier to block an invoice. + """, + 'author': 'ACSONE SA/NV', + 'website': 'http://acsone.eu', + 'depends': [ + 'base', + 'account_banking_payment_export' + ], + 'data': [ + 'view/account_invoice_view.xml' + ], + 'test': [ + ], + 'demo': [ + ], + 'js': [ + ], + 'qweb': [ + ], + 'css': [ + ], + 'installable': True, + 'application': False, + 'auto_install': False, + 'license': 'AGPL-3', +} diff --git a/account_payment_blocking/model/__init__.py b/account_payment_blocking/model/__init__.py new file mode 100644 index 000000000..0ef1a3c56 --- /dev/null +++ b/account_payment_blocking/model/__init__.py @@ -0,0 +1,24 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Account Payment Blocking module for OpenERP +# Copyright (C) 2014 ACSONE SA/NV (http://acsone.eu) +# @author Stéphane Bidoul +# +# 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 payment_order_create +from . import account_invoice diff --git a/account_payment_blocking/model/account_invoice.py b/account_payment_blocking/model/account_invoice.py new file mode 100644 index 000000000..5632c922f --- /dev/null +++ b/account_payment_blocking/model/account_invoice.py @@ -0,0 +1,72 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Account Payment Blocking module for OpenERP +# Copyright (C) 2014 ACSONE SA/NV (http://acsone.eu) +# @author Adrien Peiffer +# +# 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, fields + + +class account_invoice(orm.Model): + _inherit = "account.invoice" + + def _get_move_line(self, cr, uid, invoice_id, context=None): + return self.pool.get('account.move.line')\ + .search(cr, uid, [('account_id.type', 'in', + ['payable', 'receivable']), + ('invoice.id', '=', invoice_id)]) + + def _set_move_blocked(self, cr, uid, ids, name, field_value, arg, + context=None): + if isinstance(ids, (int, long)): + ids = [ids] + for invoice in self.browse(cr, uid, ids, context=context): + if invoice.move_id.id: + move_line_ids = self._get_move_line(cr, uid, invoice.id, + context=context) + assert len(move_line_ids) == 1 + # work with account_constraints from OCA/AFT: + context.update({'from_parent_object': True}) + self.pool.get('account.move.line')\ + .write(cr, uid, move_line_ids, {'blocked': field_value}, + context=context) + + def _get_move_blocked(self, cr, uid, ids, name, arg, context=None): + res = {} + if isinstance(ids, (int, long)): + ids = [ids] + for invoice in self.browse(cr, uid, ids, context=context): + if invoice.move_id.id: + move_line_ids = self._get_move_line(cr, uid, invoice.id, + context=context) + assert len(move_line_ids) == 1 + move_line = self.pool.get('account.move.line')\ + .browse(cr, uid, move_line_ids, context=context)[0] + res[invoice.id] = move_line.blocked + else: + res[invoice.id] = False + return res + + _columns = { + 'blocked': fields.function(_get_move_blocked, + fnct_inv=_set_move_blocked, + type='boolean', string='No Follow Up', + states={'draft': [('readonly', + True)]}), + } diff --git a/account_payment_blocking/model/payment_order_create.py b/account_payment_blocking/model/payment_order_create.py new file mode 100644 index 000000000..ef167886a --- /dev/null +++ b/account_payment_blocking/model/payment_order_create.py @@ -0,0 +1,34 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Account Payment Blocking module for OpenERP +# Copyright (C) 2014 ACSONE SA/NV (http://acsone.eu) +# @author Stéphane Bidoul +# +# 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 payment_order_create(orm.TransientModel): + _inherit = 'payment.order.create' + + def extend_payment_order_domain( + self, cr, uid, payment_order, domain, context=None): + super(payment_order_create, self).extend_payment_order_domain( + cr, uid, payment_order, domain, context=context) + domain += [('blocked', '!=', True)] + return True diff --git a/account_payment_blocking/tests/__init__.py b/account_payment_blocking/tests/__init__.py new file mode 100644 index 000000000..625581235 --- /dev/null +++ b/account_payment_blocking/tests/__init__.py @@ -0,0 +1,27 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Account Payment Blocking module for OpenERP +# Copyright (C) 2014 ACSONE SA/NV (http://acsone.eu) +# @author Adrien Peiffer +# +# 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_banking_payment_blocking + +checks = [ + test_account_banking_payment_blocking, +] diff --git a/account_payment_blocking/tests/test_account_banking_payment_blocking.py b/account_payment_blocking/tests/test_account_banking_payment_blocking.py new file mode 100644 index 000000000..5551580c0 --- /dev/null +++ b/account_payment_blocking/tests/test_account_banking_payment_blocking.py @@ -0,0 +1,81 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Account Payment Blocking module for OpenERP +# Copyright (C) 2014 ACSONE SA/NV (http://acsone.eu) +# @author Adrien Peiffer +# +# 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 import netsvc + +DB = common.DB +ADMIN_USER_ID = common.ADMIN_USER_ID + + +def create_simple_invoice(self, cr, uid, context=None): + partner_id = self.ref('base.res_partner_2') + product_id = self.ref('product.product_product_4') + return self.registry('account.invoice')\ + .create(cr, uid, {'partner_id': partner_id, + 'account_id': + self.ref('account.a_recv'), + 'journal_id': + self.ref('account.expenses_journal'), + 'invoice_line': [(0, 0, {'name': 'test', + 'account_id': + self.ref('account.a_sale'), + 'price_unit': 2000.00, + 'quantity': 1, + 'product_id': product_id, + } + ) + ], + }) + + +class TestAccountBankingPaymentBlocking(common.TransactionCase): + + def setUp(self): + super(TestAccountBankingPaymentBlocking, self).setUp() + self.context = self.registry("res.users").context_get(self.cr, + self.uid) + + def test_invoice(self): + invoice_obj = self.registry('account.invoice') + move_line_obj = self.registry('account.move.line') + invoice_id = create_simple_invoice(self, self.cr, self.uid, + context=self.context) + netsvc.LocalService("workflow")\ + .trg_validate(self.uid, 'account.invoice', invoice_id, + 'invoice_open', self.cr) + invoice = invoice_obj.browse(self.cr, self.uid, [invoice_id], + context=self.context)[0] + move_line_ids = move_line_obj\ + .search(self.cr, self.uid, [('account_id.type', 'in', + ['payable', 'receivable']), + ('invoice.id', '=', invoice.id)]) + move_line = move_line_obj.browse(self.cr, self.uid, move_line_ids)[0] + self.assertEqual(invoice.blocked, move_line.blocked, + 'Blocked values are not equals') + move_line_obj.write(self.cr, self.uid, move_line_ids, + {'blocked': True}) + invoice = invoice_obj.browse(self.cr, self.uid, [invoice_id], + context=self.context)[0] + move_line = move_line_obj.browse(self.cr, self.uid, move_line_ids)[0] + self.assertEqual(invoice.blocked, move_line.blocked, + 'Blocked values are not equals') diff --git a/account_payment_blocking/view/account_invoice_view.xml b/account_payment_blocking/view/account_invoice_view.xml new file mode 100644 index 000000000..09e6a1ba8 --- /dev/null +++ b/account_payment_blocking/view/account_invoice_view.xml @@ -0,0 +1,15 @@ + + + + + account.invoice.supplier.form (account_banking_payment_blocking) + account.invoice + + + + + + + + + \ No newline at end of file