From 5dc05f3c81cbf5c731a2dd8b38e9f6bc1416f49f Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Mon, 9 Dec 2013 18:12:45 +0100 Subject: [PATCH] Add module stock_invoice_try_again --- stock_invoice_try_again/__init__.py | 23 +++++++++ stock_invoice_try_again/__openerp__.py | 45 ++++++++++++++++ stock_invoice_try_again/stock.py | 62 ++++++++++++++++++++++ stock_invoice_try_again/stock_view.xml | 71 ++++++++++++++++++++++++++ 4 files changed, 201 insertions(+) create mode 100644 stock_invoice_try_again/__init__.py create mode 100644 stock_invoice_try_again/__openerp__.py create mode 100644 stock_invoice_try_again/stock.py create mode 100644 stock_invoice_try_again/stock_view.xml diff --git a/stock_invoice_try_again/__init__.py b/stock_invoice_try_again/__init__.py new file mode 100644 index 0000000..6bb4f4c --- /dev/null +++ b/stock_invoice_try_again/__init__.py @@ -0,0 +1,23 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Stock Invoice Try Again module for OpenERP +# Copyright (C) 2013 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# 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 stock diff --git a/stock_invoice_try_again/__openerp__.py b/stock_invoice_try_again/__openerp__.py new file mode 100644 index 0000000..afe9d99 --- /dev/null +++ b/stock_invoice_try_again/__openerp__.py @@ -0,0 +1,45 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Stock Invoice Try Again module for OpenERP +# Copyright (C) 2013 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# 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': 'Stock Invoice Try Again', + 'version': '0.1', + 'category': 'Accounting & Finance', + 'license': 'AGPL-3', + 'summary': 'Add a button to set a picking back to "To Be Invoiced"', + 'description': """ +Stock Invoice Try Again +======================= + +When the sale order has 'Create Invoice' set to 'On Delivery Order', there is a button 'Create Invoice' on the Delivery Order once the goods are shipped. When the user clicks on this button, OpenERP creates a draft invoice. If the user deletes this draft invoice by mistake, he cannot re-create the invoice. This module is the solution : if the invoice has been deleted, the user can set the picking back to 'To Be Invoiced' and create the invoice again. + +Please contact Alexis de Lattre from Akretion for any help or question about this module. + """, + 'author': 'Akretion', + 'website': 'http://www.akretion.com', + 'depends': ['stock_picking_invoice_link'], + 'data': ['stock_view.xml'], + 'images': [], + 'installable': True, + 'active': False, +} diff --git a/stock_invoice_try_again/stock.py b/stock_invoice_try_again/stock.py new file mode 100644 index 0000000..5ea9fcd --- /dev/null +++ b/stock_invoice_try_again/stock.py @@ -0,0 +1,62 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Stock Invoice Try Again module for OpenERP +# Copyright (C) 2013 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# 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 +from openerp.tools.translate import _ + + +class stock_picking(orm.Model): + _inherit = 'stock.picking' + + def revert_to_tobeinvoiced(self, cr, uid, ids, context=None): + assert len(ids) == 1, "Only one picking" + picking = self.browse(cr, uid, ids[0], context=context) + if picking.invoice_state == 'invoiced': + if picking.invoice_id: + raise orm.except_orm( + _('Error:'), + _("This picking is linked to the invoice with description '%s'. You should first delete this invoice and try again.") + % picking.invoice_id.name) + self.write(cr, uid, ids[0], { + 'invoice_state': '2binvoiced', + }, context=context) + else: + raise orm.except_orm( + _('Error:'), + _("You can only do this when the Delivery Order has 'Invoice State' = 'Invoiced'.")) + return True + + +class stock_picking_out(orm.Model): + _inherit = 'stock.picking.out' + + def revert_to_tobeinvoiced(self, cr, uid, ids, context=None): + return self.pool['stock.picking'].revert_to_tobeinvoiced( + cr, uid, ids, context=context) + + +class stock_picking_in(orm.Model): + _inherit = 'stock.picking.in' + + def revert_to_tobeinvoiced(self, cr, uid, ids, context=None): + return self.pool['stock.picking'].revert_to_tobeinvoiced( + cr, uid, ids, context=context) diff --git a/stock_invoice_try_again/stock_view.xml b/stock_invoice_try_again/stock_view.xml new file mode 100644 index 0000000..921b013 --- /dev/null +++ b/stock_invoice_try_again/stock_view.xml @@ -0,0 +1,71 @@ + + + + + + + + + stock_invoice_try_again.view_picking_form + stock.picking + + + + + + + + + + + stock_invoice_try_again.view_picking_out_form + stock.picking.out + + + + + + + + + + + stock_invoice_try_again.view_picking_in_form + stock.picking.in + + + + + + + + + + + +