[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:
@@ -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:
|
||||
|
||||
@@ -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"/>
|
||||
|
||||
Reference in New Issue
Block a user