[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
This commit is contained in:
Nicolas Martinelli
2016-04-13 16:52:50 +02:00
parent bd3531dd29
commit d0029f11ce
2 changed files with 5 additions and 4 deletions
+4 -3
View File
@@ -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:
+1 -1
View File
@@ -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"/>