From 8973d4bf9858e311539c79514463110a9cc396e9 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 20 Jan 2015 18:05:46 +0100 Subject: [PATCH] Add module account_invoice_del_attachment_cancel Add .gitignore --- .gitignore | 56 +++++++++++++++++++ .../__init__.py | 23 ++++++++ .../__openerp__.py | 45 +++++++++++++++ .../account_invoice.py | 53 ++++++++++++++++++ 4 files changed, 177 insertions(+) create mode 100644 .gitignore create mode 100644 account_invoice_del_attachment_cancel/__init__.py create mode 100644 account_invoice_del_attachment_cancel/__openerp__.py create mode 100644 account_invoice_del_attachment_cancel/account_invoice.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..890ff01 --- /dev/null +++ b/.gitignore @@ -0,0 +1,56 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +bin/ +build/ +develop-eggs/ +dist/ +eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.cache +nosetests.xml +coverage.xml + +# Translations +*.mo + +# Pycharm +.idea + +# Mr Developer +.mr.developer.cfg +.project +.pydevproject + +# Rope +.ropeproject + +# Sphinx documentation +docs/_build/ + +# Backup files +*~ +*.swp diff --git a/account_invoice_del_attachment_cancel/__init__.py b/account_invoice_del_attachment_cancel/__init__.py new file mode 100644 index 0000000..f391d3e --- /dev/null +++ b/account_invoice_del_attachment_cancel/__init__.py @@ -0,0 +1,23 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Account Invoice Del Attachment Cancel module for OpenERP +# Copyright (C) 2015 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 account_invoice diff --git a/account_invoice_del_attachment_cancel/__openerp__.py b/account_invoice_del_attachment_cancel/__openerp__.py new file mode 100644 index 0000000..7535d1c --- /dev/null +++ b/account_invoice_del_attachment_cancel/__openerp__.py @@ -0,0 +1,45 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Account Invoice Del Attachment Cancel module for OpenERP +# Copyright (C) 2015 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': 'Account Invoice Delete Attachment on Cancel', + 'version': '0.1', + 'category': 'Accounting & Finance', + 'license': 'AGPL-3', + 'summary': 'Delete the attachment on the invoice when it is cancelled', + 'description': """ +Account Invoice Delete Attachment on Cancel +=========================================== + +When an invoice is validated, on the first generation of the invoice report, a copy of the report is stored as attachment on the invoice. After that, every time you a user asks for the Invoice report, it will be taken from the attachment. + +With this module, when an invoice is cancelled, the attachment is deleted. + +Please contact Alexis de Lattre from Akretion for any help or question about this module. + """, + 'author': 'Akretion', + 'website': 'http://www.akretion.com', + 'depends': ['account'], + 'data': [], + 'installable': True, +} diff --git a/account_invoice_del_attachment_cancel/account_invoice.py b/account_invoice_del_attachment_cancel/account_invoice.py new file mode 100644 index 0000000..0cd136a --- /dev/null +++ b/account_invoice_del_attachment_cancel/account_invoice.py @@ -0,0 +1,53 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Account Invoice Del Attachment Cancel module for OpenERP +# Copyright (C) 2015 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 AccountInvoice(orm.Model): + _inherit = 'account.invoice' + + def action_cancel(self, cr, uid, ids, context=None): + res = super(AccountInvoice, self).action_cancel( + cr, uid, ids, context=context) + iao = self.pool['ir.attachment'] + for invoice in self.browse(cr, uid, ids, context=context): + # search for attachments + if 'out' in invoice.type: + attach_ids = iao.search( + cr, uid, [ + ('res_id', '=', invoice.id), + ('res_model', '=', self._name), + ('type', '=', 'binary'), + ('datas_fname', '=like', 'INV%.pdf'), + ], context=context) + if len(attach_ids) == 1: + # delete attachment + attach = iao.browse( + cr, uid, attach_ids[0], context=context) + attach_name = attach.name + iao.unlink(cr, uid, attach_ids, context=context) + self.message_post( + cr, uid, invoice.id, + _('Attachement %s has been deleted') % attach_name) + return res