diff options
| author | Nicolas Martinelli <nim@odoo.com> | 2016-04-13 16:52:50 +0200 |
|---|---|---|
| committer | Nicolas Martinelli <nim@odoo.com> | 2016-04-13 16:52:50 +0200 |
| commit | d0029f11ce5d4b9e9de6ceb8a1904c76915cee84 (patch) | |
| tree | 8dbec7df0336d26e39fa683d490364e9cd422fa9 /addons | |
| parent | bd3531dd29ab2905942644a23f54852e0f05e1ba (diff) | |
[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
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/account/models/account.py | 7 | ||||
| -rw-r--r-- | 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 @@ <page name="journal_entries" string="Journal Entries"> <group> <group> - <field name="code" attrs="{'readonly': ['|',('type', 'in', ['bank','cash']),('sequence_id','!=',False)], 'required': [('type', 'not in', ['bank', 'cash'])]}"/> + <field name="code"/> <field name="refund_sequence" attrs="{'invisible': [('type', 'not in', ['sale', 'purchase'])]}" groups="base.group_no_one"/> <field name="sequence_id" required="0" groups="base.group_no_one"/> <field name="refund_sequence_id" attrs="{'required': [('refund_sequence', '=', True)], 'invisible': ['|',('type', 'not in', ['sale', 'purchase']), ('refund_sequence', '!=', True)]}" required="0" groups="base.group_no_one"/> |
