From b64029096219475811050e2bf8cb54e0be43c63f Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Sun, 14 Feb 2016 00:33:12 +0100 Subject: [PATCH] account_invoice_partner_bank_usability: ability to choose which bank account is selected by default on customer invoices --- .../__init__.py | 22 +-------- .../__openerp__.py | 16 +++---- .../account_invoice.py | 46 ++++++++++--------- .../company_view.xml | 26 +++++++++++ 4 files changed, 58 insertions(+), 52 deletions(-) create mode 100644 account_invoice_partner_bank_usability/company_view.xml diff --git a/account_invoice_partner_bank_usability/__init__.py b/account_invoice_partner_bank_usability/__init__.py index 61afd96..ab922af 100644 --- a/account_invoice_partner_bank_usability/__init__.py +++ b/account_invoice_partner_bank_usability/__init__.py @@ -1,23 +1,3 @@ -# -*- 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 . -# -############################################################################## +# -*- coding: utf-8 -*- from . import account_invoice diff --git a/account_invoice_partner_bank_usability/__openerp__.py b/account_invoice_partner_bank_usability/__openerp__.py index d72bdcc..d6ae66a 100644 --- a/account_invoice_partner_bank_usability/__openerp__.py +++ b/account_invoice_partner_bank_usability/__openerp__.py @@ -1,8 +1,8 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # -# Account Invoice Partner Bank Usability module for OpenERP -# Copyright (C) 2013 Akretion (http://www.akretion.com) +# Account Invoice Partner Bank Usability module for Odoo +# Copyright (C) 2013-2016 Akretion (http://www.akretion.com) # @author Alexis de Lattre # # This program is free software: you can redistribute it and/or modify @@ -26,20 +26,18 @@ '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', + 'summary': 'Configure a bank account by default for customer invoices', 'description': """ Account Invoice Partner Bank Usability ====================================== -If the company has a single bank account, we set this single bank account by default on the customer invoice. +This module adds a configuration parameter on the company that allows you to choose which bank account of your company will be selected by default on customer invoices. -Please contact Alexis de Lattre from Akretion for any help or question about this module. +This module has been written by Alexis de Lattre from Akretion . """, 'author': 'Akretion', 'website': 'http://www.akretion.com', 'depends': ['account'], - 'data': [], - 'images': [], + 'data': ['company_view.xml'], 'installable': True, - 'active': False, } diff --git a/account_invoice_partner_bank_usability/account_invoice.py b/account_invoice_partner_bank_usability/account_invoice.py index 1d84798..4bab333 100644 --- a/account_invoice_partner_bank_usability/account_invoice.py +++ b/account_invoice_partner_bank_usability/account_invoice.py @@ -1,8 +1,8 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # -# Account Invoice Partner Bank Usability module for OpenERP -# Copyright (C) 2013 Akretion (http://www.akretion.com) +# Account Invoice Partner Bank Usability module for Odoo +# Copyright (C) 2013-2016 Akretion (http://www.akretion.com) # @author Alexis de Lattre # # This program is free software: you can redistribute it and/or modify @@ -20,27 +20,29 @@ # ############################################################################## -from openerp.osv import orm +from openerp import models, fields -class account_invoice(orm.Model): +class ResCompany(models.Model): + _inherit = 'res.company' + + default_out_invoice_partner_bank_id = fields.Many2one( + 'res.partner.bank', + string='Default Bank Account for Customer Invoices', + copy=False, ondelete='restrict', + help="This is the bank account of your company that will be selected " + "by default when you create a customer invoice.") + + +class AccountInvoice(models.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 + def invoice_out_default_bank_account(self): + partner_bank_id = False + if self._context.get('type') == 'out_invoice' or \ + self._context.get('inv_type') == 'out_invoice': + partner_bank_id = self.env.user.company_id.\ + default_out_invoice_partner_bank_id.id or False + return partner_bank_id - _defaults = { - 'partner_bank_id': invoice_out_get_first_partner_bank, - } + partner_bank_id = fields.Many2one(default=invoice_out_default_bank_account) diff --git a/account_invoice_partner_bank_usability/company_view.xml b/account_invoice_partner_bank_usability/company_view.xml new file mode 100644 index 0000000..914f9d6 --- /dev/null +++ b/account_invoice_partner_bank_usability/company_view.xml @@ -0,0 +1,26 @@ + + + + + + + + + account_invoice_partner_bank_usability.company.form + res.company + + + + + + + + + + +