From 5e88a3825c9a6c0b1e601039e26dc90dcd538873 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Mon, 9 Dec 2013 15:15:47 +0100 Subject: [PATCH] Initial check-in of the module "account_invoice_partner_bank_usability". --- .../__init__.py | 23 ++++++++++ .../__openerp__.py | 45 ++++++++++++++++++ .../account_invoice.py | 46 +++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 account_invoice_partner_bank_usability/__init__.py create mode 100644 account_invoice_partner_bank_usability/__openerp__.py create mode 100644 account_invoice_partner_bank_usability/account_invoice.py diff --git a/account_invoice_partner_bank_usability/__init__.py b/account_invoice_partner_bank_usability/__init__.py new file mode 100644 index 0000000..61afd96 --- /dev/null +++ b/account_invoice_partner_bank_usability/__init__.py @@ -0,0 +1,23 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Account Invoice Partner Bank Usability 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 account_invoice diff --git a/account_invoice_partner_bank_usability/__openerp__.py b/account_invoice_partner_bank_usability/__openerp__.py new file mode 100644 index 0000000..dcc258c --- /dev/null +++ b/account_invoice_partner_bank_usability/__openerp__.py @@ -0,0 +1,45 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Account Invoice Partner Bank Usability 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': 'Account Invoice Partner Bank Usability', + 'version': '0.1', + 'category': 'Accounting & Finance', + 'license': 'AGPL-3', + 'summary': 'If the company has a single bank account, get the first one on the customer invoice', + 'description': """ +Account Invoice Partner Bank Usability +====================================== + +If the company has a single bank account, we get set this bank account by default on the customer invoice. + +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': [], + 'images': [], + 'installable': True, + 'active': False, +} diff --git a/account_invoice_partner_bank_usability/account_invoice.py b/account_invoice_partner_bank_usability/account_invoice.py new file mode 100644 index 0000000..1d84798 --- /dev/null +++ b/account_invoice_partner_bank_usability/account_invoice.py @@ -0,0 +1,46 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Account Invoice Partner Bank Usability 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 + + +class account_invoice(orm.Model): + _inherit = "account.invoice" + + def invoice_out_get_first_partner_bank(self, cr, uid, context=None): + '''Get the first bank account of your company on customer invoice + if your company only has one bank account''' + if context is None: + context = {} + res_partner_bank_id = False + if context.get('type') == 'out_invoice' or \ + context.get('inv_type') == 'out_invoice': + cur_user = self.pool['res.users'].browse( + cr, uid, uid, context=context) + partner_banks = cur_user.company_id.partner_id.bank_ids + if partner_banks and len(partner_banks) == 1: + res_partner_bank_id = partner_banks[0].id + return res_partner_bank_id + + _defaults = { + 'partner_bank_id': invoice_out_get_first_partner_bank, + }