From 4c901f8ac6438333f994d39dec1558d837a123e4 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Wed, 30 Sep 2015 15:21:32 +0200 Subject: [PATCH] [FIX] sale: use default_get to define the invoice journal When creating the invoice of a sales order, from the sales order (`Create invoice` button on the sale order), the journal used for the invoice was forced with a specific domain. Besides, the only reason the journal is forced is to check there is a sale journal for the quotation company, and raise a warning if not. This check was added in 1578c2858df1ca398bcdd07cc0c3e6a83ff23b9c. This prevented to use the user defined defaults, (`Set defaults` in the `debug` menu) to set a different default journal per user. Using the `default_get` instead solves this issue, as it uses first the user defined defaults. Besides, if no user defined defaults are set, it then uses the default value set in the field definition, which in this case returns the same journal then the forced domain mentioned above, the domain used being the same. There is therefore no change of behavior, while giving the possibility to use the user defined defaults. Fixes #8786 --- addons/sale/sale.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/addons/sale/sale.py b/addons/sale/sale.py index 09256593b5c..66c53b683e7 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -391,10 +391,8 @@ class sale_order(osv.osv): """ if context is None: context = {} - journal_ids = self.pool.get('account.journal').search(cr, uid, - [('type', '=', 'sale'), ('company_id', '=', order.company_id.id)], - limit=1) - if not journal_ids: + journal_id = self.pool['account.invoice'].default_get(cr, uid, ['journal_id'], context=context)['journal_id'] + if not journal_id: raise osv.except_osv(_('Error!'), _('Please define sales journal for this company: "%s" (id:%d).') % (order.company_id.name, order.company_id.id)) invoice_vals = { @@ -404,7 +402,7 @@ class sale_order(osv.osv): 'reference': order.client_order_ref or order.name, 'account_id': order.partner_invoice_id.property_account_receivable.id, 'partner_id': order.partner_invoice_id.id, - 'journal_id': journal_ids[0], + 'journal_id': journal_id, 'invoice_line': [(6, 0, lines)], 'currency_id': order.pricelist_id.currency_id.id, 'comment': order.note,