odoo/odoo · warning · UserError
Could not compute any code for the copy automatically. Pleas
Error message
Could not compute any code for the copy automatically. Please create it manually.
What it means
In the create/copy plumbing (_copy_data / create override around line 761), when duplicating a journal Odoo derives a new short code by stripping digits from the original code and appending a counter while the candidate collides with existing codes. If the counter exceeds the number of existing codes without finding a free slot (bounded by the code field's size), it raises this UserError as a safety net.
Source
Thrown at addons/account/models/account_journal.py:761
)[0][0])
for company_id, _ in groupby(vals_list, lambda v: v['company_id'])
}
for journal, vals in zip(self, vals_list):
# Find a unique code for the copied journal
all_journal_codes = code_by_company_id[vals['company_id']]
copy_code = vals['code']
code_prefix = re.sub(r'\d+', '', copy_code).strip()
counter = 1
while counter <= len(all_journal_codes) and copy_code in all_journal_codes:
counter_str = str(counter)
copy_prefix = code_prefix[:journal._fields['code'].size - len(counter_str)]
copy_code = "%s%s" % (copy_prefix, counter_str)
counter += 1
if counter > len(all_journal_codes):
# Should never happen, but put there just in case.
raise UserError(_("Could not compute any code for the copy automatically. Please create it manually."))
vals.update(
code=copy_code,
name=_("%s (copy)", journal.name or ''))
return vals_list
def write(self, vals):
# for journals, force a readable name instead of a sanitized name e.g. non ascii in journal names
if vals.get('alias_name') and 'type' not in vals:
# will raise if writing name on more than 1 record, using self[0] is safe
if (not self.env['mail.alias']._is_encodable(vals['alias_name']) or
not self.env['mail.alias']._sanitize_alias_name(vals['alias_name'])):
vals['alias_name'] = self._alias_prepare_alias_name(
False, vals.get('name', self.name), vals.get('code', self.code), self[0].type, self[0].company_id)
for journal in self:
company = journal.company_id
if ('company_id' in vals and journal.company_id.id != vals['company_id']):View on GitHub (pinned to 1e661df964)
Solutions
- Create the copy manually with an explicit free 'code' value instead of relying on copy().
- Shorten the source journal's code prefix so a counter suffix fits within the field size.
- Free up codes by renaming/archiving journals that block the generated sequence.
Example fix
# before
new_journal = journal.copy() # may raise when codes are exhausted
# after
new_journal = journal.copy({'code': 'BNK9', 'name': '%s (copy)' % journal.name}) Defensive patterns
Strategy: fallback
Try / catch
from odoo.exceptions import UserError
try:
new_journal = journal.copy()
except UserError:
new_journal = journal.copy({'code': free_code, 'name': f"{journal.name} (copy)"}) Prevention
- Pass an explicit 'code' in copy() defaults instead of relying on auto-generation.
- Keep journal code prefixes short so counter suffixes fit the field size.
- Treat this as a rare guard: prefer deterministic codes in scripts.
When it happens
Trigger: Calling journal.copy() when the generated code candidates all collide with all_journal_codes; practically only reachable when the code column's size is too small to fit prefix+counter or when the loop guard is hit, e.g. many single-char codes exhausting combinations.
Common situations: Mass-duplicating journals with long alphabetic prefixes so the truncated copy_prefix plus counter cannot form a unique code; databases with many similarly coded journals.
Related errors
- Cannot generate an unused journal code. Please change the na
- You can't change the company of your journal since there are
- The type of the journal's default credit/debit account shoul
- You can not archive a journal containing draft journal entri
- No journal could be found in company %(company_name)s for an
AI-assisted analysis of odoo/odoo@1e661df964 (2026-08-15).
Data as JSON: /api/errors/f719ec27f35f9ad7.
Report an issue: GitHub.