From b35990ee8a2e8fad30ee5284676f1394298fc7ca Mon Sep 17 00:00:00 2001 From: Olivier Colson Date: Mon, 27 Feb 2017 15:46:17 +0100 Subject: [PATCH] [IMP] account: add default value for partner_bank_id field This field is referencing the bank account of the company issuing the invoice, so we default to the fist bank account for that company [REF] account Fix typo in id. --- addons/account/models/account_invoice.py | 19 ++++++++++++++++++- addons/account/views/res_config_view.xml | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 1b33d99c15e..4503e6ce96f 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -297,7 +297,7 @@ class AccountInvoice(models.Model): help="It indicates that the invoice has been paid and the journal entry of the invoice has been reconciled with one or several journal entries of payment.") partner_bank_id = fields.Many2one('res.partner.bank', string='Bank Account', help='Bank Account Number to which the invoice will be paid. A Company bank account if this is a Customer Invoice or Vendor Refund, otherwise a Partner bank account number.', - readonly=True, states={'draft': [('readonly', False)]}) + readonly=True, states={'draft': [('readonly', False)]}) #Default value computed in default_get for out_invoices residual = fields.Monetary(string='Amount Due', compute='_compute_residual', store=True, help="Remaining amount due.") @@ -358,6 +358,23 @@ class AccountInvoice(models.Model): (not_reconciled & pre_not_reconciled).filtered(lambda invoice: invoice.state == 'paid').action_invoice_re_open() return res + @api.model + def default_get(self,default_fields): + """ Compute default partner_bank_id field for 'out_invoice' type, + using the default values computed for the other fields. + """ + res = super(AccountInvoice, self).default_get(default_fields) + + if not res.get('type', False) == 'out_invoice' or not 'company_id' in res: + return res + + company = self.env['res.company'].browse(res['company_id']) + if company.partner_id: + partner_bank_result = self.env['res.partner.bank'].search([('partner_id', '=', company.partner_id.id)], limit=1) + if partner_bank_result: + res['partner_bank_id'] = partner_bank_result.id + return res + @api.model def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): def get_view_id(xid, name): diff --git a/addons/account/views/res_config_view.xml b/addons/account/views/res_config_view.xml index 429de71fff7..fa2074c39a8 100644 --- a/addons/account/views/res_config_view.xml +++ b/addons/account/views/res_config_view.xml @@ -285,7 +285,7 @@

Accounting Reports

-
+