From d0029f11ce5d4b9e9de6ceb8a1904c76915cee84 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Wed, 13 Apr 2016 16:52:50 +0200 Subject: [PATCH] [IMP] account: short code always required The short code is always required for the following reasons: - The auto-generated code is useless for search purpose because user cannot choose it (BNK or CSH is maybe not meaningful for him) - If the system cannot generate an unused journal code, the user is stuck since the field is read-only in the interface. However, the code can still be auto-generated, although it is required in the interface. This is to avoid breaking modules that would expect this feature. At the same time, the logic has been improved to reduce the number of search requests. opw-674485 --- addons/account/models/account.py | 7 ++++--- addons/account/views/account_view.xml | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/addons/account/models/account.py b/addons/account/models/account.py index 45ea3061342..05abdb9c0dd 100644 --- a/addons/account/models/account.py +++ b/addons/account/models/account.py @@ -405,11 +405,12 @@ class AccountJournal(models.Model): # If no code provided, loop to find next available journal code if not vals.get('code'): + journal_code_base = (vals['type'] == 'cash' and 'CSH' or 'BNK') + journals = self.env['account.journal'].search([('code', 'like', journal_code_base + '%'), ('company_id', '=', company_id)]) for num in xrange(1, 100): # journal_code has a maximal size of 5, hence we can enforce the boundary num < 100 - journal_code = (vals['type'] == 'cash' and 'CSH' or 'BNK') + str(num) - journal = self.env['account.journal'].search([('code', '=', journal_code), ('company_id', '=', company_id)], limit=1) - if not journal: + journal_code = journal_code_base + str(num) + if journal_code not in journals.mapped('code'): vals['code'] = journal_code break else: diff --git a/addons/account/views/account_view.xml b/addons/account/views/account_view.xml index 570f0195cc8..d7d884d4372 100644 --- a/addons/account/views/account_view.xml +++ b/addons/account/views/account_view.xml @@ -264,7 +264,7 @@ - +